Class: Rack::MiniProfiler::TimerStruct::Page
- Defined in:
- lib/mini_profiler/timer_struct/page.rb
Overview
TimerStruct::Page
Root: TimerStruct::Request
:has_many TimerStruct::Request children
:has_many TimerStruct::Sql children
:has_many TimerStruct::Custom children
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #attributes_to_serialize ⇒ Object
- #duration_ms ⇒ Object
- #duration_ms_in_sql ⇒ Object
- #extra_json ⇒ Object
-
#initialize(env) ⇒ Page
constructor
A new instance of Page.
- #name ⇒ Object
- #page_name(env) ⇒ Object
- #root ⇒ Object
- #to_json(*a) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(env) ⇒ Page
Returns a new instance of Page.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 60 def initialize(env) timer_id = MiniProfiler.generate_id started_at = (Time.now.to_f * 1000).to_i started = (Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000).to_i machine_name = env['SERVER_NAME'] super( id: timer_id, name: page_name(env), started: started, started_at: started_at, machine_name: machine_name, level: 0, user: "unknown user", has_user_viewed: false, client_timings: nil, duration_milliseconds: 0, has_trivial_timings: true, has_all_trivial_timings: false, trivial_duration_threshold_milliseconds: 2, head: nil, sql_count: 0, cached_sql_count: 0, duration_milliseconds_in_sql: 0, has_sql_timings: true, has_duplicate_sql_timings: false, executed_readers: 0, executed_scalars: 0, executed_non_queries: 0, custom_timing_names: [], custom_timing_stats: {}, custom_fields: {}, has_flamegraph: false, flamegraph: nil ) self[:request_method] = env['REQUEST_METHOD'] self[:request_path] = env['PATH_INFO'] name = "#{env['REQUEST_METHOD']} http://#{env['SERVER_NAME']}:#{env['SERVER_PORT']}#{env['SCRIPT_NAME']}#{page_name(env)}" self[:root] = TimerStruct::Request.createRoot(name, self) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
58 59 60 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 58 def attributes @attributes end |
Class Method Details
.from_hash(hash) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 14 def from_hash(hash) hash = symbolize_hash(hash) if hash.key?(:custom_timing_names) hash[:custom_timing_names] = [] end hash.delete(:started_formatted) if hash.key?(:duration_milliseconds) hash[:duration_milliseconds] = 0 end page = self.allocate page.instance_variable_set(:@attributes, hash) page end |
Instance Method Details
#as_json(options = nil) ⇒ Object
132 133 134 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 132 def as_json( = nil) super().slice(*attributes_to_serialize.map(&:to_s)).merge!(extra_json) end |
#attributes_to_serialize ⇒ Object
124 125 126 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 124 def attributes_to_serialize @attributes.keys - [:flamegraph] end |
#duration_ms ⇒ Object
112 113 114 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 112 def duration_ms @attributes[:root][:duration_milliseconds] end |
#duration_ms_in_sql ⇒ Object
116 117 118 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 116 def duration_ms_in_sql @attributes[:duration_milliseconds_in_sql] end |
#extra_json ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 136 def extra_json { started_formatted: '/Date(%d)/' % @attributes[:started_at], duration_milliseconds: @attributes[:root][:duration_milliseconds], custom_timing_names: @attributes[:custom_timing_stats].keys.sort } end |
#name ⇒ Object
100 101 102 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 100 def name @attributes[:name] end |
#page_name(env) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 104 def page_name(env) if env['QUERY_STRING'] && env['QUERY_STRING'] != "" env['PATH_INFO'] + "?" + env['QUERY_STRING'] else env['PATH_INFO'] end end |
#root ⇒ Object
120 121 122 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 120 def root @attributes[:root] end |
#to_json(*a) ⇒ Object
128 129 130 |
# File 'lib/mini_profiler/timer_struct/page.rb', line 128 def to_json(*a) ::JSON.generate(@attributes.slice(*attributes_to_serialize).merge(extra_json)) end |