Class: Rack::MiniProfiler::RequestTimerStruct

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TimerStruct

#[], #[]=, #attributes, #to_json

Constructor Details

#initialize(name, page, parent) ⇒ RequestTimerStruct

Returns a new instance of RequestTimerStruct.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mini_profiler/request_timer_struct.rb', line 16

def initialize(name, page, parent)
  super("Id" => MiniProfiler.generate_id,
        "Name" => name,
        "DurationMilliseconds" => 0,
        "DurationWithoutChildrenMilliseconds"=> 0,
        "StartMilliseconds" => (Time.now.to_f * 1000).to_i - page['Started'],
        "ParentTimingId" => nil,
        "Children" => [],
        "HasChildren"=> false,
        "KeyValues" => nil,
        "HasSqlTimings"=> false,
        "HasDuplicateSqlTimings"=> false,
        "TrivialDurationThresholdMilliseconds" => 2,
        "SqlTimings" => [],
        "SqlTimingsDurationMilliseconds"=> 0,
        "IsTrivial"=> false,
        "IsRoot"=> false,
        "Depth"=> parent ? parent.depth + 1 : 0,
        "ExecutedReaders"=> 0,
        "ExecutedScalars"=> 0,
        "ExecutedNonQueries"=> 0)
  @children_duration = 0
  @start = Time.now
  @parent = parent
  @page = page
end

Instance Attribute Details

#children_durationObject

Returns the value of attribute children_duration.



14
15
16
# File 'lib/mini_profiler/request_timer_struct.rb', line 14

def children_duration
  @children_duration
end

Class Method Details

.createRoot(name, page) ⇒ Object



8
9
10
11
12
# File 'lib/mini_profiler/request_timer_struct.rb', line 8

def self.createRoot(name, page)
  rt = RequestTimerStruct.new(name, page, nil)
  rt["IsRoot"]= true
  rt
end

Instance Method Details

#add_child(name) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/mini_profiler/request_timer_struct.rb', line 63

def add_child(name)
  request_timer =  RequestTimerStruct.new(name, @page, self)
  self['Children'].push(request_timer)
  self['HasChildren'] = true
  request_timer['ParentTimingId'] = self['Id']
  request_timer['Depth'] = self['Depth'] + 1
  request_timer
end

#add_sql(query, elapsed_ms, page, skip_backtrace = false, full_backtrace = false) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/mini_profiler/request_timer_struct.rb', line 72

def add_sql(query, elapsed_ms, page, skip_backtrace = false, full_backtrace = false)
  timer = SqlTimerStruct.new(query, elapsed_ms, page, self , skip_backtrace, full_backtrace)
  timer['ParentTimingId'] = self['Id']
  self['SqlTimings'].push(timer)
  self['HasSqlTimings'] = true
  self['SqlTimingsDurationMilliseconds'] += elapsed_ms
  page['DurationMillisecondsInSql'] += elapsed_ms        
  timer
end

#childrenObject



59
60
61
# File 'lib/mini_profiler/request_timer_struct.rb', line 59

def children
  self['Children']
end

#depthObject



55
56
57
# File 'lib/mini_profiler/request_timer_struct.rb', line 55

def depth
  self['Depth']
end

#duration_msObject



43
44
45
# File 'lib/mini_profiler/request_timer_struct.rb', line 43

def duration_ms
  self['DurationMilliseconds']
end

#record_time(milliseconds = nil) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mini_profiler/request_timer_struct.rb', line 82

def record_time(milliseconds = nil)
  milliseconds ||= (Time.now - @start) * 1000
  self['DurationMilliseconds'] = milliseconds
  self['IsTrivial'] = true if milliseconds < self["TrivialDurationThresholdMilliseconds"]
  self['DurationWithoutChildrenMilliseconds'] = milliseconds - @children_duration
  
  if @parent
    @parent.children_duration += milliseconds
  end

end

#startObject



51
52
53
# File 'lib/mini_profiler/request_timer_struct.rb', line 51

def start
  @start
end

#start_msObject



47
48
49
# File 'lib/mini_profiler/request_timer_struct.rb', line 47

def start_ms
  self['StartMilliseconds']
end