Skip to content

Commit 8492a89

Browse files
andrewdacenkofacebook-github-bot
authored andcommitted
Add support for perfetto on Windows tracing
Summary: Changelog: [Internal] Differential Revision: D80471173
1 parent 25104de commit 8492a89

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/react-native/ReactCommon/cxxreact/TraceSection.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@
1212
#endif
1313

1414
#ifdef WITH_PERFETTO
15+
16+
// clang-format off
17+
// Windows.h macro fail, 'interface' clashes with a function in perfetto.h
18+
#ifdef interface
19+
#pragma push_macro("interface")
20+
#undef interface
21+
#define __RCT_INTERFACE_PUSHED
22+
#endif
23+
1524
#include <perfetto.h>
25+
26+
#ifdef __RCT_INTERFACE_PUSHED
27+
#undef __RCT_INTERFACE_PUSHED
28+
#pragma pop_macro("interface")
29+
#endif
30+
// clang-format on
31+
1632
#include <reactperflogger/ReactPerfettoCategories.h>
1733
#endif
1834

packages/react-native/ReactCommon/reactperflogger/reactperflogger/FuseboxPerfettoDataSource.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
#ifdef WITH_PERFETTO
99

10+
#if defined(__ANDROID__)
1011
#include <android/log.h>
12+
#endif // __ANDROID__
1113
#include <folly/json.h>
1214
#include <hermes/hermes.h>
1315
#include <perfetto.h>
@@ -27,6 +29,7 @@ const int SAMPLING_HZ = 1000;
2729

2830
using perfetto::TrackEvent;
2931

32+
#if defined(__ANDROID__)
3033
std::string getApplicationId() {
3134
pid_t pid = getpid();
3235
char path[64] = {0};
@@ -40,6 +43,7 @@ std::string getApplicationId() {
4043
}
4144
return "";
4245
}
46+
#endif // __ANDROID__
4347

4448
uint64_t hermesToPerfettoTime(int64_t hermesTs) {
4549
return (hermesTs / 1000);
@@ -130,13 +134,15 @@ void FuseboxPerfettoDataSource::OnStop(const StopArgs& a) {
130134
std::string trace = stream.str();
131135
logHermesProfileToFusebox(trace);
132136

137+
#if defined(__ANDROID__)
133138
// XXX: Adjust the package ID. Writing to other global tmp directories
134139
// seems to fail.
135140
std::string appId = getApplicationId();
136141
__android_log_print(
137142
ANDROID_LOG_INFO, "FuseboxTracer", "Application ID: %s", appId.c_str());
138143
FuseboxTracer::getFuseboxTracer().stopTracingAndWriteToFile(
139144
"/data/data/" + appId + "/cache/hermes_trace.json");
145+
#endif // __ANDROID__
140146
}
141147

142148
} // namespace facebook::react

0 commit comments

Comments
 (0)