Class: Rack::MiniProfiler::PageTimerStruct

Inherits:
TimerStruct
  • Object
show all
Defined in:
lib/mini_profiler/page_timer_struct.rb

Overview

PageTimerStruct

Root: RequestTimer
  :has_many RequestTimer children
  :has_many SqlTimer children

Instance Method Summary collapse

Methods inherited from TimerStruct

#[], #[]=, #attributes

Constructor Details

#initialize(env) ⇒ PageTimerStruct

Returns a new instance of PageTimerStruct.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mini_profiler/page_timer_struct.rb', line 11

def initialize(env)
  super("Id" => MiniProfiler.generate_id,
        "Name" => env['PATH_INFO'],
        "Started" => (Time.now.to_f * 1000).to_i,
        "MachineName" => env['SERVER_NAME'],
        "Level" => 0,
        "User" => "unknown user",
        "HasUserViewed" => false,
        "ClientTimings" => ClientTimerStruct.new,
        "DurationMilliseconds" => 0,
        "HasTrivialTimings" => true,
        "HasAllTrivialTimigs" => false,
        "TrivialDurationThresholdMilliseconds" => 2,
        "Head" => nil,
        "DurationMillisecondsInSql" => 0,
        "HasSqlTimings" => true,
        "HasDuplicateSqlTimings" => false,
        "ExecutedReaders" => 0,
        "ExecutedScalars" => 0,
        "ExecutedNonQueries" => 0)
  name = "#{env['REQUEST_METHOD']} http://#{env['SERVER_NAME']}:#{env['SERVER_PORT']}#{env['SCRIPT_NAME']}#{env['PATH_INFO']}"
  self['Root'] = RequestTimerStruct.createRoot(name, self)
end

Instance Method Details

#duration_msObject



35
36
37
# File 'lib/mini_profiler/page_timer_struct.rb', line 35

def duration_ms
  @attributes['Root']['DurationMilliseconds']
end

#rootObject



39
40
41
# File 'lib/mini_profiler/page_timer_struct.rb', line 39

def root
  @attributes['Root']
end

#to_json(*a) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/mini_profiler/page_timer_struct.rb', line 43

def to_json(*a)
  attribs = @attributes.merge(
    "Started" => '/Date(%d)/' % @attributes['Started'], 
    "DurationMilliseconds" => @attributes['Root']['DurationMilliseconds']
  )        
  ::JSON.generate(attribs, :max_nesting => 100)
end