Skip to content

Commit 5745cc2

Browse files
committed
src: add perfetto trace agent
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
1 parent 08fcff7 commit 5745cc2

13 files changed

Lines changed: 758 additions & 6 deletions

node.gyp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@
455455
'src/node_crypto.h',
456456
],
457457
'node_tracing_perfetto_sources': [
458+
'src/tracing/agent_perfetto.cc',
459+
'src/tracing/agent_perfetto.h',
460+
'src/tracing/trace_event_perfetto.cc',
461+
'src/tracing/trace_event_perfetto.h',
458462
],
459463
'node_tracing_legacy_sources': [
460464
'src/tracing/agent_legacy.cc',

src/inspector/node_inspector.gypi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
'src/inspector/protocol_helper.h',
2525
'src/inspector/runtime_agent.cc',
2626
'src/inspector/runtime_agent.h',
27-
'src/inspector/tracing_agent.cc',
28-
'src/inspector/tracing_agent.h',
2927
'src/inspector/worker_agent.cc',
3028
'src/inspector/worker_agent.h',
3129
'src/inspector/network_inspector.cc',
@@ -185,4 +183,12 @@
185183
],
186184
},
187185
],
186+
'conditions': [
187+
['v8_use_perfetto!=1', {
188+
'sources': [
189+
'src/inspector/tracing_agent.cc',
190+
'src/inspector/tracing_agent.h',
191+
]
192+
}],
193+
],
188194
}

src/node_options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,11 @@ class PerProcessOptions : public Options {
334334

335335
std::string title;
336336
std::string trace_event_categories;
337+
#if defined(V8_USE_PERFETTO)
338+
std::string trace_event_file_pattern = "node_trace.${rotation}.pftrace";
339+
#else
337340
std::string trace_event_file_pattern = "node_trace.${rotation}.log";
341+
#endif
338342
int64_t v8_thread_pool_size = 4;
339343
bool zero_fill_all_buffers = false;
340344
bool debug_arraybuffer_allocations = false;

src/tracing/agent.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#include "tracing/agent.h"
2+
3+
#ifdef V8_USE_PERFETTO
4+
#include "tracing/agent_perfetto.h"
5+
#else
26
#include "tracing/agent_legacy.h"
3-
#include "tracing/trace_event.h"
7+
#endif
8+
9+
#include "tracing/trace_event_helper.h"
410

511
namespace node {
612
namespace tracing {
@@ -23,7 +29,11 @@ void Agent::Deleter::operator()(Agent* agent) {
2329
std::unique_ptr<Agent, Agent::Deleter> Agent::CreateDefault() {
2430
CHECK_NULL(g_agent);
2531

32+
#ifdef V8_USE_PERFETTO
33+
auto agent = new PerfettoTracingAgent();
34+
#else
2635
auto agent = new LegacyTracingAgent();
36+
#endif
2737

2838
g_agent = agent;
2939
TraceEventHelper::SetTracingController(agent->GetTracingController());

src/tracing/agent.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class Agent {
4343
virtual AgentWriterHandle* GetDefaultWriterHandle() = 0;
4444

4545
virtual void AddTraceStateObserver(
46-
v8::TracingController::TraceStateObserver* observer) = 0;
46+
v8::TracingController::TraceStateObserver* observer) {}
4747
virtual void RemoveTraceStateObserver(
48-
v8::TracingController::TraceStateObserver* observer) = 0;
48+
v8::TracingController::TraceStateObserver* observer) {}
4949

5050
struct Deleter {
5151
void operator()(Agent* agent);
@@ -88,6 +88,7 @@ class AgentWriterHandle {
8888

8989
friend class Agent;
9090
friend class LegacyTracingAgent;
91+
friend class PerfettoTracingAgent;
9192
};
9293

9394
void AgentWriterHandle::reset() {

0 commit comments

Comments
 (0)