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
- #duration ⇒ Object
- #gem_breakdown ⇒ Object
-
#initialize(url, profile, timestamp) ⇒ Run
constructor
A new instance of Run.
- #stacks ⇒ 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
#duration ⇒ Object
29 30 31 |
# File 'lib/stackprofiler/run_data_source.rb', line 29 def duration profile[:samples] * profile[:interval] / 1e6 end |
#gem_breakdown ⇒ Object
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 |
#stacks ⇒ Object
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 |