kantox-chronoscope 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6d28754b2595ecfc31f595f08474d07405c8ddf
4
- data.tar.gz: 90b19750de99c9b317c59d53ceb850234aaa07f8
3
+ metadata.gz: a4d53501fb7342dcf28242a948af1251633b0383
4
+ data.tar.gz: a2da48b18c3ad4ca31c7e82d2672bb1d93d631c8
5
5
  SHA512:
6
- metadata.gz: a530d3ecc287e92acc653f09a494c20c5c937c7f8800f448c742f0d08e387175c29f6ee2d11a7070f32056fe7f44ff62178fa39361f3d59e65a567bfc86f8ab5
7
- data.tar.gz: ec9614646ce1dcafb53df11419b53bfc3c436ee825a864bd1b457017ca201d41f77f29c42aadf72cbb3664ced19e1c7a2466df3593df349e831a9f1a6121a687
6
+ metadata.gz: 09cec413684352711afc0f92055bc45a56c97d8224e2649d4235c538e0964e1eff9828d3fc55cafec069288072060c4e00c7c3e15747f1e614f31fee0121b27a
7
+ data.tar.gz: 4b5dc5de71c87957b684954e58dc5c0bcab5826034c2692c597317417fa20b074a536a2b0bfbbe741af6e3b49faf900cc6f36cffc62f2449824de20bb37417aa
data/.rubocop.yml CHANGED
@@ -24,3 +24,7 @@ Style/ClassVars:
24
24
  Metrics/ModuleLength:
25
25
  Exclude:
26
26
  - 'lib/kantox/chronoscope/generic.rb'
27
+
28
+ Style/SpecialGlobalVars:
29
+ Exclude:
30
+ - 'lib/**/*'
@@ -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}(*args)
60
- ⌚('#{klazz}##{m}') { #{CHAIN_PREFIX}#{m} *args }
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
- # FIXME: report
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
- "#{COLOR_VIVID}#{'total'.rjust(method_len, ' ')}#{COLOR_NONE}#{ARROW}#{' ' * TIMES_LABEL.length}#{COLOR_VIVID}#{total}#{COLOR_NONE}",
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)
@@ -1,5 +1,5 @@
1
1
  module Kantox
2
2
  module Chronoscope
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kantox-chronoscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kantox