profiling 1.2.0 → 2.0.1

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: f20b2a353b190c5e2dd6dcdc5c9bd790ff1cb6b7
4
- data.tar.gz: 947bd73fe763e35f8f90c57f164f6716e0bb2a8d
3
+ metadata.gz: 93ace3273f3436ce25c317fbad89c277548c9af4
4
+ data.tar.gz: 37ecc2ab961d454be1a4461af1728a815f830ea0
5
5
  SHA512:
6
- metadata.gz: 1c687fe988cf9fc2a79a365e705aaaa7580fef6d1e4e8a7ef80f86b8659dc1f865dae48cae69522861406de6dee2ad5148cf2cb3e108340151c9594f3ec5617a
7
- data.tar.gz: 36f8235155340ed56731adaff17fc70ee415c4a91c6b1bd76f52f8c1cb5d44a5d0ec233a0a5e6d4bed4cc76a7561bc1096e0727291e71d02803abdb67ee0c7b2
6
+ metadata.gz: 9b820255232fea158d0d25184ae3597a4a73b664ce2df1a0b8bd520d5b28197c04134bd8a8d5eee0a8f6fe21b546a2c96821daf3e4f7e7ef0446865f49c7eab4
7
+ data.tar.gz: 7c5f38ac38441ff62a5f03a27d64cd04c662b67b00b98ba6928c8d52e8fe2ed56a3bba744da7b5d806dda475356a74e1c377ffcd41436d305701bb02809155dd
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', "~> 1.1"
15
+ gem 'profiling', "~> 1.2"
16
16
  ```
17
17
 
18
18
  And then execute:
@@ -51,15 +51,15 @@ The next time you call the code it will be profiled and three files will be writ
51
51
 
52
52
  ## Configuration
53
53
 
54
- Change the directory the files will be generated in:
55
-
56
54
  ```ruby
57
55
  Profiler.config = {
58
- dir: '/tmp/my-dir'
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
59
  }
60
60
  ```
61
61
 
62
- ### Rails Initializer
62
+ ## Rails Initializer
63
63
 
64
64
  This initializer is recommended if you're planning to profile in Rails:
65
65
 
@@ -72,7 +72,7 @@ Profiler.config = {
72
72
 
73
73
  ## Conditional Profiling
74
74
 
75
- Pass an argument `if:` to enable or disable profiling:
75
+ Pass an argument `if:` to enable or disable profiling at run time:
76
76
 
77
77
  ```ruby
78
78
  Profiler.run(if: user.is_admin?) do
@@ -82,7 +82,7 @@ end
82
82
 
83
83
  ## Preserving artefacts
84
84
 
85
- Every time code is profiled the previous files will be overwritten unless the label's dynamic. To keep old files, you could add the current time in the label so new files are generated with each run:
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:
86
86
 
87
87
  ```ruby
88
88
  Profiler.run("my-label-#{Time.now.to_i}") do
@@ -90,9 +90,9 @@ Profiler.run("my-label-#{Time.now.to_i}") do
90
90
  end
91
91
  ```
92
92
 
93
- ### Organizing artefacts
93
+ ## Organizing artefacts
94
94
 
95
- Labels translate to directories, so use `/` in your labels to group profiling together logically:
95
+ Labels translate to directories, so use `/` in your labels to group artefacts together:
96
96
 
97
97
  ```ruby
98
98
  Profiler.run("post/create") do
@@ -2,7 +2,9 @@ class Profiler
2
2
  module Configuration
3
3
 
4
4
  DEFAULT_CONFIG = {
5
- dir: 'profiling'
5
+ dir: 'profiling',
6
+ exclude_gems: true,
7
+ exclude_standard_lib: false
6
8
  }
7
9
 
8
10
  attr_accessor :config
@@ -11,16 +11,41 @@ class Profiler
11
11
 
12
12
  require 'ruby-prof'
13
13
 
14
- RubyProf.start
14
+ profile = RubyProf::Profile.new
15
+
16
+ profile.exclude_methods!(::Profiler::Engine, :run)
17
+ profile.exclude_common_methods! if config[:exclude_standard_lib]
18
+ # Note, we optionally exclude ruby gems after collecting the profile results
19
+ # instead of here as we can't exclude by a path any other way.
20
+
21
+ profile.start
15
22
 
16
23
  begin
17
24
  yield
18
25
  rescue => e
19
- RubyProf.stop
26
+ profile.stop
20
27
  raise e
21
28
  end
22
29
 
23
- @results = RubyProf.stop
30
+ @results = profile.stop
31
+
32
+ # Remove certain things from the profiling
33
+ unless @results.threads.empty?
34
+ exclude_paths = []
35
+
36
+ if config[:exclude_gems]
37
+ exclude_paths << /\/gems\//
38
+ end
39
+
40
+ unless exclude_paths.empty?
41
+ @results.threads.first.methods.each do |method|
42
+ if exclude_paths.any?{|regex| method.source_file.match(regex) }
43
+ method.eliminate!
44
+ end
45
+ end
46
+ end
47
+ end
48
+
24
49
  out()
25
50
  end
26
51
 
@@ -1,3 +1,3 @@
1
1
  class Profiler
2
- VERSION = "1.2.0"
2
+ VERSION = "2.0.1"
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: 1.2.0
4
+ version: 2.0.1
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-19 00:00:00.000000000 Z
11
+ date: 2018-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.15'
103
+ version: '0.17'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.15'
110
+ version: '0.17'
111
111
  description: 'Non-discriminatory Ruby code profiling: This gem is a small wrapper
112
112
  around the ruby-prof gem to do simple but powerful profiling'
113
113
  email: