method_profiler 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - jruby
6
+ - rbx
7
+ - ree
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source :rubygems
2
2
 
3
3
  gemspec
4
+
5
+ gem 'rake', :group => :test
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://secure.travis-ci.org/change/method_profiler.png)](http://travis-ci.org/change/method_profiler) [![endorse](http://api.coderwall.com/jimmycuadra/endorsecount.png)](http://coderwall.com/jimmycuadra)
2
+
1
3
  # MethodProfiler
2
4
 
3
5
  **MethodProfiler** collects performance information about the methods in your objects and creates reports to help you identify slow methods. The collected data can be sorted in various ways, converted into an array, or pretty printed as a table.
@@ -25,31 +27,33 @@ The resulting chart includes each method, the minimum time it took to run, the m
25
27
 
26
28
  ```
27
29
  MethodProfiler results for: MyClass
28
- +------------------------+-----------+------------+--------------+-------------+
29
- | Method | Min Time | Max Time | Average Time | Total Calls |
30
- +------------------------+-----------+------------+--------------+-------------+
31
- | #accusamus_est | 32.086 ms | 324.140 ms | 160.252 ms | 3 |
32
- | #autem_iste! | 29.607 ms | 318.592 ms | 156.221 ms | 3 |
33
- | #distinctio_eos | 29.477 ms | 318.471 ms | 156.097 ms | 3 |
34
- | #laborum_fugit | 18.388 ms | 291.900 ms | 140.580 ms | 3 |
35
- | #suscipit_architecto | 12.036 ms | 272.279 ms | 130.247 ms | 3 |
36
- | #et_fugit | 2.794 ms | 11.658 ms | 6.185 ms | 3 |
37
- | #porro_rerum | 0.097 ms | 12.096 ms | 1.031 ms | 43 |
38
- | #provident_molestiae | 0.005 ms | 3.997 ms | 0.871 ms | 6 |
39
- | .nisi_inventore | 0.368 ms | 1.329 ms | 0.849 ms | 2 |
40
- | #quis_temporibus | 0.104 ms | 6.696 ms | 0.713 ms | 24 |
41
- | #labore_voluptatum | 0.004 ms | 8.834 ms | 0.447 ms | 86 |
42
- | #quia_est | 0.004 ms | 3.667 ms | 0.327 ms | 24 |
43
- | #ut_reiciendis | 0.004 ms | 2.842 ms | 0.250 ms | 24 |
44
- | #sint_quasi | 0.066 ms | 1.836 ms | 0.166 ms | 24 |
45
- | #sed_at | 0.067 ms | 0.119 ms | 0.078 ms | 24 |
46
- | #repellendus_suscipit | 0.054 ms | 0.128 ms | 0.067 ms | 24 |
47
- | #quas_nesciunt | 0.024 ms | 0.026 ms | 0.025 ms | 3 |
48
- | #iure_quis | 0.006 ms | 0.232 ms | 0.014 ms | 48 |
49
- | #dicta_ipsam | 0.005 ms | 0.068 ms | 0.013 ms | 24 |
50
- | #perspiciatis_aut | 0.006 ms | 0.006 ms | 0.006 ms | 3 |
51
- | #aperiam_laborum | 0.004 ms | 0.009 ms | 0.005 ms | 34 |
52
- +------------------------+-----------+------------+--------------+-------------+
30
+ +-----------------------+-----------+------------+--------------+------------+-------------+
31
+ | Method | Min Time | Max Time | Average Time | Total Time | Total Calls |
32
+ +-----------------------+-----------+------------+--------------+------------+-------------+
33
+ | #accusamus_est | 28.722 ms | 393.649 ms | 150.543 ms | 451.628 ms | 3 |
34
+ | #autem_iste! | 26.220 ms | 387.026 ms | 146.644 ms | 439.933 ms | 3 |
35
+ | #distinctio_eos | 26.095 ms | 386.903 ms | 146.520 ms | 439.559 ms | 3 |
36
+ | #laborum_fugit | 14.887 ms | 351.369 ms | 127.564 ms | 382.692 ms | 3 |
37
+ | #suscipit_architecto | 9.876 ms | 269.339 ms | 96.440 ms | 289.319 ms | 3 |
38
+ | #et_fugit | 0.005 ms | 63.101 ms | 10.704 ms | 64.225 ms | 6 |
39
+ | #porro_rerum | 2.970 ms | 15.137 ms | 7.126 ms | 21.378 ms | 3 |
40
+ | #provident_molestiae | 0.097 ms | 17.860 ms | 1.134 ms | 27.225 ms | 24 |
41
+ | #nisi_inventore | 0.098 ms | 15.076 ms | 1.044 ms | 54.272 ms | 52 |
42
+ | #quis_temporibus | 0.004 ms | 11.908 ms | 0.643 ms | 15.430 ms | 24 |
43
+ | .labore_voluptatum | 0.440 ms | 0.470 ms | 0.455 ms | 0.910 ms | 2 |
44
+ | #quia_est | 0.004 ms | 11.133 ms | 0.453 ms | 47.092 ms | 104 |
45
+ | #ut_reiciendis | 0.004 ms | 5.626 ms | 0.346 ms | 8.302 ms | 24 |
46
+ | #sint_quasi | 0.062 ms | 2.152 ms | 0.188 ms | 4.504 ms | 24 |
47
+ | #sed_at | 0.065 ms | 0.150 ms | 0.085 ms | 2.034 ms | 24 |
48
+ | #repellendus_suscipit | 0.051 ms | 0.122 ms | 0.070 ms | 1.684 ms | 24 |
49
+ | .quas_nesciunt | 0.058 ms | 0.124 ms | 0.062 ms | 4.303 ms | 69 |
50
+ | #iure_quis | 0.021 ms | 0.025 ms | 0.023 ms | 0.069 ms | 3 |
51
+ | #dicta_ipsam | 0.006 ms | 0.266 ms | 0.017 ms | 0.798 ms | 48 |
52
+ | #perspiciatis_aut | 0.004 ms | 0.068 ms | 0.013 ms | 0.314 ms | 24 |
53
+ | .aperiam_laborum | 0.005 ms | 0.015 ms | 0.006 ms | 0.438 ms | 69 |
54
+ | #voluptas_ratione | 0.005 ms | 0.007 ms | 0.006 ms | 0.018 ms | 3 |
55
+ | #ex_voluptas | 0.004 ms | 0.010 ms | 0.005 ms | 0.212 ms | 41 |
56
+ +-----------------------+-----------+------------+--------------+------------+-------------+
53
57
  ```
54
58
 
55
59
  ## Reporting
@@ -38,8 +38,8 @@ module MethodProfiler
38
38
 
39
39
  @obj.singleton_class.module_eval do
40
40
  singleton_methods_to_wrap.each do |method|
41
- define_method("#{method}_with_profiling") do |*args|
42
- profiler.send(:profile, method, true) { send("#{method}_without_profiling", *args) }
41
+ define_method("#{method}_with_profiling") do |*args, &block|
42
+ profiler.send(:profile, method, true) { send("#{method}_without_profiling", *args, &block) }
43
43
  end
44
44
 
45
45
  alias_method "#{method}_without_profiling", method
@@ -49,8 +49,8 @@ module MethodProfiler
49
49
 
50
50
  @obj.module_eval do
51
51
  instance_methods_to_wrap.each do |method|
52
- define_method("#{method}_with_profiling") do |*args|
53
- profiler.send(:profile, method) { send("#{method}_without_profiling", *args) }
52
+ define_method("#{method}_with_profiling") do |*args, &block|
53
+ profiler.send(:profile, method) { send("#{method}_without_profiling", *args, &block) }
54
54
  end
55
55
 
56
56
  alias_method "#{method}_without_profiling", method
@@ -85,13 +85,15 @@ module MethodProfiler
85
85
 
86
86
  @data.each do |method, records|
87
87
  total_calls = records.size
88
- average = records.reduce(:+) / total_calls
88
+ total_time = records.reduce(:+)
89
+ average = total_time / total_calls
89
90
  results << {
90
91
  :method => method,
91
92
  :min => records.min,
92
93
  :max => records.max,
93
94
  :average => average,
94
- :total_calls => total_calls
95
+ :total_time => total_time,
96
+ :total_calls => total_calls,
95
97
  }
96
98
  end
97
99
 
@@ -6,7 +6,7 @@ module MethodProfiler
6
6
  #
7
7
  class Report
8
8
  # Fields that can be passed to {#sort_by}.
9
- FIELDS = [:method, :min, :max, :average, :total_calls]
9
+ FIELDS = [:method, :min, :max, :average, :total_time, :total_calls]
10
10
 
11
11
  # Directions that can be passed to {#order}.
12
12
  DIRECTIONS = [:asc, :ascending, :desc, :descending]
@@ -73,13 +73,15 @@ module MethodProfiler
73
73
  :min => "Min Time",
74
74
  :max => "Max Time",
75
75
  :average => "Average Time",
76
- :total_calls => "Total Calls"
76
+ :total_time => "Total Time",
77
+ :total_calls => "Total Calls",
77
78
  },
78
- :fields => [:method, :min, :max, :average, :total_calls],
79
+ :fields => [:method, :min, :max, :average, :total_time, :total_calls],
79
80
  :filters => {
80
81
  :min => :to_milliseconds,
81
82
  :max => :to_milliseconds,
82
- :average => :to_milliseconds
83
+ :average => :to_milliseconds,
84
+ :total_time => :to_milliseconds,
83
85
  },
84
86
  :description => false
85
87
  )
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "method_profiler"
5
- s.version = "1.0.1"
5
+ s.version = "1.1.0"
6
6
  s.authors = ["Jimmy Cuadra"]
7
7
  s.email = ["jimmy@jimmycuadra.com"]
8
8
  s.homepage = "https://github.com/change/method_profiler"
@@ -11,14 +11,30 @@ describe MethodProfiler::Profiler do
11
11
  petition.should_not respond_to(:foo_with_profiling_with_profiling)
12
12
  end
13
13
 
14
- it "class methods should properly return values" do
14
+ it "returns correct values for class methods" do
15
15
  Petition.guys.should == "sup"
16
16
  end
17
17
 
18
- it "instance method should properly return values" do
18
+ it "returns correct values for instance methods" do
19
19
  petition.baz.should == "blah"
20
20
  end
21
21
 
22
+ it "yields to implicit blocks" do
23
+ petition.method_with_implicit_block {|v| v }.should == "implicit"
24
+ end
25
+
26
+ it "calls explicit blocks" do
27
+ petition.method_with_explicit_block {|v| v }.should == "explicit"
28
+ end
29
+
30
+ it "yields to implicit blocks with arguments" do
31
+ petition.method_with_implicit_block_and_args(1,2,3) {|v| v }.should == [1,2,3]
32
+ end
33
+
34
+ it "calls explicit blocks with arguments" do
35
+ petition.method_with_explicit_block_and_args(1,2,3) {|v| v }.should == [1,2,3]
36
+ end
37
+
22
38
  describe "#report" do
23
39
  it "returns a new Report object" do
24
40
  profiler.report.should be_an_instance_of MethodProfiler::Report
@@ -15,4 +15,20 @@ class Petition
15
15
  def baz
16
16
  "blah"
17
17
  end
18
+
19
+ def method_with_implicit_block
20
+ yield "implicit"
21
+ end
22
+
23
+ def method_with_explicit_block(&block)
24
+ block.call "explicit"
25
+ end
26
+
27
+ def method_with_implicit_block_and_args(*args)
28
+ yield args
29
+ end
30
+
31
+ def method_with_explicit_block_and_args(*args, &block)
32
+ block.call args
33
+ end
18
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-06 00:00:00.000000000 Z
12
+ date: 2012-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hirb
16
- requirement: &70256884010560 !ruby/object:Gem::Requirement
16
+ requirement: &70291604515080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.6.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70256884010560
24
+ version_requirements: *70291604515080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70256884010160 !ruby/object:Gem::Requirement
27
+ requirement: &70291604514680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70256884010160
35
+ version_requirements: *70291604514680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: simplecov
38
- requirement: &70256884009700 !ruby/object:Gem::Requirement
38
+ requirement: &70291604514220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70256884009700
46
+ version_requirements: *70291604514220
47
47
  description: MethodProfiler observes your code and generates reports about the methods
48
48
  that were run and how long they took.
49
49
  email:
@@ -53,6 +53,7 @@ extensions: []
53
53
  extra_rdoc_files: []
54
54
  files:
55
55
  - .gitignore
56
+ - .travis.yml
56
57
  - Gemfile
57
58
  - LICENSE
58
59
  - README.md