Add support for perfetto on Windows tracing (#53340)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/53340

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D80471173

fbshipit-source-id: 54f24c9c6868dae2042d324c8aed87726ede05a8
This commit is contained in:
Andrew Datsenko
2025-08-19 05:38:12 -07:00
committed by Facebook GitHub Bot
parent 8197399e43
commit e7d89fa53a
2 changed files with 22 additions and 0 deletions
@@ -12,7 +12,23 @@
#endif
#ifdef WITH_PERFETTO
// clang-format off
// Windows.h macro fail, 'interface' clashes with a function in perfetto.h
#ifdef interface
#pragma push_macro("interface")
#undef interface
#define __RCT_INTERFACE_PUSHED
#endif
#include <perfetto.h>
#ifdef __RCT_INTERFACE_PUSHED
#undef __RCT_INTERFACE_PUSHED
#pragma pop_macro("interface")
#endif
// clang-format on
#include <reactperflogger/ReactPerfettoCategories.h>
#endif
@@ -7,7 +7,9 @@
#ifdef WITH_PERFETTO
#if defined(__ANDROID__)
#include <android/log.h>
#endif // __ANDROID__
#include <folly/json.h>
#include <hermes/hermes.h>
#include <perfetto.h>
@@ -27,6 +29,7 @@ const int SAMPLING_HZ = 1000;
using perfetto::TrackEvent;
#if defined(__ANDROID__)
std::string getApplicationId() {
pid_t pid = getpid();
char path[64] = {0};
@@ -40,6 +43,7 @@ std::string getApplicationId() {
}
return "";
}
#endif // __ANDROID__
uint64_t hermesToPerfettoTime(int64_t hermesTs) {
return (hermesTs / 1000);
@@ -130,6 +134,7 @@ void FuseboxPerfettoDataSource::OnStop(const StopArgs& a) {
std::string trace = stream.str();
logHermesProfileToFusebox(trace);
#if defined(__ANDROID__)
// XXX: Adjust the package ID. Writing to other global tmp directories
// seems to fail.
std::string appId = getApplicationId();
@@ -137,6 +142,7 @@ void FuseboxPerfettoDataSource::OnStop(const StopArgs& a) {
ANDROID_LOG_INFO, "FuseboxTracer", "Application ID: %s", appId.c_str());
FuseboxTracer::getFuseboxTracer().stopTracingAndWriteToFile(
"/data/data/" + appId + "/cache/hermes_trace.json");
#endif // __ANDROID__
}
} // namespace facebook::react