perfetto 0.1.14 → 0.1.16

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e3e8e962aeab33cbf932918444eb8273b5488d7c6ef8f06d0093ba7ce61ef26
4
- data.tar.gz: 8fc94a35ac54d16ece628dd97d55ee67b50c5b186e5c62ddbf6ec63127ed995b
3
+ metadata.gz: ab803475bdbf8cc2b0e37bb533978157061613c4c727defe2ef1992d2c1e79d5
4
+ data.tar.gz: 0754e92147558a60850d27f7f85bcaf39d9dcddbca23c07fc2e98868008776b0
5
5
  SHA512:
6
- metadata.gz: ea31ea7afcd01440e9f1eca3a3ad07c2a1ae085013f2dabf2917448769ffcd783739412e7ed28003131b4efa3aaeb908985d6490e9c0af618beb573126200b27
7
- data.tar.gz: 7ebdb79efbfca675bc28d984dda057f2cc2c64e7c4345c099b5acf5bacf9a692ce40eeb689329ad2d416b74ded1b4f207f0f2a51f613d6259c8b6a0df4568617
6
+ metadata.gz: 02414b0a024d2f0f9f6e543054cc53c9597825131b42a0f98c8a1e5a5c6cb778595ccd6469e5dd02598af56a88bafda2df971b6f096212a589e1223f441fd4a3
7
+ data.tar.gz: 87d77c0322a76f21505ef2ac9a54959e197c3c1271a1d453d4e46b0ed9aae0014955bb8a83e4504b4372f440fb66d0954dc66d141678da9a2486da87d2ca38a8
data/.rubocop.yml CHANGED
File without changes
data/README.md CHANGED
File without changes
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("perfetto", gemspec) do |ext|
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/example/example.png CHANGED
File without changes
data/example/example.rb CHANGED
File without changes
data/ext/perfetto/LICENSE CHANGED
File without changes
File without changes
File without changes
@@ -1,9 +1,11 @@
1
+ #include <stdbool.h>
1
2
  #include <ruby.h>
2
3
 
3
4
  #include "perfetto_internal.h"
4
5
 
5
6
  /* Modules */
6
7
  static VALUE rb_mPerfetto;
8
+ static VALUE rb_mFiber;
7
9
 
8
10
  /* Methods */
9
11
 
@@ -75,9 +77,49 @@ static VALUE rb_perfetto_trace_counter(VALUE self, VALUE category, VALUE name, V
75
77
  }
76
78
  }
77
79
 
80
+ /* Ruby Fiber */
81
+ static int current_fiber_object_id(void)
82
+ {
83
+ VALUE fiber = rb_funcall(rb_mFiber, rb_intern("current"), 0);
84
+ VALUE object_id = rb_funcall(fiber, rb_intern("object_id"), 0);
85
+ return NUM2LL(object_id);
86
+ }
87
+
88
+ static VALUE rb_perfetto_fiber_trace_event_begin(VALUE self, VALUE category, VALUE name)
89
+ {
90
+ perfetto_fiber_trace_event_begin(StringValuePtr(category), StringValuePtr(name), current_fiber_object_id());
91
+ return Qnil;
92
+ }
93
+
94
+ static VALUE rb_perfetto_fiber_trace_event_end(VALUE self, VALUE category)
95
+ {
96
+ perfetto_fiber_trace_event_end(StringValuePtr(category), current_fiber_object_id());
97
+ return Qnil;
98
+ }
99
+
100
+ static VALUE rb_perfetto_fiber_trace_event_instant(VALUE self, VALUE category, VALUE name)
101
+ {
102
+ perfetto_fiber_trace_event_instant(StringValuePtr(category), StringValuePtr(name), current_fiber_object_id());
103
+ return Qnil;
104
+ }
105
+
106
+ 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)
107
+ {
108
+ perfetto_fiber_trace_event_instant_with_debug_info(StringValuePtr(category), StringValuePtr(name), StringValuePtr(debug_info_key), StringValuePtr(debug_info_value), current_fiber_object_id());
109
+ return Qnil;
110
+ }
111
+
112
+ 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)
113
+ {
114
+ perfetto_fiber_trace_event_begin_with_debug_info(StringValuePtr(category), StringValuePtr(name), StringValuePtr(debug_info_key), StringValuePtr(debug_info_value), current_fiber_object_id());
115
+ return Qnil;
116
+ }
117
+
118
+
78
119
  void Init_perfetto_native(void)
79
120
  {
80
121
  rb_mPerfetto = rb_define_module("Perfetto");
122
+ rb_mFiber = rb_define_class("Fiber", rb_cObject);
81
123
 
82
124
  rb_define_module_function(rb_mPerfetto, "start_tracing", rb_perfetto_start_tracing, 1);
83
125
  rb_define_module_function(rb_mPerfetto, "stop_tracing", rb_perfetto_stop_tracing, 1);
@@ -89,4 +131,10 @@ void Init_perfetto_native(void)
89
131
  rb_define_module_function(rb_mPerfetto, "trace_event_instant", rb_perfetto_trace_event_instant, 2);
90
132
  rb_define_module_function(rb_mPerfetto, "trace_event_instant_with_debug_info", rb_perfetto_trace_event_instant_with_debug_info, 4);
91
133
  rb_define_module_function(rb_mPerfetto, "trace_event_begin_with_debug_info", rb_perfetto_trace_event_begin_with_debug_info, 4);
92
- }
134
+
135
+ rb_define_module_function(rb_mPerfetto, "fiber_trace_event_begin", rb_perfetto_fiber_trace_event_begin, 2);
136
+ rb_define_module_function(rb_mPerfetto, "fiber_trace_event_end", rb_perfetto_fiber_trace_event_end, 1);
137
+ rb_define_module_function(rb_mPerfetto, "fiber_trace_event_instant", rb_perfetto_fiber_trace_event_instant, 2);
138
+ rb_define_module_function(rb_mPerfetto, "fiber_trace_event_instant_with_debug_info", rb_perfetto_fiber_trace_event_instant_with_debug_info, 4);
139
+ rb_define_module_function(rb_mPerfetto, "fiber_trace_event_begin_with_debug_info", rb_perfetto_fiber_trace_event_begin_with_debug_info, 4);
140
+ }
@@ -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/ext/perfetto/sdk.cc CHANGED
File without changes
data/ext/perfetto/sdk.h CHANGED
File without changes
@@ -6,6 +6,7 @@ module Perfetto
6
6
  extend Configurable
7
7
 
8
8
  set :enable_tracing, false
9
+ set :enable_fiber, false
9
10
  set :buffer_size_kb, 1024
10
11
  end
11
12
  end
File without changes
File without changes
File without changes
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Perfetto
4
- VERSION = "0.1.14"
4
+ VERSION = "0.1.16"
5
5
  end
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
data/sig/perfetto.rbs CHANGED
File without changes
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perfetto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kowalski Dark
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-01-10 00:00:00.000000000 Z
10
+ date: 2025-07-10 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Yet another event tracing library for Ruby.
14
13
  email:
@@ -44,7 +43,6 @@ licenses: []
44
43
  metadata:
45
44
  homepage_uri: https://github.com/yet-another-ai/perfetto.rb
46
45
  rubygems_mfa_required: 'true'
47
- post_install_message:
48
46
  rdoc_options: []
49
47
  require_paths:
50
48
  - lib
@@ -60,8 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
58
  - !ruby/object:Gem::Version
61
59
  version: '0'
62
60
  requirements: []
63
- rubygems_version: 3.5.3
64
- signing_key:
61
+ rubygems_version: 3.6.2
65
62
  specification_version: 4
66
63
  summary: Yet another event tracing library for Ruby.
67
64
  test_files: []