Add method for collecting all events in a single container (#52734)

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

# Changelog: [Internal]

We are going to need it at the top of the stack, once we will capture the Trace Events as part of the Tracing Profile for the whole Host.

This is also would be used for always-on tracing.

Reviewed By: sbuggay

Differential Revision: D78660071

fbshipit-source-id: 4f876bed992b8a794e561940ad12405fef88cb62
This commit is contained in:
Ruslan Lesiutin authored and Facebook GitHub Bot committed 2025-07-22 04:34:50 -07:00
1 parent bbc0c0b6ef
commit 3da74f0799
2 files changed
+36

No files matched your search

@@ -111,6 +111,36 @@ void PerformanceTracer::collectEvents(
}
}
folly::dynamic PerformanceTracer::collectEvents(uint16_t chunkSize) {
std::vector<TraceEvent> localBuffer;
{
std::lock_guard lock(mutex_);
buffer_.swap(localBuffer);
}
auto chunks = folly::dynamic::array();
if (localBuffer.empty()) {
return chunks;
}
auto chunk = folly::dynamic::array();
chunk.reserve(chunkSize);
for (auto&& event : localBuffer) {
chunk.push_back(serializeTraceEvent(std::move(event)));
if (chunk.size() == chunkSize) {
chunks.push_back(std::move(chunk));
chunk = folly::dynamic::array();
chunk.reserve(chunkSize);
}
}
if (!chunk.empty()) {
chunks.push_back(std::move(chunk));
}
return chunks;
}
void PerformanceTracer::reportMark(
const std::string_view& name,
HighResTimeStamp start,
@@ -60,6 +60,12 @@ class PerformanceTracer {
resultCallback,
uint16_t chunkSize);
/**
* Flush out buffered CDP Trace Events into a folly::dynamic collection of
* chunks, which can be sent over CDP later.
*/
folly::dynamic collectEvents(uint16_t chunkSize);
/**
* Record a `Performance.mark()` event - a labelled timestamp. If not
* currently tracing, this is a no-op.