Skip to content

Commit 0b3face

Browse files
hoxyqfacebook-github-bot
authored andcommitted
PerformanceEntryReporter::getMarkTime to return optional DOMHighResTimeStamp (facebook#51389)
Summary: Pull Request resolved: facebook#51389 # Changelog: [Internal] This is the pre-requisite for the diff on top, which migrates performance-related classes to start using `HighResTimeStamp`. Differential Revision: D74837812
1 parent 3fafd8e commit 0b3face

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryReporter.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,32 @@ PerformanceMeasure PerformanceEntryReporter::reportMeasure(
204204
const std::optional<std::string>& endMark,
205205
const std::optional<jsinspector_modern::DevToolsTrackEntryPayload>&
206206
trackMetadata) {
207-
DOMHighResTimeStamp startTimeVal =
208-
startMark ? getMarkTime(*startMark) : startTime;
209-
DOMHighResTimeStamp endTimeVal = endMark ? getMarkTime(*endMark) : endTime;
207+
DOMHighResTimeStamp startTimeValue = startTime;
208+
if (startMark) {
209+
if (auto startMarkBufferedTime = getMarkTime(*startMark)) {
210+
startTimeValue = *startMarkBufferedTime;
211+
}
212+
}
213+
214+
DOMHighResTimeStamp endTimeValue = endTime;
215+
if (endMark) {
216+
if (auto endMarkBufferedTime = getMarkTime(*endMark)) {
217+
endTimeValue = *endMarkBufferedTime;
218+
}
219+
}
210220

211-
if (!endMark && endTime < startTimeVal) {
221+
if (!endMark && endTime < startTimeValue) {
212222
// The end time is not specified, take the current time, according to the
213223
// standard
214-
endTimeVal = getCurrentTimeStamp();
224+
endTimeValue = getCurrentTimeStamp();
215225
}
216226

217227
DOMHighResTimeStamp durationVal =
218-
duration ? *duration : endTimeVal - startTimeVal;
228+
duration ? *duration : endTimeValue - startTimeValue;
219229

220230
const auto entry = PerformanceMeasure{
221231
{.name = std::string(name),
222-
.startTime = startTimeVal,
232+
.startTime = startTimeValue,
223233
.duration = durationVal}};
224234

225235
traceMeasure(entry);
@@ -235,16 +245,16 @@ PerformanceMeasure PerformanceEntryReporter::reportMeasure(
235245
return entry;
236246
}
237247

238-
DOMHighResTimeStamp PerformanceEntryReporter::getMarkTime(
248+
std::optional<DOMHighResTimeStamp> PerformanceEntryReporter::getMarkTime(
239249
const std::string& markName) const {
240250
std::shared_lock lock(buffersMutex_);
241251

242252
if (auto it = markBuffer_.find(markName); it) {
243253
return std::visit(
244254
[](const auto& entryData) { return entryData.startTime; }, *it);
245-
} else {
246-
return 0.0;
247255
}
256+
257+
return std::nullopt;
248258
}
249259

250260
void PerformanceEntryReporter::reportEvent(

packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryReporter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class PerformanceEntryReporter {
129129

130130
std::function<double()> timeStampProvider_ = nullptr;
131131

132-
double getMarkTime(const std::string& markName) const;
132+
std::optional<double> getMarkTime(const std::string& markName) const;
133133

134134
const inline PerformanceEntryBuffer& getBuffer(
135135
PerformanceEntryType entryType) const {

0 commit comments

Comments
 (0)