perfetto 0.1.15-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +18 -0
- data/README.md +109 -0
- data/Rakefile +18 -0
- data/example/example.png +0 -0
- data/example/example.rb +88 -0
- data/ext/perfetto/LICENSE +189 -0
- data/ext/perfetto/README.md +11 -0
- data/ext/perfetto/extconf.rb +11 -0
- data/ext/perfetto/perfetto.c +139 -0
- data/ext/perfetto/perfetto_internal.cc +200 -0
- data/ext/perfetto/perfetto_internal.h +48 -0
- data/ext/perfetto/sdk.cc +62532 -0
- data/ext/perfetto/sdk.h +154360 -0
- data/lib/perfetto/configure.rb +12 -0
- data/lib/perfetto/core_ext/configurable.rb +45 -0
- data/lib/perfetto/interceptor.rb +115 -0
- data/lib/perfetto/middleware.rb +37 -0
- data/lib/perfetto/perfetto.rb +49 -0
- data/lib/perfetto/perfetto_native.so +0 -0
- data/lib/perfetto/version.rb +5 -0
- data/lib/perfetto.rb +30 -0
- data/perfetto.gemspec +34 -0
- data/sig/perfetto.rbs +4 -0
- metadata +71 -0
@@ -0,0 +1,200 @@
|
|
1
|
+
#include "sdk.h"
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <atomic>
|
5
|
+
#include <mutex>
|
6
|
+
#include <fstream>
|
7
|
+
#include <sstream>
|
8
|
+
#include <vector>
|
9
|
+
#include <string>
|
10
|
+
#include <thread>
|
11
|
+
|
12
|
+
#include "perfetto_internal.h"
|
13
|
+
|
14
|
+
PERFETTO_DEFINE_CATEGORIES();
|
15
|
+
PERFETTO_TRACK_EVENT_STATIC_STORAGE();
|
16
|
+
|
17
|
+
static struct GlobalState
|
18
|
+
{
|
19
|
+
std::unique_ptr<perfetto::TracingSession> tracing_session;
|
20
|
+
bool is_initialized;
|
21
|
+
bool is_tracing;
|
22
|
+
std::mutex mutex;
|
23
|
+
|
24
|
+
GlobalState() : tracing_session(nullptr), is_initialized(false), mutex()
|
25
|
+
{
|
26
|
+
}
|
27
|
+
} global_state;
|
28
|
+
|
29
|
+
extern "C"
|
30
|
+
{
|
31
|
+
|
32
|
+
static inline void perfetto_initialize()
|
33
|
+
{
|
34
|
+
perfetto::TracingInitArgs args;
|
35
|
+
args.backends = perfetto::kInProcessBackend;
|
36
|
+
perfetto::Tracing::Initialize(args);
|
37
|
+
perfetto::TrackEvent::Register();
|
38
|
+
global_state.is_initialized = true;
|
39
|
+
}
|
40
|
+
|
41
|
+
bool perfetto_start_tracing(const uint32_t buffer_size_kb)
|
42
|
+
{
|
43
|
+
std::lock_guard<std::mutex> lock(global_state.mutex);
|
44
|
+
|
45
|
+
if (global_state.is_tracing)
|
46
|
+
{
|
47
|
+
return false;
|
48
|
+
}
|
49
|
+
|
50
|
+
if (!global_state.is_initialized)
|
51
|
+
{
|
52
|
+
perfetto_initialize();
|
53
|
+
}
|
54
|
+
|
55
|
+
if (buffer_size_kb == 0)
|
56
|
+
{
|
57
|
+
return false;
|
58
|
+
}
|
59
|
+
|
60
|
+
perfetto::TraceConfig trace_config;
|
61
|
+
trace_config.add_buffers()->set_size_kb(buffer_size_kb);
|
62
|
+
auto *ds_config = trace_config.add_data_sources()->mutable_config();
|
63
|
+
ds_config->set_name("track_event");
|
64
|
+
|
65
|
+
auto tracing_session = perfetto::Tracing::NewTrace();
|
66
|
+
tracing_session->Setup(trace_config);
|
67
|
+
tracing_session->StartBlocking();
|
68
|
+
|
69
|
+
global_state.tracing_session = std::move(tracing_session);
|
70
|
+
global_state.is_tracing = true;
|
71
|
+
return true;
|
72
|
+
}
|
73
|
+
|
74
|
+
bool perfetto_stop_tracing(const char *const output_file)
|
75
|
+
{
|
76
|
+
std::lock_guard<std::mutex> lock(global_state.mutex);
|
77
|
+
if (!global_state.is_initialized || !global_state.is_tracing)
|
78
|
+
{
|
79
|
+
return false;
|
80
|
+
}
|
81
|
+
|
82
|
+
perfetto::TrackEvent::Flush();
|
83
|
+
global_state.tracing_session->StopBlocking();
|
84
|
+
std::vector<char> trace_data(global_state.tracing_session->ReadTraceBlocking());
|
85
|
+
global_state.tracing_session.reset();
|
86
|
+
global_state.is_tracing = false;
|
87
|
+
|
88
|
+
try
|
89
|
+
{
|
90
|
+
std::ofstream output(output_file, std::ios::out | std::ios::binary);
|
91
|
+
output.write(trace_data.data(), trace_data.size());
|
92
|
+
output.close();
|
93
|
+
}
|
94
|
+
catch (std::exception &e)
|
95
|
+
{
|
96
|
+
return false;
|
97
|
+
}
|
98
|
+
|
99
|
+
return true;
|
100
|
+
}
|
101
|
+
|
102
|
+
void perfetto_trace_event_begin(const char *const category, const char *const name)
|
103
|
+
{
|
104
|
+
perfetto::DynamicCategory dynamic_category(category);
|
105
|
+
perfetto::DynamicString dynamic_name(name);
|
106
|
+
TRACE_EVENT_BEGIN(dynamic_category, dynamic_name);
|
107
|
+
}
|
108
|
+
|
109
|
+
void perfetto_trace_event_end(const char *const category)
|
110
|
+
{
|
111
|
+
perfetto::DynamicCategory dynamic_category(category);
|
112
|
+
TRACE_EVENT_END(dynamic_category);
|
113
|
+
}
|
114
|
+
|
115
|
+
void perfetto_trace_counter_i64(const char *const category, const char *const name, const int64_t value)
|
116
|
+
{
|
117
|
+
perfetto::DynamicCategory dynamic_category(category);
|
118
|
+
perfetto::DynamicString dynamic_name(name);
|
119
|
+
TRACE_COUNTER(dynamic_category, perfetto::CounterTrack(name), value);
|
120
|
+
}
|
121
|
+
|
122
|
+
void perfetto_trace_counter_double(const char *const category, const char *const name, const double value)
|
123
|
+
{
|
124
|
+
perfetto::DynamicCategory dynamic_category(category);
|
125
|
+
TRACE_COUNTER(dynamic_category, perfetto::CounterTrack(name), value);
|
126
|
+
}
|
127
|
+
|
128
|
+
void perfetto_trace_event_instant(const char *const category, const char *const name)
|
129
|
+
{
|
130
|
+
perfetto::DynamicCategory dynamic_category(category);
|
131
|
+
perfetto::DynamicString dynamic_name(name);
|
132
|
+
TRACE_EVENT_INSTANT(dynamic_category, dynamic_name);
|
133
|
+
}
|
134
|
+
|
135
|
+
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)
|
136
|
+
{
|
137
|
+
perfetto::DynamicCategory dynamic_category(category);
|
138
|
+
perfetto::DynamicString dynamic_name(name);
|
139
|
+
TRACE_EVENT_INSTANT(dynamic_category, dynamic_name,
|
140
|
+
debug_info_key, debug_info_value);
|
141
|
+
}
|
142
|
+
|
143
|
+
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)
|
144
|
+
{
|
145
|
+
perfetto::DynamicCategory dynamic_category(category);
|
146
|
+
perfetto::DynamicString dynamic_name(name);
|
147
|
+
TRACE_EVENT_BEGIN(dynamic_category, dynamic_name,
|
148
|
+
debug_info_key, debug_info_value);
|
149
|
+
}
|
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
|
+
|
200
|
+
} // extern "C"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#ifndef _RUBY_PERFETTO_INTERNAL_H_
|
2
|
+
#define _RUBY_PERFETTO_INTERNAL_H_
|
3
|
+
|
4
|
+
#ifdef __cplusplus
|
5
|
+
extern "C"
|
6
|
+
{
|
7
|
+
#endif
|
8
|
+
|
9
|
+
#include <stdint.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <stdlib.h>
|
12
|
+
|
13
|
+
/* C Interface */
|
14
|
+
|
15
|
+
bool perfetto_start_tracing(const uint32_t buffer_size_kb);
|
16
|
+
|
17
|
+
bool perfetto_stop_tracing(const char *const output_file);
|
18
|
+
|
19
|
+
void perfetto_trace_event_begin(const char *const category, const char *const name);
|
20
|
+
|
21
|
+
void perfetto_trace_event_end(const char *const category);
|
22
|
+
|
23
|
+
void perfetto_trace_counter_i64(const char *const category, const char *const name, const int64_t value);
|
24
|
+
|
25
|
+
void perfetto_trace_counter_double(const char *const category, const char *const name, const double value);
|
26
|
+
|
27
|
+
void perfetto_trace_event_instant(const char *const category, const char *const name);
|
28
|
+
|
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
|
+
|
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
|
+
|
44
|
+
#ifdef __cplusplus
|
45
|
+
}
|
46
|
+
#endif
|
47
|
+
|
48
|
+
#endif // _RUBY_PERFETTO_INTERNAL_H_
|