profiling 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0cfec5331ddecfe74e80d46d6f222741538e5874
4
- data.tar.gz: 460a9384930e56eaa3f6d513a1b7ab650bb0f008
3
+ metadata.gz: dcebc905bbf17f65a9569c5c3517381ab8f976ae
4
+ data.tar.gz: 9156e9ccc5ae1f19772337cd53789d3e1bc421a3
5
5
  SHA512:
6
- metadata.gz: ad10718ef797fef7522e6b8de5c8931e4bfdbbaaee48f79d74f679abe8d8fcd20fa926457ca9626dab7e0b4894855891b3ee61fea2497c84363588efc2260eda
7
- data.tar.gz: ebe9c9f9d0b302f27c07a0b9cf9659f88f8e529901abdbf9f8f9a1a4fc0f940c2c82cb3ec032a36df9aceca6e1eecf71aaf6fbcbd308368c443957ba27bc7aca
6
+ metadata.gz: ce32170eb1c1776886d720bf7a0495c393bb7ab7bdc597a233d7c19f804294773acf9dcb5fb6ebecbc0645a99c3e03520a0a26a39615ff4595e17652dd5a8e5f
7
+ data.tar.gz: 1162eff56e9deaca226d8be89144d24e136426e44c1fe11135bbb0a15060f0a750a92fab53fbbef11ef99eafbabb6ce22d2504c4f2dfc5b639009e59444ca56a
data/README.md CHANGED
@@ -12,7 +12,7 @@ Non-discriminatory profiling for your MRI Ruby code. This gem is a small wrapper
12
12
  Add this line to your application's Gemfile:
13
13
 
14
14
  ```ruby
15
- gem 'profiling', "~> 2.1"
15
+ gem 'profiling', "~> 2.2"
16
16
  ```
17
17
 
18
18
  And then execute:
@@ -31,15 +31,9 @@ Profile slow code from your friend or colleague like this:
31
31
  Profiler.run do
32
32
  # Slow code here...
33
33
  end
34
-
35
- # or
36
-
37
- Profiler.run("some-label") do
38
- # Slow code here...
39
- end
40
34
  ```
41
35
 
42
- The next time you call the code it will be profiled and three files will be written into a directory `profiling`, and in the second example `profiling/some-label`.
36
+ The next time you call the code it will be profiled and three files will be written into a directory called `profiling`.
43
37
 
44
38
  ### Files Generated
45
39
 
@@ -49,25 +43,36 @@ The next time you call the code it will be profiled and three files will be writ
49
43
  | `stack.html` | See the profiled code as a nested stack |
50
44
  | `flat.txt` | List of all functions called, the time spent in each and the number of calls made to that function |
51
45
 
52
- ## Configuration
46
+ ### Is it Fast?
47
+
48
+ No, no it's not. It's really slow. For especially gnarly, deeply nested code you will want to get up and get a coffee. This gem wraps [ruby-prof](https://github.com/ruby-prof/ruby-prof) which is partly written in C, so it's as fast as it can be.
49
+ ## Options
50
+
51
+ Use the `configure` method to set some options:
53
52
 
54
53
  ```ruby
55
- Profiler.config = {
56
- dir: 'profiling', # Directory the files will be created in (default is 'profiling')
57
- exclude_gems: true, # Exclude ruby gems from the results (default is true)
58
- exclude_standard_lib: false # Exclude ruby standard library from results (default is false)
59
- }
54
+ Profiler.configure({
55
+ dir: '/tmp/my-dir',
56
+ exclude_gems: true,
57
+ exclude_standard_lib: true
58
+ })
60
59
  ```
61
60
 
61
+ | Option | Description | Default |
62
+ | ------ | --------|------------ |
63
+ | `dir` | Directory the files will be created in (can be relative or absolute) | `"profiling"` |
64
+ | `exclude_gems` | Exclude ruby gems from the results | `false` |
65
+ | `exclude_standard_lib` | Exclude ruby standard library from results | `false` |
66
+
62
67
  ## Rails Initializer
63
68
 
64
69
  This initializer is recommended if you're planning to profile in Rails:
65
70
 
66
71
  ```ruby
67
72
  # config/initializer/profiling.rb
68
- Profiler.config = {
73
+ Profiler.configure({
69
74
  dir: Rails.root.join('tmp/profiling')
70
- }
75
+ })
71
76
  ```
72
77
 
73
78
  ## Conditional Profiling
@@ -80,19 +85,29 @@ Profiler.run(if: user.is_admin?) do
80
85
  end
81
86
  ```
82
87
 
83
- ## Preserving artefacts
88
+ ## Labels
89
+
90
+ Labels translate to sub directories that the files will be generated in. This is handy for profiling multiple things at once, preserving files between runs, or grouping profiling results logically.
91
+
92
+ ```ruby
93
+ Profiler.run("some-label") do
94
+ # Slow code here...
95
+ end
96
+ ```
97
+
98
+ ### Preserving files between runs
84
99
 
85
- Every time code is profiled the previous files will be overwritten unless the label is dynamic. To keep old files, add the current time in the label so new files are generated with each run:
100
+ Keep old files by adding the current time in the label so new files are generated with each run:
86
101
 
87
102
  ```ruby
88
- Profiler.run("my-label-#{Time.now.to_i}") do
103
+ Profiler.run("some-label-#{Time.now.to_i}") do
89
104
  # Slow code here...
90
105
  end
91
106
  ```
92
107
 
93
- ## Organizing artefacts
108
+ ### Organizing
94
109
 
95
- Labels translate to directories, so use `/` in your labels to group artefacts together:
110
+ Use `/` in your labels to group profiling results together in directories:
96
111
 
97
112
  ```ruby
98
113
  Profiler.run("post/create") do
@@ -106,7 +121,7 @@ end
106
121
 
107
122
  ## Contributing
108
123
 
109
- Bug reports and pull requests are welcome.
124
+ Bug reports and pull requests are welcome. Pull requests with passing tests are even better.
110
125
 
111
126
  To run the test suite:
112
127
 
@@ -3,7 +3,7 @@ class Profiler
3
3
 
4
4
  DEFAULT_CONFIG = {
5
5
  dir: 'profiling',
6
- exclude_gems: true,
6
+ exclude_gems: false,
7
7
  exclude_standard_lib: false
8
8
  }
9
9
 
@@ -1,8 +1,10 @@
1
1
  class Profiler
2
2
  module Engine
3
3
 
4
- def run(label=nil, options={})
5
- enabled = options[:if].nil? ? true : !!options[:if]
4
+ def run(*args)
5
+ label = args.find { |a| a.is_a?(String) }
6
+ opts = args.find { |a| a.is_a?(Hash) }
7
+ enabled = opts.nil? ? true : opts[:if]
6
8
  return yield unless enabled
7
9
 
8
10
  # Create directory
@@ -32,11 +34,7 @@ class Profiler
32
34
  # Optionally remove gems from the results
33
35
  if !@results.threads.empty? && config[:exclude_gems]
34
36
  @results.threads.each do |thread|
35
- thread.methods.each do |method|
36
- if method.source_file.match(/\/gems\//)
37
- method.eliminate!
38
- end
39
- end
37
+ thread.methods.each { |m| m.eliminate! if m.source_file.match(/\/gems\//) }
40
38
  end
41
39
  end
42
40
 
@@ -1,3 +1,3 @@
1
1
  class Profiler
2
- VERSION = "2.2.0"
2
+ VERSION = "2.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: profiling
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Duncalfe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-20 00:00:00.000000000 Z
11
+ date: 2018-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  requirements: []
147
147
  rubyforge_project:
148
- rubygems_version: 2.4.5.1
148
+ rubygems_version: 2.2.2
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: 'Non-discriminatory Ruby code profiling: This gem is a small wrapper around