profiling 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1c0b6ad469919343bcbb11bdb711f0096050ad2
4
+ data.tar.gz: 5b61bf891faa8172ea003dbdd8a77d9c47409c8c
5
+ SHA512:
6
+ metadata.gz: df3dabf3d0884f20f400960d20cc3740499b67cb421bf249323c10befd11a5c519a63dd027787194c7ae127cea75490bd1657ad99ae7648f39e30a29f83c48a2
7
+ data.tar.gz: ec771cde630858097e2031f7d0bdba8b0eedf0324c874c36a131e3516c5e24b604803bc6e2a740bc97705427f48872dfacfec729baf8ad6fc98fbf7f9b172d99
data/LICENCE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Luke Duncalfe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,108 @@
1
+ ![alt ruby_silhouette](https://raw.githubusercontent.com/lukes/profiling/master/img/ruby.png)
2
+
3
+ # Profiling
4
+
5
+ Non-discriminatory profiling for your MRI Ruby code. This gem is a small wrapper around the [ruby-prof](https://github.com/ruby-prof/ruby-prof) gem, which is its only dependency. It lets you do simple but powerful profiling of your friend's bad code.
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/profiling.svg)](https://badge.fury.io/rb/profiling)
8
+ [![CircleCI](https://circleci.com/gh/lukes/profiling/tree/master.svg?style=shield)](https://circleci.com/gh/lukes/profiling/tree/master)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'profiling', "~> 1.1"
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install profiling
25
+
26
+ ## Getting Started
27
+
28
+ Profile slow code from your friend or colleague like this:
29
+
30
+ ```ruby
31
+ Profiling.run do
32
+ # Slow code here...
33
+ end
34
+
35
+ # or
36
+
37
+ Profiling.run("some-label") do
38
+ # Slow code here...
39
+ end
40
+ ```
41
+
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`:
43
+
44
+ | File | Description |
45
+ | ------------- | ------------- |
46
+ | `graph.html` | Drill down into the call tree to see where the time is spent |
47
+ | `stack.html` | See the profiled code as a nested stack |
48
+ | `flat.txt` | List of all functions called, the time spent in each and the number of calls made to that function |
49
+
50
+ ## Configuration
51
+
52
+ Change the directory the files will be generated in:
53
+
54
+ ```ruby
55
+ Profiling.config = {
56
+ dir: '/tmp/my-dir'
57
+ }
58
+ ```
59
+
60
+ ## Conditional Profiling
61
+
62
+ Pass an argument `if:` to enable or disable profiling:
63
+
64
+ ```ruby
65
+ Profiling.run(if: user.is_admin?) do
66
+ # Slow code here...
67
+ end
68
+ ```
69
+
70
+ ##
71
+ ## Preserving artefacts
72
+
73
+ 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:
74
+
75
+ ```ruby
76
+ # Files will be in `profiling/my-label-1524132842`
77
+ Profiling.run("my-label-#{Time.now.to_i}") do
78
+ # Slow code here...
79
+ end
80
+ ```
81
+
82
+ ## Organizing artefacts
83
+
84
+ Labels translate to directories, so use `/` in your labels if you want to group profiling together logically:
85
+
86
+ ```ruby
87
+ # Files will be in `profiling/post/create`
88
+ Profiling.run("post/create") do
89
+ # Slow code here...
90
+ end
91
+
92
+ # Files will be in `profiling/post/update`
93
+ Profiling.run("post/update") do
94
+ # Slow code here...
95
+ end
96
+ ```
97
+
98
+ ## Contributing
99
+
100
+ Bug reports and pull requests are welcome.
101
+
102
+ To run the test suite:
103
+
104
+ bundle exec rspec
105
+
106
+ ## License
107
+
108
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "profiling"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ class Profiling
2
+ module Configuration
3
+
4
+ DEFAULT_CONFIG = {
5
+ dir: 'profiling'
6
+ }
7
+
8
+ attr_accessor :config
9
+
10
+ def self.extended(mod)
11
+ mod.config = DEFAULT_CONFIG
12
+ end
13
+
14
+ def configure(opts)
15
+ self.config = DEFAULT_CONFIG.merge(opts)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ class Profiling
2
+ VERSION = "1.1.0"
3
+ end
data/lib/profiling.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'fileutils'
2
+ require 'ostruct'
3
+
4
+ Dir[File.dirname(__FILE__) + '/profiling/*.rb'].each { |file| require file }
5
+
6
+ class Profiling
7
+ extend Configuration
8
+
9
+ def self.run(label='', options={})
10
+ enabled = options[:if].nil? ? true : !!options[:if]
11
+
12
+ return yield unless enabled
13
+
14
+ # Create directory
15
+ subdir = File.join(config[:dir], label)
16
+ FileUtils.mkdir_p subdir unless File.exist? subdir
17
+
18
+ require 'ruby-prof'
19
+
20
+ RubyProf.start
21
+
22
+ begin
23
+ yield
24
+ rescue => e
25
+ RubyProf.stop
26
+ raise e
27
+ end
28
+
29
+ results = RubyProf.stop
30
+
31
+ File.open(File.join(subdir, "graph.html"), 'w') do |file|
32
+ RubyProf::GraphHtmlPrinter.new(results).print(file)
33
+ end
34
+
35
+ File.open(File.join(subdir, "flat.txt"), 'w') do |file|
36
+ RubyProf::FlatPrinterWithLineNumbers.new(results).print(file)
37
+ end
38
+
39
+ File.open(File.join(subdir, "stack.html"), 'w') do |file|
40
+ RubyProf::CallStackPrinter.new(results).print(file)
41
+ end
42
+ end
43
+
44
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: profiling
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luke Duncalfe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec_junit_formatter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby-prof
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.15'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.15'
111
+ description: 'Non-discriminatory Ruby code profiling: This gem is a small wrapper
112
+ around the ruby-prof gem to do simple but powerful profiling'
113
+ email:
114
+ - lduncalfe@eml.cc
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - LICENCE.txt
120
+ - README.md
121
+ - bin/console
122
+ - bin/setup
123
+ - lib/profiling.rb
124
+ - lib/profiling/configuration.rb
125
+ - lib/profiling/version.rb
126
+ homepage: https://github.com/lukes/profiling
127
+ licenses:
128
+ - MIT
129
+ metadata:
130
+ yard.run: yri
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.2.2
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: 'Non-discriminatory Ruby code profiling: This gem is a small wrapper around
151
+ the ruby-prof gem to do simple but powerful profiling'
152
+ test_files: []