Class: Stackprofiler::Run
- Inherits:
-
Object
- Object
- Stackprofiler::Run
- Defined in:
- lib/stackprofiler/run_data_source.rb
Instance Attribute Summary collapse
-
#profile ⇒ Object
Returns the value of attribute profile.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #code_cache ⇒ Object
- #duration ⇒ Object
- #gem_breakdown ⇒ Object
-
#initialize(url, profile, timestamp) ⇒ Run
constructor
A new instance of Run.
- #stacks(use_weights = false) ⇒ Object
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, ) @url = url @profile = profile @timestamp = end |
Instance Attribute Details
#profile ⇒ Object
Returns the value of attribute profile.
4 5 6 |
# File 'lib/stackprofiler/run_data_source.rb', line 4 def profile @profile end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
5 6 7 |
# File 'lib/stackprofiler/run_data_source.rb', line 5 def @timestamp end |
#url ⇒ Object
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_cache ⇒ Object
13 14 15 |
# File 'lib/stackprofiler/run_data_source.rb', line 13 def code_cache @code_cache ||= RunCodeCache.new @profile end |
#duration ⇒ Object
35 36 37 |
# File 'lib/stackprofiler/run_data_source.rb', line 35 def duration profile[:samples] * profile[:interval] / 1e6 end |
#gem_breakdown ⇒ Object
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 |