stackprof 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba362f7b8c12e89a30cc376280443aef51ce7ac6
4
- data.tar.gz: 561f31e9f8b90a728dec5c9d6090f4bd7701228a
3
+ metadata.gz: a10d79a11e17b11b5b706c69c9c5b5546b7fabe9
4
+ data.tar.gz: 41e9454828e293709c63bb96ecff91530f2fb8da
5
5
  SHA512:
6
- metadata.gz: 85a79f6edbf81e520b90d4f35d615c475297acdfe7b5db4277b93bc1e342ac8cc2aebdd56990bca1e82258020f270d6c28bd2098df27f90f320c005da07e9cae
7
- data.tar.gz: 7d17bca5d3f356f63d1eec962e40dd4e50520e4a7b2c602b748f94779a9fb147566cc4439ff3cc0c619a687e4eff6e2da5a997240f1542e09849802a4ee7e09a
6
+ metadata.gz: 0e3d5900059d2531409bba444a58679e50227d656ab450d5fc04bc8a8fcec9d0055224599369cab3304dbd8366c06957af06978b12f28cb359d8f83455c409ca
7
+ data.tar.gz: 34c673bbe0c60795d7b97a39d2ab1bace18a6377dfd7c5f63dca31fc2c2e0447e8c420e5663e9b7c61cd11365d5cd4c2e2bc6d0f23f8b414ddb3c7083b82867a
data/Gemfile.lock CHANGED
@@ -1,11 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stackprof (0.2.0)
4
+ stackprof (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ metaclass (0.0.1)
10
+ mocha (0.14.0)
11
+ metaclass (~> 0.0.1)
9
12
  rake (10.1.0)
10
13
  rake-compiler (0.9.1)
11
14
  rake
@@ -14,5 +17,6 @@ PLATFORMS
14
17
  ruby
15
18
 
16
19
  DEPENDENCIES
20
+ mocha
17
21
  rake-compiler
18
22
  stackprof!
data/bin/stackprof CHANGED
@@ -11,15 +11,15 @@ options = {
11
11
  parser = OptionParser.new(ARGV) do |o|
12
12
  o.banner = "Usage: stackprof [file.dump]+ [--text|--method=NAME|--callgrind|--graphviz]"
13
13
 
14
- o.on('--text', 'Text summary (default)'){ options[:format] = :text }
15
- o.on('--method [grep]', 'Zoom into specified method'){ |f| options[:format] = :method; options[:filter] = f }
14
+ o.on('--text', 'Text summary per method (default)'){ options[:format] = :text }
16
15
  o.on('--files', 'List of files'){ |f| options[:format] = :files }
17
- o.on('--file [grep]', 'Show annotated code for specified file'){ |f| options[:format] = :file; options[:filter] = f }
16
+ o.on('--limit=[num]', Integer, 'Limit --text or --files output to N lines'){ |n| options[:limit] = n }
17
+ o.on('--sort-total', "Sort --text or --files output on total samples\n\n"){ options[:sort] = true }
18
+ o.on('--method=[grep]', 'Zoom into specified method'){ |f| options[:format] = :method; options[:filter] = f }
19
+ o.on('--file=[grep]', 'Show annotated code for specified file'){ |f| options[:format] = :file; options[:filter] = f }
18
20
  o.on('--callgrind', 'Callgrind output (use with kcachegrind, gprof2dot)'){ options[:format] = :callgrind }
19
- o.on('--graphviz', 'Graphviz output (use with dot)'){ options[:format] = :graphviz }
20
- o.on('--debug'){ options[:format] = :debug }
21
- o.on('--limit [num]', Integer, 'Limit --text output to N lines'){ |n| options[:limit] = n }
22
- o.on('--sort-total', 'Sort --text output on total samples'){ options[:sort] = true }
21
+ o.on('--graphviz', "Graphviz output (use with dot)\n\n"){ options[:format] = :graphviz }
22
+ o.on('--debug', 'Pretty print raw profile data'){ options[:format] = :debug }
23
23
  end
24
24
 
25
25
  parser.parse!
@@ -3,12 +3,14 @@ require 'fileutils'
3
3
  module StackProf
4
4
  class Middleware
5
5
  def initialize(app, options = {})
6
- @app = app
7
- @options = options
8
- @num_reqs = options[:save_every] || nil
9
- Middleware.mode = options[:mode] || :cpu
6
+ @app = app
7
+ @options = options
8
+ @num_reqs = options[:save_every] || nil
9
+
10
+ Middleware.mode = options[:mode] || :cpu
10
11
  Middleware.interval = options[:interval] || 1000
11
- Middleware.enabled = options[:enabled]
12
+ Middleware.enabled = options[:enabled]
13
+ Middleware.path = options[:path] || 'tmp'
12
14
  at_exit{ Middleware.save? } if options[:save_at_exit]
13
15
  end
14
16
 
@@ -26,17 +28,19 @@ module StackProf
26
28
  end
27
29
 
28
30
  class << self
29
- attr_accessor :enabled, :mode, :interval
31
+ attr_accessor :enabled, :mode, :interval, :path
30
32
  alias enabled? enabled
31
33
 
32
34
  def save
33
35
  if results = StackProf.results
34
- FileUtils.mkdir_p('tmp')
35
- File.open("tmp/stackprof-#{results[:mode]}-#{Process.pid}-#{Time.now.to_i}.dump", 'wb') do |f|
36
+ FileUtils.mkdir_p(Middleware.path)
37
+ filename = "stackprof-#{results[:mode]}-#{Process.pid}-#{Time.now.to_i}.dump"
38
+ File.open(File.join(Middleware.path, filename), 'wb') do |f|
36
39
  f.write Marshal.dump(results)
37
40
  end
38
41
  end
39
42
  end
43
+
40
44
  end
41
45
  end
42
46
  end
@@ -92,11 +92,11 @@ module StackProf
92
92
  fontsize = (1.0 * call / max_samples) * 28 + 10
93
93
  size = (1.0 * total / overall_samples) * 2.0 + 0.5
94
94
 
95
- f.puts " #{frame} [size=#{size}] [fontsize=#{fontsize}] [penwidth=\"#{size}\"] [shape=box] [label=\"#{info[:name]}\\n#{sample}\"];"
95
+ f.puts " \"#{frame}\" [size=#{size}] [fontsize=#{fontsize}] [penwidth=\"#{size}\"] [shape=box] [label=\"#{info[:name]}\\n#{sample}\"];"
96
96
  if edges = info[:edges]
97
97
  edges.each do |edge, weight|
98
98
  size = (1.0 * weight / overall_samples) * 2.0 + 0.5
99
- f.puts " #{frame} -> #{edge} [label=\"#{weight}\"] [weight=\"#{weight}\"] [penwidth=\"#{size}\"];"
99
+ f.puts " \"#{frame}\" -> \"#{edge}\" [label=\"#{weight}\"] [weight=\"#{weight}\"] [penwidth=\"#{size}\"];"
100
100
  end
101
101
  end
102
102
  end
@@ -171,7 +171,7 @@ module StackProf
171
171
 
172
172
  if callees = info[:edges]
173
173
  f.printf " callees (%d total):\n", info[:total_samples]-info[:samples]
174
- callees = callees.map{ |k, weight| [data[:frames][k][:name], weight] }
174
+ callees = callees.map{ |k, weight| [data[:frames][k][:name], weight] }.sort_by{ |k,v| -v }
175
175
  callees.each do |name, weight|
176
176
  f.printf " % 5d (% 8s) %s\n", weight, "%3.1f%%" % (100.0*weight/(info[:total_samples]-info[:samples])), name
177
177
  end
@@ -188,7 +188,7 @@ module StackProf
188
188
  list = list.first(limit) if limit
189
189
  list.each do |file, vals|
190
190
  total_samples, samples = *vals
191
- f.printf "% 5d (%2.1f%%) / % 5d (%2.1f%%) %s\n", total_samples, (100.0*total_samples/overall_samples), samples, (100.0*samples/overall_samples), file
191
+ f.printf "% 5d (%5.1f%%) / % 5d (%5.1f%%) %s\n", total_samples, (100.0*total_samples/overall_samples), samples, (100.0*samples/overall_samples), file
192
192
  end
193
193
  end
194
194
 
data/stackprof.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'stackprof'
3
- s.version = '0.2.1'
3
+ s.version = '0.2.2'
4
4
  s.homepage = 'http://github.com/tmm1/stackprof'
5
5
 
6
6
  s.authors = 'Aman Gupta'
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.license = 'MIT'
19
19
 
20
20
  s.add_development_dependency 'rake-compiler'
21
+ s.add_development_dependency 'mocha'
21
22
  end
@@ -0,0 +1,41 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'stackprof'
3
+ require 'stackprof/middleware'
4
+ require 'test/unit'
5
+ require 'mocha/setup'
6
+
7
+ class StackProf::MiddlewareTest < Test::Unit::TestCase
8
+
9
+ def test_path_default
10
+ StackProf::Middleware.new(Object.new)
11
+
12
+ assert_equal 'tmp', StackProf::Middleware.path
13
+ end
14
+
15
+ def test_path_custom
16
+ StackProf::Middleware.new(Object.new, { path: '/foo' })
17
+
18
+ assert_equal '/foo', StackProf::Middleware.path
19
+ end
20
+
21
+ def test_save_default
22
+ StackProf::Middleware.new(Object.new)
23
+
24
+ StackProf.stubs(:results).returns({ mode: 'foo' })
25
+ FileUtils.expects(:mkdir_p).with('tmp')
26
+ File.expects(:open).with(regexp_matches(/^tmp\/stackprof-foo/), 'wb')
27
+
28
+ StackProf::Middleware.save
29
+ end
30
+
31
+ def test_save_custom
32
+ StackProf::Middleware.new(Object.new, { path: '/foo' })
33
+
34
+ StackProf.stubs(:results).returns({ mode: 'foo' })
35
+ FileUtils.expects(:mkdir_p).with('/foo')
36
+ File.expects(:open).with(regexp_matches(/^\/foo\/stackprof-foo/), 'wb')
37
+
38
+ StackProf::Middleware.save
39
+ end
40
+
41
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackprof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aman Gupta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-29 00:00:00.000000000 Z
11
+ date: 2014-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mocha
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: stackprof is a fast sampling profiler for ruby code, with cpu, wallclock
28
42
  and object allocation samplers.
29
43
  email: aman@tmm1.net
@@ -45,6 +59,7 @@ files:
45
59
  - lib/stackprof/report.rb
46
60
  - sample.rb
47
61
  - stackprof.gemspec
62
+ - test/test_middleware.rb
48
63
  - test/test_stackprof.rb
49
64
  homepage: http://github.com/tmm1/stackprof
50
65
  licenses: