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 +4 -4
- data/README.md +37 -22
- data/lib/profiling/configuration.rb +1 -1
- data/lib/profiling/engine.rb +5 -7
- data/lib/profiling/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcebc905bbf17f65a9569c5c3517381ab8f976ae
|
4
|
+
data.tar.gz: 9156e9ccc5ae1f19772337cd53789d3e1bc421a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
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
|
-
|
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.
|
56
|
-
dir: '
|
57
|
-
exclude_gems: true,
|
58
|
-
exclude_standard_lib:
|
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.
|
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
|
-
##
|
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
|
-
|
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("
|
103
|
+
Profiler.run("some-label-#{Time.now.to_i}") do
|
89
104
|
# Slow code here...
|
90
105
|
end
|
91
106
|
```
|
92
107
|
|
93
|
-
|
108
|
+
### Organizing
|
94
109
|
|
95
|
-
|
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
|
|
data/lib/profiling/engine.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
class Profiler
|
2
2
|
module Engine
|
3
3
|
|
4
|
-
def run(
|
5
|
-
|
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
|
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
|
|
data/lib/profiling/version.rb
CHANGED
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.
|
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-
|
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.
|
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
|