Class: Stackprofiler::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/stackprofiler/run_data_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, profile, timestamp) ⇒ Run

Returns a new instance of Run.



7
8
9
10
11
# File 'lib/stackprofiler/run_data_source.rb', line 7

def initialize(url, profile, timestamp)
  @url = url
  @profile = profile
  @timestamp = timestamp
end

Instance Attribute Details

#profileObject

Returns the value of attribute profile.



4
5
6
# File 'lib/stackprofiler/run_data_source.rb', line 4

def profile
  @profile
end

#timestampObject

Returns the value of attribute timestamp.



5
6
7
# File 'lib/stackprofiler/run_data_source.rb', line 5

def timestamp
  @timestamp
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/stackprofiler/run_data_source.rb', line 3

def url
  @url
end

Instance Method Details

#durationObject



29
30
31
# File 'lib/stackprofiler/run_data_source.rb', line 29

def duration
  profile[:samples] * profile[:interval] / 1e6
end

#gem_breakdownObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/stackprofiler/run_data_source.rb', line 33

def gem_breakdown
  bottom_frames = stacks.map &:last
  paths = bottom_frames.map {|addr| profile[:frames][addr][:file] }

  gems = paths.map do |p|
    case p
      when %r{gems/(\D\w+)}
        $1
      when %r{#{RbConfig::CONFIG['rubylibdir']}}
        'stdlib'
      else
        '(app)'
    end
  end

  gems.group_by {|g| g }.map {|k, v| [k, v.count] }.sort_by(&:last).reverse.to_h
end

#stacksObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stackprofiler/run_data_source.rb', line 13

def stacks
  @stacks ||= begin
    off = 0
    stacks = []
    raw = @profile[:raw]
    while off < raw.length
      len = raw[off]
      these_frames = raw[off + 1..off + len]
      off += len + 2

      stacks.push these_frames
    end
    stacks
  end
end