vernier 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -8
- data/bin/vernier +4 -0
- data/examples/minitest.rb +20 -0
- data/examples/ractor.rb +11 -0
- data/examples/rails.rb +125 -0
- data/exe/vernier +38 -0
- data/ext/vernier/vernier.cc +571 -302
- data/lib/vernier/autorun.rb +65 -0
- data/lib/vernier/collector.rb +47 -28
- data/lib/vernier/marker.rb +11 -11
- data/lib/vernier/output/firefox.rb +76 -45
- data/lib/vernier/result.rb +139 -0
- data/lib/vernier/version.rb +1 -1
- data/lib/vernier.rb +6 -133
- data/vernier.gemspec +1 -1
- metadata +12 -5
- data/sig/vernier.rbs +0 -4
data/lib/vernier.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "vernier/version"
|
4
4
|
require_relative "vernier/collector"
|
5
|
+
require_relative "vernier/result"
|
5
6
|
require_relative "vernier/vernier"
|
6
7
|
require_relative "vernier/output/firefox"
|
7
8
|
require_relative "vernier/output/top"
|
@@ -9,162 +10,34 @@ require_relative "vernier/output/top"
|
|
9
10
|
module Vernier
|
10
11
|
class Error < StandardError; end
|
11
12
|
|
12
|
-
class Result
|
13
|
-
attr_reader :weights, :samples, :stack_table, :frame_table, :func_table
|
14
|
-
attr_reader :timestamps, :sample_threads, :sample_categories
|
15
|
-
attr_reader :markers
|
16
|
-
|
17
|
-
attr_accessor :pid, :start_time, :end_time
|
18
|
-
attr_accessor :threads
|
19
|
-
attr_accessor :meta
|
20
|
-
|
21
|
-
def started_at
|
22
|
-
meta[:started_at]
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_gecko
|
26
|
-
Output::Firefox.new(self).output
|
27
|
-
end
|
28
|
-
|
29
|
-
def write(out:)
|
30
|
-
File.write(out, to_gecko)
|
31
|
-
end
|
32
|
-
|
33
|
-
def each_sample
|
34
|
-
return enum_for(__method__) unless block_given?
|
35
|
-
@samples.size.times do |sample_idx|
|
36
|
-
weight = @weights[sample_idx]
|
37
|
-
stack_idx = @samples[sample_idx]
|
38
|
-
yield stack(stack_idx), weight
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class BaseType
|
43
|
-
attr_reader :result, :idx
|
44
|
-
def initialize(result, idx)
|
45
|
-
@result = result
|
46
|
-
@idx = idx
|
47
|
-
end
|
48
|
-
|
49
|
-
def to_s
|
50
|
-
idx.to_s
|
51
|
-
end
|
52
|
-
|
53
|
-
def inspect
|
54
|
-
"#<#{self.class}\n#{to_s}>"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class Func < BaseType
|
59
|
-
def label
|
60
|
-
result.func_table[:name][idx]
|
61
|
-
end
|
62
|
-
alias name label
|
63
|
-
|
64
|
-
def filename
|
65
|
-
result.func_table[:filename][idx]
|
66
|
-
end
|
67
|
-
|
68
|
-
def to_s
|
69
|
-
"#{name} at #{filename}"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
class Frame < BaseType
|
74
|
-
def label; func.label; end
|
75
|
-
def filename; func.filename; end
|
76
|
-
alias name label
|
77
|
-
|
78
|
-
def func
|
79
|
-
func_idx = result.frame_table[:func][idx]
|
80
|
-
Func.new(result, func_idx)
|
81
|
-
end
|
82
|
-
|
83
|
-
def line
|
84
|
-
result.frame_table[:line][idx]
|
85
|
-
end
|
86
|
-
|
87
|
-
def to_s
|
88
|
-
"#{func}:#{line}"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class Stack < BaseType
|
93
|
-
def each_frame
|
94
|
-
return enum_for(__method__) unless block_given?
|
95
|
-
|
96
|
-
stack_idx = idx
|
97
|
-
while stack_idx
|
98
|
-
frame_idx = result.stack_table[:frame][stack_idx]
|
99
|
-
yield Frame.new(result, frame_idx)
|
100
|
-
stack_idx = result.stack_table[:parent][stack_idx]
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def leaf_frame_idx
|
105
|
-
result.stack_table[:frame][idx]
|
106
|
-
end
|
107
|
-
|
108
|
-
def leaf_frame
|
109
|
-
Frame.new(result, leaf_frame_idx)
|
110
|
-
end
|
111
|
-
|
112
|
-
def frames
|
113
|
-
each_frame.to_a
|
114
|
-
end
|
115
|
-
|
116
|
-
def to_s
|
117
|
-
arr = []
|
118
|
-
each_frame do |frame|
|
119
|
-
arr << frame.to_s
|
120
|
-
end
|
121
|
-
arr.join("\n")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def stack(idx)
|
126
|
-
Stack.new(self, idx)
|
127
|
-
end
|
128
|
-
|
129
|
-
def total_bytes
|
130
|
-
@weights.sum
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
13
|
def self.trace(mode: :wall, out: nil, interval: nil)
|
135
14
|
collector = Vernier::Collector.new(mode, { interval: })
|
136
15
|
collector.start
|
137
16
|
|
138
17
|
result = nil
|
139
18
|
begin
|
140
|
-
yield
|
19
|
+
yield collector
|
141
20
|
ensure
|
142
21
|
result = collector.stop
|
22
|
+
if out
|
23
|
+
File.write(out, Output::Firefox.new(result).output)
|
24
|
+
end
|
143
25
|
end
|
144
26
|
|
145
|
-
if out
|
146
|
-
File.write(out, Output::Firefox.new(result).output)
|
147
|
-
end
|
148
27
|
result
|
149
28
|
end
|
150
29
|
|
151
30
|
def self.trace_retained(out: nil, gc: true)
|
152
31
|
3.times { GC.start } if gc
|
153
32
|
|
154
|
-
start_time = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
|
155
|
-
|
156
33
|
collector = Vernier::Collector.new(:retained)
|
157
34
|
collector.start
|
158
35
|
|
159
36
|
result = nil
|
160
37
|
begin
|
161
|
-
yield
|
38
|
+
yield collector
|
162
39
|
ensure
|
163
40
|
result = collector.stop
|
164
|
-
end_time = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
|
165
|
-
result.pid = Process.pid
|
166
|
-
result.start_time = start_time
|
167
|
-
result.end_time = end_time
|
168
41
|
end
|
169
42
|
|
170
43
|
if out
|
data/vernier.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = spec.summary
|
13
13
|
spec.homepage = "https://github.com/jhawthorn/vernier"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">= 3.2.
|
15
|
+
spec.required_ruby_version = ">= 3.2.1"
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = spec.homepage
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vernier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hawthorn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: An experimental profiler
|
14
14
|
email:
|
15
15
|
- john@hawthorn.email
|
16
|
-
executables:
|
16
|
+
executables:
|
17
|
+
- vernier
|
17
18
|
extensions:
|
18
19
|
- ext/vernier/extconf.rb
|
19
20
|
extra_rdoc_files: []
|
@@ -25,18 +26,24 @@ files:
|
|
25
26
|
- Rakefile
|
26
27
|
- bin/console
|
27
28
|
- bin/setup
|
29
|
+
- bin/vernier
|
30
|
+
- examples/minitest.rb
|
31
|
+
- examples/ractor.rb
|
32
|
+
- examples/rails.rb
|
28
33
|
- examples/threaded_http_requests.rb
|
34
|
+
- exe/vernier
|
29
35
|
- ext/vernier/extconf.rb
|
30
36
|
- ext/vernier/ruby_type_names.h
|
31
37
|
- ext/vernier/vernier.cc
|
32
38
|
- ext/vernier/vernier.hh
|
33
39
|
- lib/vernier.rb
|
40
|
+
- lib/vernier/autorun.rb
|
34
41
|
- lib/vernier/collector.rb
|
35
42
|
- lib/vernier/marker.rb
|
36
43
|
- lib/vernier/output/firefox.rb
|
37
44
|
- lib/vernier/output/top.rb
|
45
|
+
- lib/vernier/result.rb
|
38
46
|
- lib/vernier/version.rb
|
39
|
-
- sig/vernier.rbs
|
40
47
|
- vernier.gemspec
|
41
48
|
homepage: https://github.com/jhawthorn/vernier
|
42
49
|
licenses:
|
@@ -53,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
60
|
requirements:
|
54
61
|
- - ">="
|
55
62
|
- !ruby/object:Gem::Version
|
56
|
-
version: 3.2.
|
63
|
+
version: 3.2.1
|
57
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
65
|
requirements:
|
59
66
|
- - ">="
|
data/sig/vernier.rbs
DELETED