Module: TestProf::RSpecDissect
- Extended by:
- Logging
- Defined in:
- lib/test_prof/rspec_dissect.rb,
lib/test_prof/rspec_dissect/rspec.rb,
lib/test_prof/rspec_dissect/collectors/let.rb,
lib/test_prof/rspec_dissect/collectors/base.rb,
lib/test_prof/rspec_dissect/collectors/before.rb
Overview
RSpecDissect tracks how much time do you spend in ‘before` hooks and memoization helpers (i.e. `let`) in your tests.
Defined Under Namespace
Modules: Collectors, ExampleInstrumentation, MemoizedInstrumentation
Classes: Configuration, Listener
Constant Summary
collapse
- METRICS =
%w[before let].freeze
Constants included
from Logging
Logging::COLORS
Class Method Summary
collapse
Methods included from Logging
build_log_msg, colorize, log
Class Method Details
.config ⇒ Object
78
79
80
|
# File 'lib/test_prof/rspec_dissect.rb', line 78
def config
@config ||= Configuration.new
end
|
82
83
84
|
# File 'lib/test_prof/rspec_dissect.rb', line 82
def configure
yield config
end
|
.init ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/test_prof/rspec_dissect.rb', line 86
def init
RSpec::Core::Example.prepend(ExampleInstrumentation)
if memoization_available?
RSpec::Core::MemoizedHelpers::ThreadsafeMemoized.prepend(MemoizedInstrumentation)
RSpec::Core::MemoizedHelpers::NonThreadSafeMemoized.prepend(MemoizedInstrumentation)
end
@data = {}
METRICS.each do |type|
@data["total_#{type}"] = 0.0
end
reset!
if config.let? && !memoization_available?
log :warn, "RSpecDissect: `let` profiling is not supported (requires RSpec >= 3.3.0)\n"
end
log :info, "RSpecDissect enabled"
end
|
.memoization_available? ⇒ Boolean
Whether we are able to track ‘let` usage
127
128
129
|
# File 'lib/test_prof/rspec_dissect.rb', line 127
def memoization_available?
defined?(::RSpec::Core::MemoizedHelpers::ThreadsafeMemoized)
end
|
135
136
137
|
# File 'lib/test_prof/rspec_dissect.rb', line 135
def meta_for(key)
@data[key.to_s][:meta]
end
|
.reset! ⇒ Object
120
121
122
123
124
|
# File 'lib/test_prof/rspec_dissect.rb', line 120
def reset!
METRICS.each do |type|
@data[type.to_s] = { time: 0.0, meta: [] }
end
end
|
.time_for(key) ⇒ Object
131
132
133
|
# File 'lib/test_prof/rspec_dissect.rb', line 131
def time_for(key)
@data[key.to_s][:time]
end
|
.total_time_for(key) ⇒ Object
139
140
141
|
# File 'lib/test_prof/rspec_dissect.rb', line 139
def total_time_for(key)
@data["total_#{key}"]
end
|
.track(type, meta = nil) ⇒ Object
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/test_prof/rspec_dissect.rb', line 109
def track(type, meta = nil)
start = TestProf.now
res = yield
delta = (TestProf.now - start)
type = type.to_s
@data[type][:time] += delta
@data[type][:meta] << meta unless meta.nil?
@data["total_#{type}"] += delta
res
end
|