Skip to content

Commit 3da74f0

Browse files
hoxyqfacebook-github-bot
authored andcommitted
Add method for collecting all events in a single container (#52734)
Summary: Pull Request resolved: #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
1 parent bbc0c0b commit 3da74f0

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,36 @@ void PerformanceTracer::collectEvents(
111111
}
112112
}
113113

114+
folly::dynamic PerformanceTracer::collectEvents(uint16_t chunkSize) {
115+
std::vector<TraceEvent> localBuffer;
116+
{
117+
std::lock_guard lock(mutex_);
118+
buffer_.swap(localBuffer);
119+
}
120+
121+
auto chunks = folly::dynamic::array();
122+
if (localBuffer.empty()) {
123+
return chunks;
124+
}
125+
126+
auto chunk = folly::dynamic::array();
127+
chunk.reserve(chunkSize);
128+
for (auto&& event : localBuffer) {
129+
chunk.push_back(serializeTraceEvent(std::move(event)));
130+
131+
if (chunk.size() == chunkSize) {
132+
chunks.push_back(std::move(chunk));
133+
chunk = folly::dynamic::array();
134+
chunk.reserve(chunkSize);
135+
}
136+
}
137+
138+
if (!chunk.empty()) {
139+
chunks.push_back(std::move(chunk));
140+
}
141+
return chunks;
142+
}
143+
114144
void PerformanceTracer::reportMark(
115145
const std::string_view& name,
116146
HighResTimeStamp start,

packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ class PerformanceTracer {
6060
resultCallback,
6161
uint16_t chunkSize);
6262

63+
/**
64+
* Flush out buffered CDP Trace Events into a folly::dynamic collection of
65+
* chunks, which can be sent over CDP later.
66+
*/
67+
folly::dynamic collectEvents(uint16_t chunkSize);
68+
6369
/**
6470
* Record a `Performance.mark()` event - a labelled timestamp. If not
6571
* currently tracing, this is a no-op.

0 commit comments

Comments
 (0)