perforat 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/perforat.rb +22 -0
- data/lib/perforat/listener.rb +42 -0
- data/lib/perforat/results_processor.rb +61 -0
- data/lib/perforat/version.rb +3 -0
- data/perforat.gemspec +35 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7ca44e3dad104ec39a6f02dd5c01f95bc4ed59e
|
4
|
+
data.tar.gz: c88ca6a54437a9f3c5b3e4b034bf77bdfcc38d2d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 388aea2f62f7e8dc1f08b29d2841eb18876dd2d201c43981a7824e5420bd4c8ca14fec8e04d4ff6d04e6ee4ed589e64e7d2f243114f7feecfcf33b5c7e3daf2f
|
7
|
+
data.tar.gz: da02e8d5c12a38496b869fca4310ba19d92a2f47ce5c02fb172e9ab7f2247ba55fbb8a4ee2ff011d7c6a058a254dd0a52a6454af44a07245c212eac48004a168
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ignat Zakrevsky
|
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,56 @@
|
|
1
|
+
# Perforat
|
2
|
+
|
3
|
+
**Perforat** monitors your tests and notice in case some of them significant slowed down.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'perforat'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install perforat
|
20
|
+
|
21
|
+
Then you need to require it on your `rails_helper` or `spec_helper`
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'perforat'
|
25
|
+
```
|
26
|
+
As each test running takes different time to run there are some settings to tune it:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
:results_count, default: 20 # how much notification can be displayed
|
30
|
+
:minimal_duration, default: 0.1 # in case of your tests are really fast they produce really huge coefficients event without any changes, minimal_duration` uses to minimal false positive activation.
|
31
|
+
:minimal_epsilon, default: 0.1 # in case of test takes acceptable time it can be not so slowed down to notify about it
|
32
|
+
:keep_files, default: 2 # **Perforat** need only last two files to see difference between tests duration, so if you need more -- you always can change this setting
|
33
|
+
```
|
34
|
+
|
35
|
+
To configure it add you need to pass params to RSpec settings
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
RSpec.configure do |config|
|
39
|
+
config.perforat = { keep_files: 5 }
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
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.
|
46
|
+
|
47
|
+
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).
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ignat-zakrevsky/perforat.
|
52
|
+
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'perforat'
|
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
data/lib/perforat.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'perforat/version'
|
2
|
+
require 'perforat/listener'
|
3
|
+
|
4
|
+
module Perforat
|
5
|
+
PERFORAT_DIR = 'tmp/perforat'.freeze
|
6
|
+
DEFAULT_SETTINGS = {
|
7
|
+
results_count: 20,
|
8
|
+
minimal_duration: 0.1,
|
9
|
+
minimal_epsilon: 0.1,
|
10
|
+
keep_files: 2
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def self.settings
|
14
|
+
DEFAULT_SETTINGS.merge(RSpec.configuration.perforat)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.reporter.register_listener Perforat::Listener.new,
|
20
|
+
:start, :example_passed, :example_failed, :stop
|
21
|
+
config.add_setting :perforat, default: Perforat::DEFAULT_SETTINGS
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'csv'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
require 'perforat/results_processor'
|
6
|
+
|
7
|
+
module Perforat
|
8
|
+
class Listener
|
9
|
+
def start(_)
|
10
|
+
current_time = Time.now.to_i
|
11
|
+
FileUtils.mkdir_p(PERFORAT_DIR)
|
12
|
+
@output = CSV.open("#{PERFORAT_DIR}/#{current_time}.csv", 'w')
|
13
|
+
@output << [current_time]
|
14
|
+
end
|
15
|
+
|
16
|
+
def example_finished(notification)
|
17
|
+
@output << [
|
18
|
+
notification.example.full_description,
|
19
|
+
notification.example.execution_result.run_time
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def stop(_)
|
24
|
+
@output.close
|
25
|
+
puts
|
26
|
+
files = Dir["#{PERFORAT_DIR}/*.csv"].sort_by(&File.method(:mtime))
|
27
|
+
remove_old_files(files)
|
28
|
+
contents = files.last(2).map { |file| CSV.read(file) }
|
29
|
+
ResultsProcessor.new(contents: contents).call
|
30
|
+
end
|
31
|
+
|
32
|
+
alias :example_passed :example_finished
|
33
|
+
alias :example_failed :example_finished
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def remove_old_files(files)
|
38
|
+
keep_files = Perforat.settings.fetch(:keep_files)
|
39
|
+
(files - files.last(keep_files)).each(&File.method(:delete))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Perforat
|
2
|
+
class ResultsProcessor
|
3
|
+
def initialize(contents:, formatter: default_formatter, settings: Perforat.settings)
|
4
|
+
@formatter = formatter
|
5
|
+
@contents = contents
|
6
|
+
@settings = settings
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
results = @contents.map(&parse_info).inject(&:merge)
|
11
|
+
|
12
|
+
results.values.map(&:keys).inject(&:&).map do |test_name|
|
13
|
+
durations = results.map(&tests_by(test_name)).reverse
|
14
|
+
[test_name, durations, durations.inject(&:/)]
|
15
|
+
end
|
16
|
+
.sort_by(&by_coefficient_increasing)
|
17
|
+
.last(settings.fetch(:results_count))
|
18
|
+
.reject(&by_low_results)
|
19
|
+
.each(&formatter)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def parse_info
|
25
|
+
lambda do |info|
|
26
|
+
{ parse_timestamp(info.shift.first) => info.map(&present_test_info).inject(&:merge) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def present_test_info
|
31
|
+
-> (test, time) { { test => time.to_f } }
|
32
|
+
end
|
33
|
+
|
34
|
+
def tests_by(test_name)
|
35
|
+
-> (_, tests) { tests.fetch(test_name) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def by_coefficient_increasing
|
39
|
+
-> (_, _, coefficient) { coefficient }
|
40
|
+
end
|
41
|
+
|
42
|
+
def by_low_results
|
43
|
+
lambda do |_, durations, coefficient|
|
44
|
+
durations.all? { |duration| duration < settings.fetch(:minimal_duration) } ||
|
45
|
+
coefficient - 1 < settings.fetch(:minimal_epsilon)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_timestamp(timestamp)
|
50
|
+
Time.at(timestamp.to_i).to_datetime
|
51
|
+
end
|
52
|
+
|
53
|
+
def default_formatter
|
54
|
+
lambda do |(test_name, durations, coefficient)|
|
55
|
+
puts "#{test_name}: #{durations[1]} -> #{durations[0]} coefficient: #{coefficient}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
attr_reader :formatter, :settings
|
60
|
+
end
|
61
|
+
end
|
data/perforat.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'perforat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'perforat'
|
8
|
+
spec.version = Perforat::VERSION
|
9
|
+
spec.authors = ['Ignat Zakrevsky']
|
10
|
+
spec.email = ['iezakrevsky@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Check your tests for performance decrease.'
|
13
|
+
spec.description = 'Check your tests for performance decrease and notify about it.'
|
14
|
+
spec.homepage = 'https://github.com/ignat-zakrevsky/perforat'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
33
|
+
spec.add_development_dependency 'pry'
|
34
|
+
spec.add_development_dependency 'rubocop'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: perforat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ignat Zakrevsky
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-29 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: pry
|
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: rubocop
|
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
|
+
description: Check your tests for performance decrease and notify about it.
|
84
|
+
email:
|
85
|
+
- iezakrevsky@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/perforat.rb
|
100
|
+
- lib/perforat/listener.rb
|
101
|
+
- lib/perforat/results_processor.rb
|
102
|
+
- lib/perforat/version.rb
|
103
|
+
- perforat.gemspec
|
104
|
+
homepage: https://github.com/ignat-zakrevsky/perforat
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata:
|
108
|
+
allowed_push_host: https://rubygems.org
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.5
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Check your tests for performance decrease.
|
129
|
+
test_files: []
|