Class: Rack::MiniProfiler::TimerStruct::Page

Inherits:
Base
  • Object
show all
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 Method Summary collapse

Methods inherited from Base

#[], #[]=, #attributes

Constructor Details

#initialize(env) ⇒ Page

Returns a new instance of Page.



11
12
13
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
# File 'lib/mini_profiler/timer_struct/page.rb', line 11

def initialize(env)
  timer_id     = MiniProfiler.generate_id
  page_name    = env['PATH_INFO']
  started_at   = (Time.now.to_f * 1000).to_i
  machine_name = env['SERVER_NAME']
  super(
    :id                                      => timer_id,
    :name                                    => page_name,
    :started                                 => 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,
    :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                     => {}
  )
  name = "#{env['REQUEST_METHOD']} http://#{env['SERVER_NAME']}:#{env['SERVER_PORT']}#{env['SCRIPT_NAME']}#{env['PATH_INFO']}"
  self[:root] = TimerStruct::Request.createRoot(name, self)
end

Instance Method Details

#as_json(options = nil) ⇒ Object



63
64
65
# File 'lib/mini_profiler/timer_struct/page.rb', line 63

def as_json(options = nil)
  super(options).merge!(extra_json)
end

#duration_msObject



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

def duration_ms
  @attributes[:root][:duration_milliseconds]
end

#duration_ms_in_sqlObject



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

def duration_ms_in_sql
  @attributes[:duration_milliseconds_in_sql]
end

#extra_jsonObject



67
68
69
70
71
72
73
# File 'lib/mini_profiler/timer_struct/page.rb', line 67

def extra_json
  {
    :started               => '/Date(%d)/' % @attributes[:started],
    :duration_milliseconds => @attributes[:root][:duration_milliseconds],
    :custom_timing_names   => @attributes[:custom_timing_stats].keys.sort
  }
end

#nameObject



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

def name
  @attributes[:name]
end

#rootObject



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

def root
  @attributes[:root]
end

#to_json(*a) ⇒ Object



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

def to_json(*a)
  ::JSON.generate(@attributes.merge(self.extra_json))
end