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

#code_cacheObject



13
14
15
# File 'lib/stackprofiler/run_data_source.rb', line 13

def code_cache
  @code_cache ||= RunCodeCache.new @profile
end

#durationObject



35
36
37
# File 'lib/stackprofiler/run_data_source.rb', line 35

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

#gem_breakdownObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/stackprofiler/run_data_source.rb', line 39

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

  gems = frames.map do |frame|
    case frame[:file]
      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

#stacks(use_weights = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/stackprofiler/run_data_source.rb', line 17

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

      times = use_weights ? weight : 1
      times.times { stacks.push these_frames }
    end
    stacks
  end
end