kantox-chronoscope 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/.rubocop.yml +26 -0
- data/.rubocop_todo.yml +64 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +24 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/chronoscope.yml +9 -0
- data/kantox-chronoscope.gemspec +35 -0
- data/lib/kantox/chronoscope.rb +62 -0
- data/lib/kantox/chronoscope/dummy.rb +22 -0
- data/lib/kantox/chronoscope/generic.rb +150 -0
- data/lib/kantox/chronoscope/version.rb +5 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b2b87e9b58a4238164f0f7576b407cfa582e51ed
|
4
|
+
data.tar.gz: 65de2749827f1306b565134abf1223516d1df0eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9827da1afddfa8f6c839c41b3f54ea9937a1b9a677e0ac5c5acc64a4f2b492ba77a14112d5d7018f23e4248fc28f1f395272fa9b8b4f0f5ce788a51f5e0af652
|
7
|
+
data.tar.gz: f3c129f32a6e5111875e2cb8abd1b9e36c5f2209b67cf92711d052c6417319547cd212ebccece6ea9c1535bd4b0af9fe427075ce48cc0142643e2e8974c7ec4c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Metrics/LineLength:
|
4
|
+
Max: 180
|
5
|
+
|
6
|
+
Style/AsciiIdentifiers:
|
7
|
+
Exclude:
|
8
|
+
- 'lib/**/*'
|
9
|
+
- 'spec/**/*'
|
10
|
+
|
11
|
+
Style/AsciiComments:
|
12
|
+
Exclude:
|
13
|
+
- 'lib/**/*'
|
14
|
+
- 'spec/**/*'
|
15
|
+
|
16
|
+
Style/VariableName:
|
17
|
+
Exclude:
|
18
|
+
- 'lib/**/*'
|
19
|
+
|
20
|
+
Style/ClassVars:
|
21
|
+
Exclude:
|
22
|
+
- 'lib/**/*'
|
23
|
+
|
24
|
+
Metrics/ModuleLength:
|
25
|
+
Exclude:
|
26
|
+
- 'lib/kantox/chronoscope/generic.rb'
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-03-21 16:08:26 +0100 using RuboCop version 0.37.2.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
Lint/HandleExceptions:
|
11
|
+
Exclude:
|
12
|
+
- 'lib/kantox/chronoscope.rb'
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
# Configuration parameters: CountComments.
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Max: 12
|
18
|
+
|
19
|
+
# Offense count: 1
|
20
|
+
# Cop supports --auto-correct.
|
21
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
22
|
+
# SupportedStyles: percent_q, bare_percent
|
23
|
+
Style/BarePercentLiterals:
|
24
|
+
Exclude:
|
25
|
+
- 'lib/kantox/chronoscope.rb'
|
26
|
+
|
27
|
+
# Offense count: 2
|
28
|
+
Style/Documentation:
|
29
|
+
Exclude:
|
30
|
+
- 'spec/**/*'
|
31
|
+
- 'test/**/*'
|
32
|
+
- 'lib/kantox/chronoscope.rb'
|
33
|
+
|
34
|
+
# Offense count: 1
|
35
|
+
# Cop supports --auto-correct.
|
36
|
+
# Configuration parameters: SupportedStyles, UseHashRocketsWithSymbolValues.
|
37
|
+
# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
|
38
|
+
Style/HashSyntax:
|
39
|
+
EnforcedStyle: ruby19
|
40
|
+
|
41
|
+
# Offense count: 1
|
42
|
+
# Cop supports --auto-correct.
|
43
|
+
Style/MutableConstant:
|
44
|
+
Exclude:
|
45
|
+
- 'lib/kantox/chronoscope/version.rb'
|
46
|
+
|
47
|
+
# Offense count: 1
|
48
|
+
# Cop supports --auto-correct.
|
49
|
+
Style/RescueModifier:
|
50
|
+
Exclude:
|
51
|
+
- 'lib/kantox/chronoscope.rb'
|
52
|
+
|
53
|
+
# Offense count: 13
|
54
|
+
# Cop supports --auto-correct.
|
55
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
|
56
|
+
# SupportedStyles: single_quotes, double_quotes
|
57
|
+
Style/StringLiterals:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
# Offense count: 1
|
61
|
+
# Cop supports --auto-correct.
|
62
|
+
Style/UnneededPercentQ:
|
63
|
+
Exclude:
|
64
|
+
- 'lib/kantox/chronoscope.rb'
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Aleksei Matiushkin
|
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,38 @@
|
|
1
|
+
# Kantox::Chronoscope
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/am-kantox/kantox-chronoscope.svg?branch=master)](https://travis-ci.org/am-kantox/kantox-chronoscope)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'kantox-chronoscope'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install kantox-chronoscope
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
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.
|
28
|
+
|
29
|
+
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).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kantox-chronoscope. 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.
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'bundler/gem_tasks'
|
7
|
+
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
|
10
|
+
begin
|
11
|
+
Bundler.setup(:default, :development, :test)
|
12
|
+
rescue Bundler::BundlerError => e
|
13
|
+
$stderr.puts e.message
|
14
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
15
|
+
exit e.status_code
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Tests'
|
19
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
20
|
+
spec.rspec_opts = '-Ispec'
|
21
|
+
# spec.rcov = true
|
22
|
+
end
|
23
|
+
|
24
|
+
task :default => :spec
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "kantox/chronoscope"
|
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,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kantox/chronoscope/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'kantox-chronoscope'
|
8
|
+
spec.version = Kantox::Chronoscope::VERSION
|
9
|
+
spec.authors = ['Kantox']
|
10
|
+
spec.email = ['aleksei.matiushkin@kantox.com']
|
11
|
+
|
12
|
+
spec.summary = 'Handy profiler for rspec.'
|
13
|
+
spec.description = 'Allows to easy and quick profile method calls during rspec execution.'
|
14
|
+
spec.homepage = "https://github.com/am-kantox/#{spec.name}"
|
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
|
+
raise 'RubyGems 2.0 or newer is required.' unless spec.respond_to?(:metadata)
|
20
|
+
|
21
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
spec.bindir = 'bin'
|
25
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'rspec'
|
31
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
32
|
+
spec.add_development_dependency 'awesome_print', '~> 1'
|
33
|
+
|
34
|
+
spec.add_dependency 'kungfuig', '~> 0.3'
|
35
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'benchmark'
|
3
|
+
require 'kungfuig'
|
4
|
+
require 'hashie/mash'
|
5
|
+
|
6
|
+
require "kantox/chronoscope/version"
|
7
|
+
|
8
|
+
module Kantox
|
9
|
+
module Chronoscope
|
10
|
+
module Generic; end
|
11
|
+
module Dummy; end
|
12
|
+
|
13
|
+
DEFAULT_ENV = :development
|
14
|
+
CONFIG_LOCATION = 'config/chronoscope.yml'.freeze
|
15
|
+
|
16
|
+
include Kungfuig
|
17
|
+
config(File.join(File.expand_path('..', __FILE__), CONFIG_LOCATION)) rescue nil # FIXME: report
|
18
|
+
config(CONFIG_LOCATION) rescue nil # FIXME: report
|
19
|
+
|
20
|
+
ENV = const_defined?('Rails') && Rails.env || ENV['CHRONOSCOPE_ENV'] || DEFAULT_ENV
|
21
|
+
|
22
|
+
require "kantox/chronoscope/dummy"
|
23
|
+
require "kantox/chronoscope/generic"
|
24
|
+
general_config = option(ENV, :general) || Hashie::Mash.new
|
25
|
+
chronoscope = if general_config.enable
|
26
|
+
begin
|
27
|
+
Kernel.const_get(general_config.handler)
|
28
|
+
rescue NameError, TypeError
|
29
|
+
# FIXME: Log this error
|
30
|
+
Kantox::Chronoscope::Generic
|
31
|
+
end
|
32
|
+
else
|
33
|
+
Kantox::Chronoscope::Dummy
|
34
|
+
end
|
35
|
+
chronoscope.inject(general_config.top)
|
36
|
+
|
37
|
+
module ClassMethods
|
38
|
+
# `methods` parameter accepts:
|
39
|
+
# none for all instance methods
|
40
|
+
# :method for explicit method
|
41
|
+
def attach(klazz, *methods)
|
42
|
+
klazz = Kernel.const_get(klazz) unless klazz.is_a?(Class)
|
43
|
+
methods = klazz.instance_methods(false) if methods.empty?
|
44
|
+
|
45
|
+
methods.each do |m|
|
46
|
+
next if m.to_s =~ /\A⚑/ || methods.include?("⚑#{m}".to_sym) # skip already wrapped functions
|
47
|
+
next if klazz.instance_method(m).parameters.to_h[:block] # FIXME: report
|
48
|
+
|
49
|
+
klazz.class_eval %Q|
|
50
|
+
alias_method '⚑#{m}', '#{m}'
|
51
|
+
def #{m} *args
|
52
|
+
⌚('#{klazz}##{m}') { ⚑#{m}(*args) }
|
53
|
+
end
|
54
|
+
|
|
55
|
+
end
|
56
|
+
rescue NameError
|
57
|
+
# FIXME: report
|
58
|
+
end
|
59
|
+
end
|
60
|
+
extend ClassMethods
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Kantox
|
2
|
+
module Chronoscope
|
3
|
+
# Dummy module to be used in production-like environments.
|
4
|
+
module Dummy
|
5
|
+
# rubocop:disable Style/MethodName
|
6
|
+
# rubocop:disable Style/OpMethod
|
7
|
+
def ⌚(*args)
|
8
|
+
yield(*args) if block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
def ⌛(*args)
|
12
|
+
end
|
13
|
+
# rubocop:enable Style/OpMethod
|
14
|
+
# rubocop:enable Style/MethodName
|
15
|
+
|
16
|
+
def inject(top = nil)
|
17
|
+
(top || Object).send :prepend, Kantox::Chronoscope::Dummy
|
18
|
+
end
|
19
|
+
module_function :inject
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module Kantox
|
2
|
+
module Chronoscope
|
3
|
+
# Dummy module to be used in production-like environments.
|
4
|
+
module Generic
|
5
|
+
COLOR_VIVID = "\033[#{Kantox::Chronoscope.config.colors!.vivid || '01;38;05;226'}m".freeze
|
6
|
+
COLOR_PALE = "\033[#{Kantox::Chronoscope.config.colors!.pale || '01;38;05;178'}m".freeze
|
7
|
+
COLOR_WARN = "\033[#{Kantox::Chronoscope.config.colors!.warn || '01;38;05;173'}m".freeze
|
8
|
+
LOGGER = Kantox::Chronoscope.config.logger && Kernel.const_get(Kantox::Chronoscope.config.logger).new ||
|
9
|
+
Kernel.const_defined?(:Rails) && ::Rails.logger ||
|
10
|
+
Logger.new(STDOUT)
|
11
|
+
|
12
|
+
BM_DELIMITER = (Kantox::Chronoscope.config.i18n!.bm_delimiter || ' :: ').to_s.freeze
|
13
|
+
ARROW = (Kantox::Chronoscope.config.i18n!.arrow || ' ⇒ ').to_s.freeze
|
14
|
+
METHOD_LABEL = Kantox::Chronoscope.config.i18n!.name || 'method'.freeze
|
15
|
+
TIMES_LABEL = Kantox::Chronoscope.config.i18n!.times || 'times'.freeze
|
16
|
+
AVERAGE_LABEL = Kantox::Chronoscope.config.i18n!.average || 'average'.freeze
|
17
|
+
TOTAL_LABEL = Kantox::Chronoscope.config.i18n!.total || 'total'.freeze
|
18
|
+
|
19
|
+
COLOR_NONE = "\033[0m".freeze
|
20
|
+
DEFAULT_TAG = 'N/A'.freeze
|
21
|
+
LOGGER_TAG = 'CHRONOS'.freeze
|
22
|
+
|
23
|
+
@@chronoscope_data = {}
|
24
|
+
@@★ = []
|
25
|
+
|
26
|
+
# rubocop:disable Style/MethodName
|
27
|
+
# rubocop:disable Style/OpMethod
|
28
|
+
# rubocop:disable Metrics/MethodLength
|
29
|
+
# rubocop:disable Metrics/AbcSize
|
30
|
+
# rubocop:disable Style/SpecialGlobalVars
|
31
|
+
|
32
|
+
def ⌚(arg = DEFAULT_TAG)
|
33
|
+
return (@@chronoscope_data[arg.to_s] = nil) unless block_given? # pass no block to reset
|
34
|
+
|
35
|
+
result = nil # needed for it to be defined in this scope
|
36
|
+
@@chronoscope_data[arg.to_s] ||= { count: 0, total: 0, stack: @@★.dup }
|
37
|
+
@@★.unshift arg.to_s
|
38
|
+
begin
|
39
|
+
(Benchmark.measure { result = yield }).tap do |bm|
|
40
|
+
@@chronoscope_data[arg.to_s][:count] += 1
|
41
|
+
@@chronoscope_data[arg.to_s][:total] += bm.real
|
42
|
+
LOGGER.debug log_bm arg, bm
|
43
|
+
end
|
44
|
+
result
|
45
|
+
rescue => e
|
46
|
+
LOGGER.debug log_problem arg, e
|
47
|
+
yield # re-try without any wrappers. If it will raise anyway— fine
|
48
|
+
ensure
|
49
|
+
@@★.shift
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# FIXME: total currently adds up all calls, including nested
|
54
|
+
# I am not sure if it is correct ot not, so leaving it for now
|
55
|
+
def ⌛(cleanup: true, count: 18, log: true) # Yes, 18 is my fave number)
|
56
|
+
return if @@chronoscope_data.empty?
|
57
|
+
|
58
|
+
log_report(count).tap do |log_hash|
|
59
|
+
LOGGER.debug(log_hash[:string]) if log
|
60
|
+
puts '—' * 80
|
61
|
+
puts @@chronoscope_data.inspect
|
62
|
+
puts '—' * 80
|
63
|
+
log_hash[:data] = @@chronoscope_data.dup
|
64
|
+
@@chronoscope_data.clear if cleanup
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def log_bm(arg, bm)
|
69
|
+
[
|
70
|
+
" #{COLOR_PALE}[#{LOGGER_TAG}] #{arg}#{COLOR_NONE}",
|
71
|
+
BM_DELIMITER,
|
72
|
+
"#{COLOR_PALE}#{@@chronoscope_data[arg.to_s][:count]}#{COLOR_NONE}",
|
73
|
+
BM_DELIMITER,
|
74
|
+
"#{COLOR_VIVID}#{@@chronoscope_data[arg.to_s][:total].round(3)}#{COLOR_NONE}",
|
75
|
+
bm.to_s
|
76
|
+
].join(' ')
|
77
|
+
end
|
78
|
+
|
79
|
+
def log_problem(arg, e)
|
80
|
+
[
|
81
|
+
" #{COLOR_WARN}[#{LOGGER_TAG}] #{arg}#{COLOR_NONE} #{BM_DELIMITER} threw “#{COLOR_WARN}#{e.message}#{COLOR_NONE}”",
|
82
|
+
e.backtrace.map { |s| "#{COLOR_WARN}#{s}#{COLOR_NONE}" }
|
83
|
+
].join("#{$/}⮩\t")
|
84
|
+
end
|
85
|
+
|
86
|
+
def log_report(count)
|
87
|
+
count = @@chronoscope_data.size if count <= 0
|
88
|
+
|
89
|
+
delim_label = [" ⇓⇓ [#{LOGGER_TAG}] ⇓⇓ ", " ⇑⇑ [#{LOGGER_TAG}] ⇑⇑ "].map do |label|
|
90
|
+
delim = '—' * ((log_width - label.length) / 2)
|
91
|
+
"#{COLOR_PALE}#{delim}#{label}#{delim}#{COLOR_NONE}"
|
92
|
+
end
|
93
|
+
|
94
|
+
method_len = [@@chronoscope_data.keys.max_by(&:length).length, 5].max + 2
|
95
|
+
times_len = [TIMES_LABEL.length, 6].max
|
96
|
+
average_len = [AVERAGE_LABEL.length, 8].max
|
97
|
+
total = @@chronoscope_data.values.map { |v| v[:total] }.inject(:+).round(5)
|
98
|
+
|
99
|
+
as_string = [
|
100
|
+
'',
|
101
|
+
delim_label.first,
|
102
|
+
[
|
103
|
+
METHOD_LABEL.rjust(method_len, ' '),
|
104
|
+
ARROW,
|
105
|
+
TIMES_LABEL.rjust(times_len, ' '),
|
106
|
+
BM_DELIMITER,
|
107
|
+
AVERAGE_LABEL.ljust(average_len, ' '),
|
108
|
+
BM_DELIMITER,
|
109
|
+
TOTAL_LABEL
|
110
|
+
].join,
|
111
|
+
(@@chronoscope_data.sort_by { |_, v| -v[:total] }.take(count).map do |what, bms|
|
112
|
+
[
|
113
|
+
"#{COLOR_PALE}#{what.rjust(method_len, ' ')}#{COLOR_NONE}",
|
114
|
+
ARROW,
|
115
|
+
"#{COLOR_VIVID}#{bms[:count].to_s.rjust(times_len, ' ')}#{COLOR_NONE}",
|
116
|
+
BM_DELIMITER,
|
117
|
+
"#{COLOR_VIVID}#{(bms[:total] / bms[:count]).round(5).to_s.ljust(average_len, ' ')}#{COLOR_NONE}",
|
118
|
+
BM_DELIMITER,
|
119
|
+
"#{COLOR_VIVID}#{bms[:total].round(5)}#{COLOR_NONE}"
|
120
|
+
].join
|
121
|
+
end),
|
122
|
+
"#{COLOR_PALE}#{'—' * log_width}#{COLOR_NONE}",
|
123
|
+
"#{COLOR_VIVID}#{'total'.rjust(method_len, ' ')}#{COLOR_NONE}#{ARROW}#{' ' * TIMES_LABEL.length}#{COLOR_VIVID}#{total}#{COLOR_NONE}",
|
124
|
+
delim_label.last
|
125
|
+
].flatten.join($/)
|
126
|
+
|
127
|
+
{ data: @@chronoscope_data, string: as_string }
|
128
|
+
end
|
129
|
+
|
130
|
+
def log_width
|
131
|
+
# rubocop:disable Style/RescueModifier
|
132
|
+
$stdin.winsize.last - 10 rescue 80
|
133
|
+
# rubocop:enable Style/RescueModifier
|
134
|
+
end
|
135
|
+
|
136
|
+
protected :log_problem, :log_bm, :log_report, :log_width
|
137
|
+
# rubocop:enable Style/SpecialGlobalVars
|
138
|
+
# rubocop:enable Metrics/AbcSize
|
139
|
+
# rubocop:enable Metrics/MethodLength
|
140
|
+
# rubocop:enable Style/OpMethod
|
141
|
+
# rubocop:enable Style/MethodName
|
142
|
+
|
143
|
+
def inject(top = nil)
|
144
|
+
top ||= Object
|
145
|
+
top.send :prepend, Kantox::Chronoscope::Generic
|
146
|
+
end
|
147
|
+
module_function :inject
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kantox-chronoscope
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kantox
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-22 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: rspec
|
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
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: awesome_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: kungfuig
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.3'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.3'
|
97
|
+
description: Allows to easy and quick profile method calls during rspec execution.
|
98
|
+
email:
|
99
|
+
- aleksei.matiushkin@kantox.com
|
100
|
+
executables:
|
101
|
+
- console
|
102
|
+
- setup
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- ".rubocop.yml"
|
109
|
+
- ".rubocop_todo.yml"
|
110
|
+
- ".travis.yml"
|
111
|
+
- CODE_OF_CONDUCT.md
|
112
|
+
- Gemfile
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- bin/console
|
117
|
+
- bin/setup
|
118
|
+
- config/chronoscope.yml
|
119
|
+
- kantox-chronoscope.gemspec
|
120
|
+
- lib/kantox/chronoscope.rb
|
121
|
+
- lib/kantox/chronoscope/dummy.rb
|
122
|
+
- lib/kantox/chronoscope/generic.rb
|
123
|
+
- lib/kantox/chronoscope/version.rb
|
124
|
+
homepage: https://github.com/am-kantox/kantox-chronoscope
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.4.8
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Handy profiler for rspec.
|
148
|
+
test_files: []
|