stackprof 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stackprof (0.2.5)
4
+ stackprof (0.2.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -7,6 +7,19 @@ and written as a replacement for [perftools.rb](https://github.com/tmm1/perftool
7
7
 
8
8
  ### getting started
9
9
 
10
+ #### Install
11
+
12
+ In your Gemfile add:
13
+
14
+ ```ruby
15
+ gem 'stackprof'
16
+ ```
17
+
18
+ Then run `$ bundle install`. Alternatively you can run `$ gem install stackprof`.
19
+
20
+
21
+ #### Run
22
+
10
23
  in ruby:
11
24
 
12
25
  ``` ruby
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ task :default => :test
4
4
  # Packaging
5
5
  # ==========================================================
6
6
 
7
- GEMSPEC = eval(File.read('stackprof.gemspec'))
7
+ GEMSPEC = Gem::Specification::load('stackprof.gemspec')
8
8
 
9
9
  require 'rubygems/package_task'
10
10
  Gem::PackageTask.new(GEMSPEC) do |pkg|
@@ -92,7 +92,7 @@ stackprof_start(int argc, VALUE *argv, VALUE self)
92
92
  if (mode == sym_object) {
93
93
  if (!RTEST(interval)) interval = INT2FIX(1);
94
94
 
95
- objtracer = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ, stackprof_newobj_handler, 0);
95
+ objtracer = rb_tracepoint_new(Qnil, RUBY_INTERNAL_EVENT_NEWOBJ, stackprof_newobj_handler, 0);
96
96
  rb_tracepoint_enable(objtracer);
97
97
  } else if (mode == sym_wall || mode == sym_cpu) {
98
98
  if (!RTEST(interval)) interval = INT2FIX(1000);
@@ -11,14 +11,15 @@ module StackProf
11
11
  Middleware.interval = options[:interval] || 1000
12
12
  Middleware.enabled = options[:enabled]
13
13
  Middleware.path = options[:path] || 'tmp'
14
- at_exit{ Middleware.save? } if options[:save_at_exit]
14
+ at_exit{ Middleware.save } if options[:save_at_exit]
15
15
  end
16
16
 
17
17
  def call(env)
18
- StackProf.start(mode: Middleware.mode, interval: Middleware.interval) if Middleware.enabled?
18
+ enabled = Middleware.enabled?(env)
19
+ StackProf.start(mode: Middleware.mode, interval: Middleware.interval) if enabled
19
20
  @app.call(env)
20
21
  ensure
21
- if Middleware.enabled?
22
+ if enabled
22
23
  StackProf.stop
23
24
  if @num_reqs && (@num_reqs-=1) == 0
24
25
  @num_reqs = @options[:save_every]
@@ -29,7 +30,14 @@ module StackProf
29
30
 
30
31
  class << self
31
32
  attr_accessor :enabled, :mode, :interval, :path
32
- alias enabled? enabled
33
+
34
+ def enabled?(env)
35
+ if enabled.respond_to?(:call)
36
+ enabled.call(env)
37
+ else
38
+ enabled
39
+ end
40
+ end
33
41
 
34
42
  def save(filename = nil)
35
43
  if results = StackProf.results
@@ -285,40 +285,6 @@ module StackProf
285
285
  end
286
286
  end
287
287
 
288
- private
289
-
290
- def root_frames
291
- frames.select{ |addr, frame| callers_for(addr).size == 0 }
292
- end
293
-
294
- def callers_for(addr)
295
- @callers_for ||= {}
296
- @callers_for[addr] ||= data[:frames].map{ |id, other| [other[:name], other[:edges][addr]] if other[:edges] && other[:edges].include?(addr) }.compact
297
- end
298
-
299
- def source_display(f, file, lines, range=nil)
300
- File.readlines(file).each_with_index do |code, i|
301
- next unless range.nil? || range.include?(i)
302
- if lines and lineinfo = lines[i+1]
303
- total_samples, samples = lineinfo
304
- if version == 1.0
305
- samples = total_samples
306
- f.printf "% 5d % 7s | % 5d | %s", samples, "(%2.1f%%)" % (100.0*samples/overall_samples), i+1, code
307
- elsif samples > 0
308
- f.printf "% 5d % 8s / % 5d % 7s | % 5d | %s", total_samples, "(%2.1f%%)" % (100.0*total_samples/overall_samples), samples, "(%2.1f%%)" % (100.0*samples/overall_samples), i+1, code
309
- else
310
- f.printf "% 5d % 8s | % 5d | %s", total_samples, "(%3.1f%%)" % (100.0*total_samples/overall_samples), i+1, code
311
- end
312
- else
313
- if version == 1.0
314
- f.printf " | % 5d | %s", i+1, code
315
- else
316
- f.printf " | % 5d | %s", i+1, code
317
- end
318
- end
319
- end
320
- end
321
-
322
288
  def +(other)
323
289
  raise ArgumentError, "cannot combine #{other.class}" unless self.class == other.class
324
290
  raise ArgumentError, "cannot combine #{modeline} with #{other.modeline}" unless modeline == other.modeline
@@ -364,5 +330,39 @@ module StackProf
364
330
 
365
331
  self.class.new(data)
366
332
  end
333
+
334
+ private
335
+ def root_frames
336
+ frames.select{ |addr, frame| callers_for(addr).size == 0 }
337
+ end
338
+
339
+ def callers_for(addr)
340
+ @callers_for ||= {}
341
+ @callers_for[addr] ||= data[:frames].map{ |id, other| [other[:name], other[:edges][addr]] if other[:edges] && other[:edges].include?(addr) }.compact
342
+ end
343
+
344
+ def source_display(f, file, lines, range=nil)
345
+ File.readlines(file).each_with_index do |code, i|
346
+ next unless range.nil? || range.include?(i)
347
+ if lines and lineinfo = lines[i+1]
348
+ total_samples, samples = lineinfo
349
+ if version == 1.0
350
+ samples = total_samples
351
+ f.printf "% 5d % 7s | % 5d | %s", samples, "(%2.1f%%)" % (100.0*samples/overall_samples), i+1, code
352
+ elsif samples > 0
353
+ f.printf "% 5d % 8s / % 5d % 7s | % 5d | %s", total_samples, "(%2.1f%%)" % (100.0*total_samples/overall_samples), samples, "(%2.1f%%)" % (100.0*samples/overall_samples), i+1, code
354
+ else
355
+ f.printf "% 5d % 8s | % 5d | %s", total_samples, "(%3.1f%%)" % (100.0*total_samples/overall_samples), i+1, code
356
+ end
357
+ else
358
+ if version == 1.0
359
+ f.printf " | % 5d | %s", i+1, code
360
+ else
361
+ f.printf " | % 5d | %s", i+1, code
362
+ end
363
+ end
364
+ end
365
+ end
366
+
367
367
  end
368
368
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'stackprof'
3
- s.version = '0.2.6'
3
+ s.version = '0.2.7'
4
4
  s.homepage = 'http://github.com/tmm1/stackprof'
5
5
 
6
6
  s.authors = 'Aman Gupta'
@@ -38,4 +38,26 @@ class StackProf::MiddlewareTest < Test::Unit::TestCase
38
38
  StackProf::Middleware.save
39
39
  end
40
40
 
41
+ def test_enabled_should_use_a_proc_if_passed
42
+ env = {}
43
+
44
+ StackProf::Middleware.new(Object.new, enabled: Proc.new{ false })
45
+ refute StackProf::Middleware.enabled?(env)
46
+
47
+ StackProf::Middleware.new(Object.new, enabled: Proc.new{ true })
48
+ assert StackProf::Middleware.enabled?(env)
49
+ end
50
+
51
+ def test_enabled_should_use_a_proc_if_passed_and_use_the_request_env
52
+ enable_proc = Proc.new {|env| env['PROFILE'] }
53
+
54
+ env = Hash.new { false }
55
+ StackProf::Middleware.new(Object.new, enabled: enable_proc)
56
+ refute StackProf::Middleware.enabled?(env)
57
+
58
+ env = Hash.new { true}
59
+ StackProf::Middleware.new(Object.new, enabled: enable_proc)
60
+ assert StackProf::Middleware.enabled?(env)
61
+ end
62
+
41
63
  end
metadata CHANGED
@@ -1,41 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackprof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Aman Gupta
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-02-25 00:00:00.000000000 Z
12
+ date: 2014-06-17 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rake-compiler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - "~>"
19
+ - - ~>
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0.9'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - "~>"
27
+ - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.9'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: mocha
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - "~>"
35
+ - - ~>
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0.14'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - "~>"
43
+ - - ~>
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0.14'
41
46
  description: stackprof is a fast sampling profiler for ruby code, with cpu, wallclock
@@ -49,7 +54,7 @@ extensions:
49
54
  - ext/extconf.rb
50
55
  extra_rdoc_files: []
51
56
  files:
52
- - ".gitignore"
57
+ - .gitignore
53
58
  - Gemfile
54
59
  - Gemfile.lock
55
60
  - README.md
@@ -74,26 +79,27 @@ files:
74
79
  homepage: http://github.com/tmm1/stackprof
75
80
  licenses:
76
81
  - MIT
77
- metadata: {}
78
82
  post_install_message:
79
83
  rdoc_options: []
80
84
  require_paths:
81
85
  - lib
82
86
  required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
83
88
  requirements:
84
- - - ">="
89
+ - - ! '>='
85
90
  - !ruby/object:Gem::Version
86
91
  version: '0'
87
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
88
94
  requirements:
89
- - - ">="
95
+ - - ! '>='
90
96
  - !ruby/object:Gem::Version
91
97
  version: '0'
92
98
  requirements: []
93
99
  rubyforge_project:
94
- rubygems_version: 2.2.0.rc.1
100
+ rubygems_version: 1.8.23
95
101
  signing_key:
96
- specification_version: 4
102
+ specification_version: 3
97
103
  summary: sampling callstack-profiler for ruby 2.1+
98
104
  test_files: []
99
105
  has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: e783faab7c8c97296d52c602c971eddb3e4c85eb
4
- data.tar.gz: 4952c5aec78540e9a2509e37f6e2195f56568712
5
- SHA512:
6
- metadata.gz: 3a0f36b8202aefb65836dbe71b359fbcea3f7ecf4252fce52ec127f47db0ea9995f177f808c631d6803f5b40e1697d2e065028a15ceb17387351b2d3fa7af0e7
7
- data.tar.gz: 685c58d929c5681693c64a1a63e939382171420ecc83856cabc9efeb2d0f7e65c25802d6f0c5c47e0b6def8addda2f0b78985048c7829f6b23e7ccb636be79ff