ruby-prof-speedscope 0.2.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 +7 -0
- data/lib/ruby-prof-speedscope.rb +90 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b6fab0e26495d65a4c9b629c349b097e76611f30
|
4
|
+
data.tar.gz: d294f6877e406679792d9354485fef31937c9e3b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89ff71a99b168e704eb0c88abbde06402dfb7e39d65c40396a724b881ae13aaf56507691570d92c956a2024b6647782e064cfe19f27fa70162a7850d7c6f639b
|
7
|
+
data.tar.gz: be775854ece0ef9194fafa9a14a8e8cb903fc1f9e6939932cdb1a7ed696fcb96f33db05e44315d7e2a71b69f54c8c220a7292f06a99dfda829706ee3aaf14558
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module RubyProf
|
4
|
+
class SpeedscopePrinter < AbstractPrinter
|
5
|
+
def print_threads
|
6
|
+
profiles = []
|
7
|
+
@output << <<~HEADER
|
8
|
+
{
|
9
|
+
"$schema": "https://www.speedscope.app/file-format-schema.json",
|
10
|
+
"exporter": "ruby-prof-speedscope",
|
11
|
+
"shared": {
|
12
|
+
"frames": [
|
13
|
+
HEADER
|
14
|
+
|
15
|
+
frames = {}
|
16
|
+
frame_index = 0
|
17
|
+
@result.threads.each do |thread|
|
18
|
+
thread.methods.each_with_index do |method, idx|
|
19
|
+
next if frames.has_key?(method.object_id)
|
20
|
+
name = "#{method.klass_name}##{method.method_name}"
|
21
|
+
name += " *recursive*" if method.recursive?
|
22
|
+
@output << <<~FRAME
|
23
|
+
{
|
24
|
+
"name": "#{name}",
|
25
|
+
"file": "#{method.source_file}",
|
26
|
+
"line": "#{method.line}"
|
27
|
+
},
|
28
|
+
FRAME
|
29
|
+
frames[method.object_id] = frame_index
|
30
|
+
frame_index += 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
@output << <<~FRAMES
|
35
|
+
{"name": "dummy_trailing_comma"}
|
36
|
+
]
|
37
|
+
},
|
38
|
+
"profiles": [
|
39
|
+
FRAMES
|
40
|
+
|
41
|
+
@result.threads.each_with_index do |thread, idx|
|
42
|
+
@output << <<~PROFILES
|
43
|
+
{
|
44
|
+
"type": "evented",
|
45
|
+
"name": "Thread: #{thread.id}, Fiber: #{thread.fiber_id}",
|
46
|
+
"unit": "seconds",
|
47
|
+
"startValue": 0,
|
48
|
+
"endValue": #{JSON.dump(thread.call_tree.measurement.total_time)},
|
49
|
+
"events": [
|
50
|
+
PROFILES
|
51
|
+
print_call_tree(thread.call_tree, frames, 0.0, true)
|
52
|
+
@output << <<~PROFILES
|
53
|
+
]
|
54
|
+
}#{idx < @result.threads.length - 1 ? "," : ""}
|
55
|
+
PROFILES
|
56
|
+
end
|
57
|
+
|
58
|
+
@output << <<~ENDING
|
59
|
+
]
|
60
|
+
}
|
61
|
+
ENDING
|
62
|
+
end
|
63
|
+
|
64
|
+
def print_call_tree(call_tree, frames, start_time, root = false)
|
65
|
+
@output << <<~BEGINEVENT
|
66
|
+
{
|
67
|
+
"type": "O",
|
68
|
+
"frame": #{frames[call_tree.target.object_id]},
|
69
|
+
"at": #{JSON.dump(start_time)}
|
70
|
+
},
|
71
|
+
BEGINEVENT
|
72
|
+
|
73
|
+
original_start_time = start_time
|
74
|
+
start_time += call_tree.self_time
|
75
|
+
call_tree.children.each do |child_tree|
|
76
|
+
next if child_tree.total_time < 0
|
77
|
+
print_call_tree(child_tree, frames, start_time)
|
78
|
+
start_time += child_tree.total_time
|
79
|
+
end
|
80
|
+
|
81
|
+
@output << <<~CLOSEEVENT
|
82
|
+
{
|
83
|
+
"type": "C",
|
84
|
+
"frame": #{frames[call_tree.target.object_id]},
|
85
|
+
"at": #{JSON.dump(original_start_time + call_tree.total_time)}
|
86
|
+
}#{root ? "" : ","}
|
87
|
+
CLOSEEVENT
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-prof-speedscope
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chan Zuckerberg Initiative
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: opensource@chanzuckerberg.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/ruby-prof-speedscope.rb
|
20
|
+
homepage: https://github.com/chanzuckerberg/ruby-prof-speedscope
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements:
|
39
|
+
- A recent version of ruby-prof.
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.5.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: A ruby-prof printer compatible with speedscope.app.
|
45
|
+
test_files: []
|