rspec-stackprof 0.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: 8b1ad7123082f5318dab44316eb3f20dddc21c47
4
+ data.tar.gz: 8c6a524925d10092467ac4d5cc11c6949279ac51
5
+ SHA512:
6
+ metadata.gz: b1d615940d4a517670fcdf759818e0685be828f0652ff54752201770d3eb1fe292ec47674b456cde3676cf770886bc378734c6f98d0bbcb77d13f557034a9fb7
7
+ data.tar.gz: 017a37426f787d66e5f5a76391de2c6f43fa55b3aacf2e7b95746648b900a31b78f550988b4756d8d75f2684cc14a9363aafa6f9cb774de73c1fa0c13f55ef3b
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /tags
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-stackprof.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Devinder Khroad
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,128 @@
1
+ # RSpec::StackProf
2
+
3
+ Provides a convenient way to profile your specs using [stackprof](https://github.com/tmm1/stackprof) gem by
4
+ integrating stackprof gem with your RSpec setup.
5
+
6
+ Specs can be profiled at suite level or indvidually.
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'rspec-stackprof'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install rspec-stackprof
24
+
25
+ ## Usage
26
+
27
+ Profiling can be enabled by setting environment variable `RSPEC_STACKPROF` while running `rspec` command.
28
+ 1. To profile the whole test suite, set `RSPEC_STACKPROF` variable to `all` while running the command to
29
+ invoke `rspec`.
30
+
31
+ Example:
32
+
33
+ ```
34
+ RSPEC_STACKPROF=all rspec ...
35
+ ```
36
+
37
+ profiled output is stored in `./tmp/stackprof_<pid>_<timestamp>.out`.
38
+
39
+ 2. To profile each test individually, set `RSPEC_STACKPROF` environment variable to `each`
40
+
41
+ Example:
42
+
43
+ ```
44
+ RSPEC_STACKPROF=each rspec ..
45
+ ```
46
+ profiled output is stored individually for each rspec example. A unique filename is constructed
47
+ by examining spec metadata. A sub directory is created for each 'describe' and 'context' block
48
+
49
+ For example, given a spec like:
50
+
51
+ ```
52
+ describe "main context" do
53
+ ..
54
+ context "primary context" do
55
+ ..
56
+ it "does something" do
57
+ end
58
+ end
59
+ end
60
+ ```
61
+ The profiled data will be stored at the following path:
62
+ ```
63
+ ./tmp/main_context/primary_context/does_something.<pid>.<timestamp>.out
64
+ ```
65
+
66
+ ### Configuration
67
+
68
+ You can configure following parameters for this gem.
69
+
70
+ * out_dir
71
+
72
+ directory location where profile data will be stored. When using `RSPEC_STACKPROF=each` option,
73
+ subdirectories will be created under this dir
74
+
75
+ * out_file
76
+
77
+ filename where profile results is stored when using `RSPEC_STACKPROF=all` option.
78
+
79
+
80
+ In addition, you can configure all Stackprof parameters (`mode`, `interval`, 'agregate`, `raw`) as well.
81
+
82
+ Add a file `spec/support/rspec_stackprof.rb` and add/change configuration parameters. For example:
83
+
84
+ ```
85
+ RSpec::StackProf.configure do |config|
86
+ config.out_dir = '/tmp/profiles'
87
+ config.mode = :wall
88
+ config.interval = 500
89
+ end
90
+ ```
91
+ See [stackprof](https://github.com/tmm1/stackprof) readme to learn about stackprof usage.
92
+
93
+ ### Generating Flamegraphs
94
+
95
+ Set the option `raw` to true
96
+
97
+ ```
98
+ RSpec::StackProf.configure do |config|
99
+ config.raw = true
100
+ end
101
+ ```
102
+
103
+ After profiling, run the following stackprof commands:
104
+
105
+ ```
106
+ stackprof --stackcollapse tmp/stackprof.out > tmp/stackprof_collapsed.out
107
+ stackprof-flamegraph.pl tmp/stackprof_collapsed.out > tmp/stackprof_collapsed.svg
108
+ ```
109
+
110
+ Open the svg file in a browser to view the visual representation of your profiled data.
111
+ Flamegraphs are extremely useful. If you are unfamiliar with flamegraphs, checkout [Brendan Gregg's site](http://www.brendangregg.com/flamegraphs.html) to learn more about flamegraphs
112
+
113
+
114
+ ## Development
115
+
116
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
117
+
118
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
119
+
120
+ ## Contributing
121
+
122
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec-stackprof. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
123
+
124
+
125
+ ## License
126
+
127
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
128
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec/stackprof"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ require "rspec/stackprof/version"
2
+ require 'ostruct'
3
+ require 'fileutils'
4
+ require 'stackprof'
5
+ require 'rspec/stackprof/filename_helpers'
6
+ require 'rspec/stackprof/rspec.rb'
7
+
8
+ module RSpec
9
+ class StackProf
10
+ extend FilenameHelpers
11
+
12
+ class << self
13
+ attr_accessor :configuration
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= ::OpenStruct.new(
18
+ out_dir: 'tmp',
19
+ out_file: 'stackprof.out',
20
+ )
21
+ end
22
+
23
+ def self.configure
24
+ yield(configuration)
25
+ end
26
+
27
+ def self.reset
28
+ @configuration = nil
29
+ end
30
+
31
+ def self.options
32
+ create_missing_dirs
33
+ file=create_unique_file_name
34
+ dirname = File.dirname(File.join(output_dir,output_file))
35
+ {out: File.join(dirname,file)}.merge(configuration.to_h)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,61 @@
1
+ module RSpec
2
+ class StackProf
3
+ module FilenameHelpers
4
+
5
+ def output_dir
6
+ RSpec::StackProf.configuration.out_dir
7
+ end
8
+
9
+ def output_file
10
+ RSpec::StackProf.configuration.out_file
11
+ end
12
+
13
+ def file_extension
14
+ ext = File.extname(RSpec::StackProf.configuration.out_file)
15
+ return ".out" if ext.length == 0
16
+ return ext
17
+ end
18
+
19
+ def file_basename
20
+ File.basename(RSpec::StackProf.configuration.out_file,".*")
21
+ end
22
+
23
+ def file_dirname
24
+ File.dirname(RSpec::StackProf.configuration.out_file)
25
+ end
26
+
27
+ def path_for metadata
28
+ if metadata[:parent_example_group]
29
+ File.join(path_for(metadata[:parent_example_group]), metadata[:description])
30
+ else
31
+ metadata[:description]
32
+ end
33
+ end
34
+
35
+ def uniqueness
36
+ "#{Process.pid}_#{Time.now.to_i}"
37
+ end
38
+
39
+ def create_missing_dirs
40
+ dirname = File.dirname(File.join(output_dir,output_file))
41
+ FileUtils.mkdir_p(dirname)
42
+ end
43
+
44
+ def create_unique_file_name
45
+ "#{file_basename}_#{uniqueness}#{file_extension}"
46
+ end
47
+
48
+ def filename_for example
49
+ require 'pry'
50
+ raise "No example specified" if example.nil?
51
+ path = path_for(example.metadata[:example_group])
52
+ line_number = example.metadata[:line_number].to_s
53
+ description = example.metadata[:description]
54
+ File.join(
55
+ path,
56
+ description
57
+ ).gsub(/\s+/, '_') + ":" + line_number
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,28 @@
1
+ RSpec.configure do |config|
2
+
3
+ config.before(:suite) do
4
+ unless ['all', 'each', ''].include?(ENV['RSPEC_STACKPROF'].to_s)
5
+ raise "ENV['RSPEC_STACKPROF'] should be blank, 'all' or 'each', but was '#{ENV['RSPEC_STACKPROF']}'"
6
+ end
7
+
8
+ if ENV['RSPEC_STACKPROF'] == 'all'
9
+ StackProf.start RSpec::StackProf.options
10
+ end
11
+ end
12
+
13
+ config.after(:suite) do
14
+ if ENV['RSPEC_STACKPROF'] == 'all'
15
+ StackProf.stop
16
+ StackProf.results
17
+ end
18
+ end
19
+
20
+ config.around(:each) do |example|
21
+ if ENV['RSPEC_STACKPROF'] == 'each'
22
+ RSpec::StackProf.configuration.out_file = RSpec::StackProf::filename_for(example)
23
+ StackProf.run(RSpec::StackProf.options) { example.call }
24
+ else
25
+ example.call
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ module RSpec
2
+ class StackProf
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
6
+
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/stackprof/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-stackprof"
8
+ spec.version = RSpec::StackProf::VERSION
9
+ spec.authors = ["Devinder Khroad"]
10
+ spec.email = ["dkhroad@gmail.com"]
11
+
12
+ spec.summary = %q{Profile your RSpec examples using stackprof gem}
13
+ spec.description = %q{Add profiling hooks to use stackprof gem in a RSpec suit}
14
+ spec.homepage = "https://github.com/dkhroad/rspec-stackprof"
15
+ spec.license = "MIT"
16
+
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry-byebug"
26
+ spec.add_development_dependency "pry-doc"
27
+ spec.add_development_dependency "pry-stack_explorer"
28
+ spec.add_runtime_dependency 'rspec', '~> 3.0'
29
+ spec.add_runtime_dependency 'stackprof'
30
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-stackprof
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Devinder Khroad
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-01 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-doc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-stack_explorer
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: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: stackprof
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Add profiling hooks to use stackprof gem in a RSpec suit
112
+ email:
113
+ - dkhroad@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/rspec/stackprof.rb
129
+ - lib/rspec/stackprof/filename_helpers.rb
130
+ - lib/rspec/stackprof/rspec.rb
131
+ - lib/rspec/stackprof/version.rb
132
+ - rspec-stackprof.gemspec
133
+ homepage: https://github.com/dkhroad/rspec-stackprof
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.4.6
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Profile your RSpec examples using stackprof gem
157
+ test_files: []
158
+ has_rdoc: