kantox-chronoscope 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/lib/kantox/chronoscope.rb +11 -5
- data/lib/kantox/chronoscope/generic.rb +8 -11
- data/lib/kantox/chronoscope/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4d53501fb7342dcf28242a948af1251633b0383
|
4
|
+
data.tar.gz: a2da48b18c3ad4ca31c7e82d2672bb1d93d631c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09cec413684352711afc0f92055bc45a56c97d8224e2649d4235c538e0964e1eff9828d3fc55cafec069288072060c4e00c7c3e15747f1e614f31fee0121b27a
|
7
|
+
data.tar.gz: 4b5dc5de71c87957b684954e58dc5c0bcab5826034c2692c597317417fa20b074a536a2b0bfbbe741af6e3b49faf900cc6f36cffc62f2449824de20bb37417aa
|
data/.rubocop.yml
CHANGED
data/lib/kantox/chronoscope.rb
CHANGED
@@ -10,7 +10,7 @@ module Kantox
|
|
10
10
|
module Generic; end
|
11
11
|
module Dummy; end
|
12
12
|
|
13
|
-
CHAIN_PREFIX = '⚑'
|
13
|
+
CHAIN_PREFIX = '⚑'.freeze
|
14
14
|
|
15
15
|
DEFAULT_ENV = :development
|
16
16
|
CONFIG_LOCATION = 'config/chronoscope.yml'.freeze
|
@@ -24,6 +24,7 @@ module Kantox
|
|
24
24
|
require "kantox/chronoscope/dummy"
|
25
25
|
require "kantox/chronoscope/generic"
|
26
26
|
general_config = option(ENV, :general) || Hashie::Mash.new
|
27
|
+
|
27
28
|
chronoscope = if general_config.enable
|
28
29
|
begin
|
29
30
|
Kernel.const_get(general_config.handler)
|
@@ -41,6 +42,7 @@ module Kantox
|
|
41
42
|
# rubocop:disable Metrics/AbcSize
|
42
43
|
# rubocop:disable Metrics/MethodLength
|
43
44
|
module ClassMethods
|
45
|
+
# TODO: Permit monitoring of private methods
|
44
46
|
# `methods` parameter accepts:
|
45
47
|
# none for all instance methods
|
46
48
|
# :method for explicit method
|
@@ -50,19 +52,23 @@ module Kantox
|
|
50
52
|
|
51
53
|
methods.each do |m|
|
52
54
|
next if m.to_s =~ /\A#{CHAIN_PREFIX}/ # skip wrappers
|
53
|
-
next if m.to_s.end_with?('=') # skip attr_writers # FIXME: WTF?????
|
54
55
|
next if methods.include?("#{CHAIN_PREFIX}#{m}".to_sym) # skip already wrapped functions
|
55
56
|
next if (klazz.instance_method(m).parameters.to_h[:block] rescue false) # FIXME: report
|
56
57
|
|
58
|
+
receiver, arg_string = m.to_s.end_with?('=') ? ['self.', 'arg'] : [nil, '*args'] # to satisfy setter
|
59
|
+
|
57
60
|
klazz.class_eval %Q|
|
58
61
|
alias_method :'#{CHAIN_PREFIX}#{m}', :'#{m}'
|
59
|
-
def #{m}(
|
60
|
-
⌚('#{klazz}##{m}') { #{CHAIN_PREFIX}#{m}
|
62
|
+
def #{m}(#{arg_string})
|
63
|
+
⌚('#{klazz}##{m}', #{Kantox::Chronoscope.config.options!.silent && false || true}) { #{receiver}#{CHAIN_PREFIX}#{m} #{arg_string} }
|
61
64
|
end
|
62
65
|
|
|
63
66
|
end
|
64
67
|
rescue NameError
|
65
|
-
|
68
|
+
Generic::LOGGER.debug [
|
69
|
+
" #{Generic::COLOR_WARN}[#{Generic::LOGGER_TAG}] ERROR#{Generic::COLOR_NONE} #{Generic::BM_DELIMITER} “#{Generic::COLOR_WARN}#{e.message}#{Generic::COLOR_NONE}”",
|
70
|
+
e.backtrace.map { |s| "#{Generic::COLOR_WARN}#{s}#{Generic::COLOR_NONE}" }
|
71
|
+
].join("#{$/}⮩\t")
|
66
72
|
end
|
67
73
|
end
|
68
74
|
# rubocop:enable Metrics/MethodLength
|
@@ -24,12 +24,10 @@ module Kantox
|
|
24
24
|
@@★ = []
|
25
25
|
|
26
26
|
# rubocop:disable Style/MethodName
|
27
|
-
# rubocop:disable Style/OpMethod
|
28
27
|
# rubocop:disable Metrics/MethodLength
|
29
28
|
# rubocop:disable Metrics/AbcSize
|
30
|
-
# rubocop:disable Style/SpecialGlobalVars
|
31
29
|
|
32
|
-
def ⌚(arg = DEFAULT_TAG)
|
30
|
+
def ⌚(arg = DEFAULT_TAG, log = false)
|
33
31
|
return (@@chronoscope_data[arg.to_s] = nil) unless block_given? # pass no block to reset
|
34
32
|
|
35
33
|
result = nil # needed for it to be defined in this scope
|
@@ -39,7 +37,7 @@ module Kantox
|
|
39
37
|
(Benchmark.measure { result = yield }).tap do |bm|
|
40
38
|
@@chronoscope_data[arg.to_s][:count] += 1
|
41
39
|
@@chronoscope_data[arg.to_s][:total] += bm.real
|
42
|
-
LOGGER.debug log_bm arg, bm
|
40
|
+
LOGGER.debug log_bm arg, bm if log
|
43
41
|
end
|
44
42
|
result
|
45
43
|
rescue => e
|
@@ -57,9 +55,6 @@ module Kantox
|
|
57
55
|
|
58
56
|
log_report(count).tap do |log_hash|
|
59
57
|
LOGGER.debug(log_hash[:string]) if log
|
60
|
-
puts '—' * 80
|
61
|
-
puts @@chronoscope_data.inspect
|
62
|
-
puts '—' * 80
|
63
58
|
log_hash[:data] = @@chronoscope_data.dup
|
64
59
|
@@chronoscope_data.clear if cleanup
|
65
60
|
end
|
@@ -75,7 +70,7 @@ module Kantox
|
|
75
70
|
BM_DELIMITER,
|
76
71
|
"#{COLOR_PALE}#{@@chronoscope_data[arg.to_s][:total].round(3)}#{COLOR_NONE}",
|
77
72
|
bm.to_s
|
78
|
-
].join(' ')
|
73
|
+
].join(' ').strip
|
79
74
|
end
|
80
75
|
|
81
76
|
def log_problem(arg, e)
|
@@ -122,7 +117,11 @@ module Kantox
|
|
122
117
|
].join
|
123
118
|
end),
|
124
119
|
"#{COLOR_PALE}#{'—' * log_width}#{COLOR_NONE}",
|
125
|
-
|
120
|
+
[
|
121
|
+
"#{COLOR_VIVID}#{'total'.rjust(method_len, ' ')}#{COLOR_NONE}#{ARROW}",
|
122
|
+
' ' * (times_len + average_len + 2 * BM_DELIMITER.length),
|
123
|
+
"#{COLOR_VIVID}#{total}#{COLOR_NONE}"
|
124
|
+
].join,
|
126
125
|
delim_label.last
|
127
126
|
].flatten.join($/)
|
128
127
|
|
@@ -136,10 +135,8 @@ module Kantox
|
|
136
135
|
end
|
137
136
|
|
138
137
|
protected :log_problem, :log_bm, :log_report, :log_width
|
139
|
-
# rubocop:enable Style/SpecialGlobalVars
|
140
138
|
# rubocop:enable Metrics/AbcSize
|
141
139
|
# rubocop:enable Metrics/MethodLength
|
142
|
-
# rubocop:enable Style/OpMethod
|
143
140
|
# rubocop:enable Style/MethodName
|
144
141
|
|
145
142
|
def inject(top = nil)
|