5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/ruby-prof-speedscope.rb', line 5
def print_threads
profiles = []
@output << " {\n \"$schema\": \"https://www.speedscope.app/file-format-schema.json\",\n \"exporter\": \"ruby-prof-speedscope\",\n \"shared\": {\n \"frames\": [\n HEADER\n\n frames = {}\n frame_index = 0\n @result.threads.each do |thread|\n thread.methods.each_with_index do |method, idx|\n next if frames.has_key?(method.object_id)\n name = \"\#{method.klass_name}#\#{method.method_name}\"\n name += \" *recursive*\" if method.recursive?\n @output << <<~FRAME\n {\n \"name\": \"\#{name}\",\n \"file\": \"\#{method.source_file}\",\n \"line\": \"\#{method.line}\"\n },\n FRAME\n frames[method.object_id] = frame_index\n frame_index += 1\n end\n end\n\n @output << <<~FRAMES\n {\"name\": \"dummy_trailing_comma\"}\n ]\n },\n \"profiles\": [\n FRAMES\n\n @result.threads.each_with_index do |thread, idx|\n @output << <<~PROFILES\n {\n \"type\": \"evented\",\n \"name\": \"Thread: \#{thread.id}, Fiber: \#{thread.fiber_id}\",\n \"unit\": \"seconds\",\n \"startValue\": 0,\n \"endValue\": \#{JSON.dump(thread.call_tree.measurement.total_time)},\n \"events\": [\n PROFILES\n print_call_tree(thread.call_tree, frames, 0.0, true)\n @output << <<~PROFILES\n ]\n }\#{idx < @result.threads.length - 1 ? \",\" : \"\"}\n PROFILES\n end\n\n @output << <<~ENDING\n ]\n }\n ENDING\nend\n"
|