Class: Rack::MiniProfiler::TimerStruct::Request
- Defined in:
- lib/mini_profiler/timer_struct/request.rb
Instance Attribute Summary collapse
-
#children_duration ⇒ Object
Returns the value of attribute children_duration.
Class Method Summary collapse
Instance Method Summary collapse
- #add_child(name) ⇒ Object
- #add_custom(type, elapsed_ms, page) ⇒ Object
- #add_sql(query, elapsed_ms, page, params = nil, skip_backtrace = false, full_backtrace = false) ⇒ Object
- #children ⇒ Object
- #custom_timings ⇒ Object
- #depth ⇒ Object
- #duration_ms ⇒ Object
- #duration_ms_in_sql ⇒ Object
-
#initialize(name, page, parent) ⇒ Request
constructor
A new instance of Request.
- #name ⇒ Object
- #record_time(milliseconds = nil) ⇒ Object
- #sql_timings ⇒ Object
- #start ⇒ Object
- #start_ms ⇒ Object
Methods inherited from Base
#[], #[]=, #as_json, #attributes, #to_json
Constructor Details
#initialize(name, page, parent) ⇒ Request
Returns a new instance of Request.
14 15 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 42 43 44 45 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 14 def initialize(name, page, parent) start_millis = (Time.now.to_f * 1000).to_i - page[:started] depth = parent ? parent.depth + 1 : 0 super( :id => MiniProfiler.generate_id, :name => name, :duration_milliseconds => 0, :duration_without_children_milliseconds => 0, :start_milliseconds => start_millis, :parent_timing_id => nil, :children => [], :has_children => false, :key_values => nil, :has_sql_timings => false, :has_duplicate_sql_timings => false, :trivial_duration_threshold_milliseconds => 2, :sql_timings => [], :sql_timings_duration_milliseconds => 0, :is_trivial => false, :is_root => false, :depth => depth, :executed_readers => 0, :executed_scalars => 0, :executed_non_queries => 0, :custom_timing_stats => {}, :custom_timings => {} ) @children_duration = 0 @start = Time.now @parent = parent @page = page end |
Instance Attribute Details
#children_duration ⇒ Object
Returns the value of attribute children_duration.
12 13 14 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 12 def children_duration @children_duration end |
Class Method Details
.createRoot(name, page) ⇒ Object
6 7 8 9 10 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 6 def self.createRoot(name, page) TimerStruct::Request.new(name, page, nil).tap do |timer| timer[:is_root] = true end end |
Instance Method Details
#add_child(name) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 83 def add_child(name) TimerStruct::Request.new(name, @page, self).tap do |timer| self[:children].push(timer) self[:has_children] = true timer[:parent_timing_id] = self[:id] timer[:depth] = self[:depth] + 1 end end |
#add_custom(type, elapsed_ms, page) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 102 def add_custom(type, elapsed_ms, page) TimerStruct::Custom.new(type, elapsed_ms, page, self).tap do |timer| timer[:parent_timing_id] = self[:id] self[:custom_timings][type] ||= [] self[:custom_timings][type].push(timer) self[:custom_timing_stats][type] ||= {:count => 0, :duration => 0.0} self[:custom_timing_stats][type][:count] += 1 self[:custom_timing_stats][type][:duration] += elapsed_ms page[:custom_timing_stats][type] ||= {:count => 0, :duration => 0.0} page[:custom_timing_stats][type][:count] += 1 page[:custom_timing_stats][type][:duration] += elapsed_ms end end |
#add_sql(query, elapsed_ms, page, params = nil, skip_backtrace = false, full_backtrace = false) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 92 def add_sql(query, elapsed_ms, page, params = nil, skip_backtrace = false, full_backtrace = false) TimerStruct::Sql.new(query, elapsed_ms, page, self, params, skip_backtrace, full_backtrace).tap do |timer| self[:sql_timings].push(timer) timer[:parent_timing_id] = self[:id] self[:has_sql_timings] = true self[:sql_timings_duration_milliseconds] += elapsed_ms page[:duration_milliseconds_in_sql] += elapsed_ms end end |
#children ⇒ Object
71 72 73 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 71 def children self[:children] end |
#custom_timings ⇒ Object
75 76 77 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 75 def custom_timings self[:custom_timings] end |
#depth ⇒ Object
67 68 69 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 67 def depth self[:depth] end |
#duration_ms ⇒ Object
51 52 53 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 51 def duration_ms self[:duration_milliseconds] end |
#duration_ms_in_sql ⇒ Object
55 56 57 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 55 def duration_ms_in_sql @attributes[:duration_milliseconds_in_sql] end |
#name ⇒ Object
47 48 49 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 47 def name @attributes[:name] end |
#record_time(milliseconds = nil) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 119 def record_time(milliseconds = nil) milliseconds ||= (Time.now - @start) * 1000 self[:duration_milliseconds] = milliseconds self[:is_trivial] = true if milliseconds < self[:trivial_duration_threshold_milliseconds] self[:duration_without_children_milliseconds] = milliseconds - @children_duration if @parent @parent.children_duration += milliseconds end end |
#sql_timings ⇒ Object
79 80 81 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 79 def sql_timings self[:sql_timings] end |
#start ⇒ Object
63 64 65 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 63 def start @start end |
#start_ms ⇒ Object
59 60 61 |
# File 'lib/mini_profiler/timer_struct/request.rb', line 59 def start_ms self[:start_milliseconds] end |