perfetto 0.1.14 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/ext/perfetto/perfetto.c +47 -0
- data/ext/perfetto/perfetto_internal.cc +51 -0
- data/ext/perfetto/perfetto_internal.h +12 -0
- data/lib/perfetto/configure.rb +1 -0
- data/lib/perfetto/perfetto.rb +17 -13
- data/lib/perfetto/version.rb +1 -1
- data/lib/perfetto.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b753aabc8493140c2019e6eac7673df495b2f3144f161c88eb561210d78171ff
|
4
|
+
data.tar.gz: 300ea0e7a5f70452944921eb44dfe24f51e49760308f5aece59e2d6cd5572f95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b12129eb219d48f12658c43679d1a2b09663f5dc1cdcbab1ab7a44a92d98b3fbecc2cfe5d0d851e5583d3acbb3683fb2155f03dc64cb744ce692da0b4ff286e
|
7
|
+
data.tar.gz: 2c8ce26e43b3a3f61851595fcd9721136bb9ff7e21c4899e1af56b357b44e2a2af2ab8575ce1d60844281fde920cfd1217cc549fb5770550b6cfdbe29ce5e88f
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require "bundler/gem_tasks"
|
|
4
4
|
|
5
5
|
require "rake/extensiontask"
|
6
6
|
gemspec = Gem::Specification.load("perfetto.gemspec")
|
7
|
-
Rake::ExtensionTask.new("
|
7
|
+
Rake::ExtensionTask.new("perfetto_native", gemspec) do |ext|
|
8
8
|
ext.ext_dir = "ext/perfetto"
|
9
9
|
ext.lib_dir = "lib/perfetto"
|
10
10
|
end
|
data/ext/perfetto/perfetto.c
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
/* Modules */
|
6
6
|
static VALUE rb_mPerfetto;
|
7
|
+
static VALUE rb_mFiber;
|
7
8
|
|
8
9
|
/* Methods */
|
9
10
|
|
@@ -75,9 +76,49 @@ static VALUE rb_perfetto_trace_counter(VALUE self, VALUE category, VALUE name, V
|
|
75
76
|
}
|
76
77
|
}
|
77
78
|
|
79
|
+
/* Ruby Fiber */
|
80
|
+
static int current_fiber_object_id(void)
|
81
|
+
{
|
82
|
+
VALUE fiber = rb_funcall(rb_mFiber, rb_intern("current"), 0);
|
83
|
+
VALUE object_id = rb_funcall(fiber, rb_intern("object_id"), 0);
|
84
|
+
return NUM2LL(object_id);
|
85
|
+
}
|
86
|
+
|
87
|
+
static VALUE rb_perfetto_fiber_trace_event_begin(VALUE self, VALUE category, VALUE name)
|
88
|
+
{
|
89
|
+
perfetto_fiber_trace_event_begin(StringValuePtr(category), StringValuePtr(name), current_fiber_object_id());
|
90
|
+
return Qnil;
|
91
|
+
}
|
92
|
+
|
93
|
+
static VALUE rb_perfetto_fiber_trace_event_end(VALUE self, VALUE category)
|
94
|
+
{
|
95
|
+
perfetto_fiber_trace_event_end(StringValuePtr(category), current_fiber_object_id());
|
96
|
+
return Qnil;
|
97
|
+
}
|
98
|
+
|
99
|
+
static VALUE rb_perfetto_fiber_trace_event_instant(VALUE self, VALUE category, VALUE name)
|
100
|
+
{
|
101
|
+
perfetto_fiber_trace_event_instant(StringValuePtr(category), StringValuePtr(name), current_fiber_object_id());
|
102
|
+
return Qnil;
|
103
|
+
}
|
104
|
+
|
105
|
+
static VALUE rb_perfetto_fiber_trace_event_instant_with_debug_info(VALUE self, VALUE category, VALUE name, VALUE debug_info_key, VALUE debug_info_value)
|
106
|
+
{
|
107
|
+
perfetto_fiber_trace_event_instant_with_debug_info(StringValuePtr(category), StringValuePtr(name), StringValuePtr(debug_info_key), StringValuePtr(debug_info_value), current_fiber_object_id());
|
108
|
+
return Qnil;
|
109
|
+
}
|
110
|
+
|
111
|
+
static VALUE rb_perfetto_fiber_trace_event_begin_with_debug_info(VALUE self, VALUE category, VALUE name, VALUE debug_info_key, VALUE debug_info_value)
|
112
|
+
{
|
113
|
+
perfetto_fiber_trace_event_begin_with_debug_info(StringValuePtr(category), StringValuePtr(name), StringValuePtr(debug_info_key), StringValuePtr(debug_info_value), current_fiber_object_id());
|
114
|
+
return Qnil;
|
115
|
+
}
|
116
|
+
|
117
|
+
|
78
118
|
void Init_perfetto_native(void)
|
79
119
|
{
|
80
120
|
rb_mPerfetto = rb_define_module("Perfetto");
|
121
|
+
rb_mFiber = rb_define_class("Fiber", rb_cObject);
|
81
122
|
|
82
123
|
rb_define_module_function(rb_mPerfetto, "start_tracing", rb_perfetto_start_tracing, 1);
|
83
124
|
rb_define_module_function(rb_mPerfetto, "stop_tracing", rb_perfetto_stop_tracing, 1);
|
@@ -89,4 +130,10 @@ void Init_perfetto_native(void)
|
|
89
130
|
rb_define_module_function(rb_mPerfetto, "trace_event_instant", rb_perfetto_trace_event_instant, 2);
|
90
131
|
rb_define_module_function(rb_mPerfetto, "trace_event_instant_with_debug_info", rb_perfetto_trace_event_instant_with_debug_info, 4);
|
91
132
|
rb_define_module_function(rb_mPerfetto, "trace_event_begin_with_debug_info", rb_perfetto_trace_event_begin_with_debug_info, 4);
|
133
|
+
|
134
|
+
rb_define_module_function(rb_mPerfetto, "fiber_trace_event_begin", rb_perfetto_fiber_trace_event_begin, 2);
|
135
|
+
rb_define_module_function(rb_mPerfetto, "fiber_trace_event_end", rb_perfetto_fiber_trace_event_end, 1);
|
136
|
+
rb_define_module_function(rb_mPerfetto, "fiber_trace_event_instant", rb_perfetto_fiber_trace_event_instant, 2);
|
137
|
+
rb_define_module_function(rb_mPerfetto, "fiber_trace_event_instant_with_debug_info", rb_perfetto_fiber_trace_event_instant_with_debug_info, 4);
|
138
|
+
rb_define_module_function(rb_mPerfetto, "fiber_trace_event_begin_with_debug_info", rb_perfetto_fiber_trace_event_begin_with_debug_info, 4);
|
92
139
|
}
|
@@ -4,8 +4,10 @@
|
|
4
4
|
#include <atomic>
|
5
5
|
#include <mutex>
|
6
6
|
#include <fstream>
|
7
|
+
#include <sstream>
|
7
8
|
#include <vector>
|
8
9
|
#include <string>
|
10
|
+
#include <thread>
|
9
11
|
|
10
12
|
#include "perfetto_internal.h"
|
11
13
|
|
@@ -146,4 +148,53 @@ extern "C"
|
|
146
148
|
debug_info_key, debug_info_value);
|
147
149
|
}
|
148
150
|
|
151
|
+
/* Ruby Fiber */
|
152
|
+
static inline perfetto::Track fiber_track(const int64_t fiber_object_id)
|
153
|
+
{
|
154
|
+
auto tid = std::this_thread::get_id();
|
155
|
+
std::stringstream ss;
|
156
|
+
ss << "T(" << tid << ")F(" << fiber_object_id << ")"; // T(thread_id)F(fiber_id)
|
157
|
+
perfetto::Track fiber_track(fiber_object_id);
|
158
|
+
auto track_desc = fiber_track.Serialize();
|
159
|
+
track_desc.set_name(ss.str());
|
160
|
+
perfetto::TrackEvent::SetTrackDescriptor(fiber_track, track_desc);
|
161
|
+
return fiber_track;
|
162
|
+
}
|
163
|
+
|
164
|
+
void perfetto_fiber_trace_event_begin(const char *const category, const char *const name, const int64_t fiber_object_id)
|
165
|
+
{
|
166
|
+
perfetto::DynamicCategory dynamic_category(category);
|
167
|
+
perfetto::DynamicString dynamic_name(name);
|
168
|
+
TRACE_EVENT_BEGIN(dynamic_category, dynamic_name, fiber_track(fiber_object_id));
|
169
|
+
}
|
170
|
+
|
171
|
+
void perfetto_fiber_trace_event_end(const char *const category, const int64_t fiber_object_id)
|
172
|
+
{
|
173
|
+
perfetto::DynamicCategory dynamic_category(category);
|
174
|
+
TRACE_EVENT_END(dynamic_category, fiber_track(fiber_object_id));
|
175
|
+
}
|
176
|
+
|
177
|
+
void perfetto_fiber_trace_event_instant(const char *const category, const char *const name, const int64_t fiber_object_id)
|
178
|
+
{
|
179
|
+
perfetto::DynamicCategory dynamic_category(category);
|
180
|
+
perfetto::DynamicString dynamic_name(name);
|
181
|
+
TRACE_EVENT_INSTANT(dynamic_category, dynamic_name, fiber_track(fiber_object_id));
|
182
|
+
}
|
183
|
+
|
184
|
+
void perfetto_fiber_trace_event_instant_with_debug_info(const char *const category, const char *const name, const char *const debug_info_key, const char *const debug_info_value, const int64_t fiber_object_id)
|
185
|
+
{
|
186
|
+
perfetto::DynamicCategory dynamic_category(category);
|
187
|
+
perfetto::DynamicString dynamic_name(name);
|
188
|
+
TRACE_EVENT_INSTANT(dynamic_category, dynamic_name, fiber_track(fiber_object_id),
|
189
|
+
debug_info_key, debug_info_value);
|
190
|
+
}
|
191
|
+
|
192
|
+
void perfetto_fiber_trace_event_begin_with_debug_info(const char *const category, const char *const name, const char *const debug_info_key, const char *const debug_info_value, const int64_t fiber_object_id)
|
193
|
+
{
|
194
|
+
perfetto::DynamicCategory dynamic_category(category);
|
195
|
+
perfetto::DynamicString dynamic_name(name);
|
196
|
+
TRACE_EVENT_BEGIN(dynamic_category, dynamic_name, fiber_track(fiber_object_id),
|
197
|
+
debug_info_key, debug_info_value);
|
198
|
+
}
|
199
|
+
|
149
200
|
} // extern "C"
|
@@ -29,6 +29,18 @@ extern "C"
|
|
29
29
|
void perfetto_trace_event_instant_with_debug_info(const char *const category, const char *const name, const char *const debug_info_key, const char *const debug_info_value);
|
30
30
|
|
31
31
|
void perfetto_trace_event_begin_with_debug_info(const char *const category, const char *const name, const char *const debug_info_key, const char *const debug_info_value);
|
32
|
+
|
33
|
+
/* Ruby Fiber */
|
34
|
+
void perfetto_fiber_trace_event_begin(const char *const category, const char *const name, const int64_t fiber_object_id);
|
35
|
+
|
36
|
+
void perfetto_fiber_trace_event_end(const char *const category, const int64_t fiber_object_id);
|
37
|
+
|
38
|
+
void perfetto_fiber_trace_event_instant(const char *const category, const char *const name, const int64_t fiber_object_id);
|
39
|
+
|
40
|
+
void perfetto_fiber_trace_event_instant_with_debug_info(const char *const category, const char *const name, const char *const debug_info_key, const char *const debug_info_value, const int64_t fiber_object_id);
|
41
|
+
|
42
|
+
void perfetto_fiber_trace_event_begin_with_debug_info(const char *const category, const char *const name, const char *const debug_info_key, const char *const debug_info_value, const int64_t fiber_object_id);
|
43
|
+
|
32
44
|
#ifdef __cplusplus
|
33
45
|
}
|
34
46
|
#endif
|
data/lib/perfetto/configure.rb
CHANGED
data/lib/perfetto/perfetto.rb
CHANGED
@@ -8,6 +8,23 @@ module Perfetto
|
|
8
8
|
end
|
9
9
|
|
10
10
|
if Perfetto::Configure.enable_tracing?
|
11
|
+
if Perfetto::Configure.enable_fiber?
|
12
|
+
class << self
|
13
|
+
# Replace thread based methods with fiber based methods
|
14
|
+
alias thread_trace_event_begin trace_event_begin
|
15
|
+
alias thread_trace_event_end trace_event_end
|
16
|
+
alias thread_trace_event_instant trace_event_instant
|
17
|
+
alias thread_trace_event_begin_with_debug_info trace_event_begin_with_debug_info
|
18
|
+
alias thread_trace_event_instant_with_debug_info trace_event_instant_with_debug_info
|
19
|
+
|
20
|
+
alias trace_event_begin fiber_trace_event_begin
|
21
|
+
alias trace_event_end fiber_trace_event_end
|
22
|
+
alias trace_event_instant fiber_trace_event_instant
|
23
|
+
alias trace_event_begin_with_debug_info fiber_trace_event_begin_with_debug_info
|
24
|
+
alias trace_event_instant_with_debug_info fiber_trace_event_instant_with_debug_info
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
11
28
|
# Default arguments implemented in this wrapper
|
12
29
|
def self.start_tracing
|
13
30
|
start_tracing_native Configure.buffer_size_kb
|
@@ -16,19 +33,6 @@ module Perfetto
|
|
16
33
|
def self.stop_tracing(trace_file_name = "#{Time.now.strftime("%Y%m%d-%H-%M-%S")}.pftrace")
|
17
34
|
stop_tracing_native trace_file_name
|
18
35
|
end
|
19
|
-
|
20
|
-
# Methods implemented in native extension
|
21
|
-
# We don't want to proxy these methods because they are called very frequently on hot paths
|
22
|
-
# def self.start_tracing; end
|
23
|
-
# def self.stop_tracing(_trace_file_name); end
|
24
|
-
# def self.trace_event_begin(_class_name, _method_name); end
|
25
|
-
# def self.trace_event_end(_class_name); end
|
26
|
-
# def self.trace_counter(_class_name, _counter_name, _counter_value); end
|
27
|
-
# def self.trace_counter_i64(_class_name, _counter_name, _counter_value); end
|
28
|
-
# def self.trace_counter_double(_class_name, _counter_name, _counter_value); end
|
29
|
-
# def self.trace_event_instant(_class_name, _method_name); end
|
30
|
-
# def self.trace_event_begin_with_debug_info(_class_name, _method_name, _debug_key, _debug_value); end
|
31
|
-
# def self.trace_event_instant_with_debug_info(_class_name, _method_name, _debug_key, _debug_value); end
|
32
36
|
else
|
33
37
|
# Stub methods
|
34
38
|
def self.start_tracing; end
|
data/lib/perfetto/version.rb
CHANGED
data/lib/perfetto.rb
CHANGED
@@ -15,8 +15,9 @@ require_relative "perfetto/middleware"
|
|
15
15
|
# at the first call to 'setup' method instead of
|
16
16
|
# every call to bussiness logics being traced.
|
17
17
|
module Perfetto
|
18
|
-
def self.setup(enable_tracing: nil, buffer_size_kb: nil)
|
18
|
+
def self.setup(enable_tracing: nil, enable_fiber: nil, buffer_size_kb: nil)
|
19
19
|
Configure.enable_tracing = enable_tracing unless enable_tracing.nil?
|
20
|
+
Configure.enable_fiber = enable_fiber unless enable_fiber.nil?
|
20
21
|
Configure.buffer_size_kb = buffer_size_kb unless buffer_size_kb.nil?
|
21
22
|
|
22
23
|
# Native extension
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perfetto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kowalski Dark
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Yet another event tracing library for Ruby.
|
14
14
|
email:
|