rspec-sleep_study 0.0.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/rspec/sleep_study.rb +78 -1
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 50c24123b8e00e6d07d2edea894d7d00a1674de50c980ac2ed64da7f4d368e16
|
4
|
+
data.tar.gz: 594cad1ffa4a248a795c80a63705df1dafaf5812bba040fb1cb8d132af9326ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 719426f4a037c24386ee087b94f856517b30108fe7ce9b8f2128f17be51cbcc11cf3af642ed4e07d95dda5126ecb2d56b437003594a7ced271570de7d35bbb36
|
7
|
+
data.tar.gz: 3689be2a1b235529292694d75e07f9ff4cc1ec2bea87cb387272c03eca0c0b73729fd0fb10a61c34bdd1330f081236ab5c23c4cc63a84e764e0dfe766113ac52
|
data/lib/rspec/sleep_study.rb
CHANGED
@@ -1,6 +1,83 @@
|
|
1
|
-
require "rspec"
|
1
|
+
require "rspec/core"
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joey Schoblaska / Kenna Security
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|
@@ -24,18 +24,18 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description:
|
28
|
-
email:
|
27
|
+
description:
|
28
|
+
email:
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- lib/rspec/sleep_study.rb
|
34
|
-
homepage: https://github.com/
|
34
|
+
homepage: https://github.com/joeyschoblaska/rspec-sleep_study
|
35
35
|
licenses:
|
36
36
|
- MIT
|
37
37
|
metadata: {}
|
38
|
-
post_install_message:
|
38
|
+
post_install_message:
|
39
39
|
rdoc_options: []
|
40
40
|
require_paths:
|
41
41
|
- lib
|
@@ -50,9 +50,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
|
-
|
54
|
-
|
55
|
-
signing_key:
|
53
|
+
rubygems_version: 3.2.3
|
54
|
+
signing_key:
|
56
55
|
specification_version: 4
|
57
56
|
summary: An RSpec profiler that shows you how long specs are spending in `sleep`
|
58
57
|
test_files: []
|