rspec-sleep_study 0.0.1 → 1.1.0
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 +5 -5
- data/lib/rspec/sleep_study.rb +77 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bf206c1e45c89ae1faf5eddf2be2d8fcee08618178b87c71186d70c119112826
|
4
|
+
data.tar.gz: b2d8ddaf4284e76186f052405acad2391fa5e105df84621bf2026abc8b3121ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcdb58dd0b3ff3403b54f324a7436ef488c20364ecd2a3cb02a14490c9af80ddc730c47ed00c1c2d00bce1e57eaedcf9af9fbbe4d676ccb142e36119181e1e78
|
7
|
+
data.tar.gz: d47545bbe29f2b25a74b4ee4caf90df91ebb59b5538f8b01dc9f0ff5b5a8ce7cbc4e6ccfe04b9dc66bc2e73fb1dafff7718addb638f0ae26e610a46b3c520543
|
data/lib/rspec/sleep_study.rb
CHANGED
@@ -2,5 +2,82 @@ require "rspec"
|
|
2
2
|
|
3
3
|
module RSpec
|
4
4
|
class SleepStudy
|
5
|
+
RSpec::Core::Formatters.register self, :dump_summary, :example_started,
|
6
|
+
:example_failed, :example_passed, :example_pending
|
7
|
+
|
8
|
+
def initialize(output)
|
9
|
+
@output = output
|
10
|
+
@sleepers = []
|
11
|
+
@locs_by_example = {}
|
12
|
+
@tracers = [
|
13
|
+
TracePoint.new(:c_call) { |tp| start_sleep(tp) if tp.method_id == :sleep },
|
14
|
+
TracePoint.new(:c_return) { |tp| end_sleep if tp.method_id == :sleep }
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
def example_started(notification)
|
19
|
+
@total_time_slept = 0
|
20
|
+
@sleep_starts = []
|
21
|
+
@tracers.each(&:enable)
|
22
|
+
@locs_by_example[notification.example.id] = {}
|
23
|
+
@current_example = notification.example
|
24
|
+
end
|
25
|
+
|
26
|
+
def example_ended(notification)
|
27
|
+
@tracers.each(&:disable)
|
28
|
+
@current_example = nil
|
29
|
+
record_time_slept(notification)
|
30
|
+
end
|
31
|
+
alias example_failed example_ended
|
32
|
+
alias example_passed example_ended
|
33
|
+
alias example_pending example_ended
|
34
|
+
|
35
|
+
def dump_summary(_notification)
|
36
|
+
return unless sleepers_to_report.any?
|
37
|
+
|
38
|
+
@output << "\nThe following examples spent the most time in `sleep`:\n"
|
39
|
+
|
40
|
+
sleepers_to_report.each do |example, slept|
|
41
|
+
@output << " #{slept.round(3)} seconds: #{example.location}\n"
|
42
|
+
|
43
|
+
locs_to_report(example.id, slept).each do |loc, loc_slept|
|
44
|
+
@output << " - #{loc_slept.round(3)} seconds: #{loc}\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
@output << "\n"
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def start_sleep(tp)
|
54
|
+
@sleep_starts << ["#{tp.path}:#{tp.lineno}", Time.now.to_f]
|
55
|
+
end
|
56
|
+
|
57
|
+
def end_sleep
|
58
|
+
if @sleep_starts.any?
|
59
|
+
sleep_start = @sleep_starts.pop
|
60
|
+
loc = sleep_start[0]
|
61
|
+
time_slept = Time.now.to_f - sleep_start[1]
|
62
|
+
@locs_by_example[@current_example.id][loc] ||= 0
|
63
|
+
@locs_by_example[@current_example.id][loc] += time_slept
|
64
|
+
@total_time_slept += time_slept
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def sleepers_to_report
|
69
|
+
@sleepers.sort_by { |s| -s[1] }[0, 10]
|
70
|
+
end
|
71
|
+
|
72
|
+
def locs_to_report(example_id, example_slept)
|
73
|
+
@locs_by_example[example_id].select do |_, slept|
|
74
|
+
slept >= example_slept * 0.25
|
75
|
+
end.sort_by { |_, slept| -slept }
|
76
|
+
end
|
77
|
+
|
78
|
+
def record_time_slept(notification)
|
79
|
+
return if @total_time_slept <= 0.001
|
80
|
+
@sleepers << [notification.example, @total_time_slept]
|
81
|
+
end
|
5
82
|
end
|
6
83
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-sleep_study
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joey Schoblaska / Kenna Security
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
53
|
rubyforge_project:
|
54
|
-
rubygems_version: 2.6
|
54
|
+
rubygems_version: 2.7.6
|
55
55
|
signing_key:
|
56
56
|
specification_version: 4
|
57
57
|
summary: An RSpec profiler that shows you how long specs are spending in `sleep`
|