Expose API for registering processes and threads (#49083)

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

# Changelog: [Internal]

> NOTE: Some CI jobs are expected to fail, because changes in Hermes D67353585 should be landed first, and then grafted to Static Hermes.

Added 2 new public methods to `PerformanceTracer` instance for registering metadata Trace Events for processes and threads.

Reviewed By: huntie

Differential Revision: D68439733

fbshipit-source-id: dd9f0e72e2414b8c665c57a542cbbfe7df34a516
This commit is contained in:
Ruslan Lesiutin
2025-02-17 09:34:33 -08:00
committed by Facebook GitHub Bot
parent 71f0b4d5a0
commit acebebfd21
2 changed files with 45 additions and 0 deletions
@@ -151,6 +151,40 @@ void PerformanceTracer::reportMeasure(
});
}
void PerformanceTracer::reportProcess(uint64_t id, const std::string& name) {
std::lock_guard<std::mutex> lock(mutex_);
if (!tracing_) {
return;
}
buffer_.push_back(TraceEvent{
.name = "process_name",
.cat = "__metadata",
.ph = 'M',
.ts = 0,
.pid = id,
.tid = 0,
.args = folly::dynamic::object("name", name),
});
}
void PerformanceTracer::reportThread(uint64_t id, const std::string& name) {
std::lock_guard<std::mutex> lock(mutex_);
if (!tracing_) {
return;
}
buffer_.push_back(TraceEvent{
.name = "thread_name",
.cat = "__metadata",
.ph = 'M',
.ts = 0,
.pid = processId_,
.tid = id,
.args = folly::dynamic::object("name", name),
});
}
folly::dynamic PerformanceTracer::serializeTraceEvent(TraceEvent event) const {
folly::dynamic result = folly::dynamic::object;
@@ -13,6 +13,7 @@
#include <folly/dynamic.h>
#include <functional>
#include <mutex>
#include <optional>
#include <vector>
@@ -66,6 +67,16 @@ class PerformanceTracer {
uint64_t duration,
const std::optional<DevToolsTrackEntryPayload>& trackMetadata);
/**
* Record a corresponding Trace Event for OS-level process.
*/
void reportProcess(uint64_t id, const std::string& name);
/**
* Record a corresponding Trace Event for OS-level thread.
*/
void reportThread(uint64_t id, const std::string& name);
private:
PerformanceTracer();
PerformanceTracer(const PerformanceTracer&) = delete;