mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use C++20 designated initializers in PerformanceEntryReporter (#43702)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43702 Changelog: [internal] Just a minor refactor to use C++20 designated initializers in `PerformanceEntryReporter` and its tests, while removing unnecessary initialization for optional fields. Reviewed By: rshest Differential Revision: D55477745 fbshipit-source-id: a643adf7ae48df23c5c383420fd4c4dd550e1322
This commit is contained in:
committed by
Facebook GitHub Bot
parent
20598949c8
commit
9284fcb97f
+16
-28
@@ -155,13 +155,9 @@ void PerformanceEntryReporter::mark(
|
||||
const std::string& name,
|
||||
const std::optional<double>& startTime) {
|
||||
logEntry(RawPerformanceEntry{
|
||||
name,
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
startTime ? *startTime : getCurrentTimeStamp(),
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt});
|
||||
.name = name,
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK),
|
||||
.startTime = startTime ? *startTime : getCurrentTimeStamp()});
|
||||
}
|
||||
|
||||
void PerformanceEntryReporter::clearEntries(
|
||||
@@ -257,25 +253,17 @@ void PerformanceEntryReporter::measure(
|
||||
double durationVal = duration ? *duration : endTimeVal - startTimeVal;
|
||||
|
||||
logEntry(
|
||||
{name,
|
||||
static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
startTimeVal,
|
||||
durationVal,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt});
|
||||
{.name = name,
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
.startTime = startTimeVal,
|
||||
.duration = durationVal});
|
||||
}
|
||||
|
||||
double PerformanceEntryReporter::getMarkTime(
|
||||
const std::string& markName) const {
|
||||
RawPerformanceEntry mark{
|
||||
markName,
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
0.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt};
|
||||
.name = markName,
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK)};
|
||||
|
||||
std::lock_guard lock(nameLookupMutex_);
|
||||
const auto& marksBuffer = getBuffer(PerformanceEntryType::MARK);
|
||||
@@ -295,13 +283,13 @@ void PerformanceEntryReporter::logEventEntry(
|
||||
double processingEnd,
|
||||
uint32_t interactionId) {
|
||||
logEntry(
|
||||
{std::move(name),
|
||||
static_cast<int>(PerformanceEntryType::EVENT),
|
||||
startTime,
|
||||
duration,
|
||||
processingStart,
|
||||
processingEnd,
|
||||
interactionId});
|
||||
{.name = std::move(name),
|
||||
.entryType = static_cast<int>(PerformanceEntryType::EVENT),
|
||||
.startTime = startTime,
|
||||
.duration = duration,
|
||||
.processingStart = processingStart,
|
||||
.processingEnd = processingEnd,
|
||||
.interactionId = interactionId});
|
||||
}
|
||||
|
||||
void PerformanceEntryReporter::scheduleFlushBuffer() {
|
||||
|
||||
+62
-126
@@ -104,34 +104,18 @@ TEST(PerformanceEntryReporter, PerformanceEntryReporterTestReportMarks) {
|
||||
ASSERT_EQ(4, entries.size());
|
||||
|
||||
const std::vector<RawPerformanceEntry> expected = {
|
||||
{"mark0",
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
0.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"mark1",
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
1.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"mark2",
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
2.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"mark0",
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
3.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{.name = "mark0",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK),
|
||||
.startTime = 0.0},
|
||||
{.name = "mark1",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK),
|
||||
.startTime = 1.0},
|
||||
{.name = "mark2",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK),
|
||||
.startTime = 2.0},
|
||||
{.name = "mark0",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK),
|
||||
.startTime = 3.0},
|
||||
};
|
||||
|
||||
ASSERT_EQ(expected, entries);
|
||||
@@ -172,104 +156,56 @@ TEST(PerformanceEntryReporter, PerformanceEntryReporterTestReportMeasures) {
|
||||
ASSERT_EQ(0, res.droppedEntriesCount);
|
||||
|
||||
const std::vector<RawPerformanceEntry> expected = {
|
||||
{"mark0",
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
0.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"measure0",
|
||||
static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
0.0,
|
||||
2.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"measure1",
|
||||
static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
0.0,
|
||||
4.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"mark1",
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
1.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"measure2",
|
||||
static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
1.0,
|
||||
1.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"measure7",
|
||||
static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
1.0,
|
||||
2.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"measure3",
|
||||
static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
1.0,
|
||||
5.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"measure4",
|
||||
static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
1.5,
|
||||
0.5,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"mark2",
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
2.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"mark3",
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
2.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"mark4",
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
2.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"measure6",
|
||||
static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
2.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"measure5",
|
||||
static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
2.0,
|
||||
1.5,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt},
|
||||
{"mark4",
|
||||
static_cast<int>(PerformanceEntryType::MARK),
|
||||
3.0,
|
||||
0.0,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt}};
|
||||
{.name = "mark0",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK),
|
||||
.startTime = 0.0},
|
||||
{.name = "measure0",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
.startTime = 0.0,
|
||||
.duration = 2.0},
|
||||
{.name = "measure1",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
.startTime = 0.0,
|
||||
.duration = 4.0},
|
||||
{.name = "mark1",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK),
|
||||
.startTime = 1.0},
|
||||
{.name = "measure2",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
.startTime = 1.0,
|
||||
.duration = 1.0},
|
||||
{.name = "measure7",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
.startTime = 1.0,
|
||||
.duration = 2.0},
|
||||
{.name = "measure3",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
.startTime = 1.0,
|
||||
.duration = 5.0},
|
||||
{.name = "measure4",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
.startTime = 1.5,
|
||||
.duration = 0.5},
|
||||
{.name = "mark2",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK),
|
||||
.startTime = 2.0},
|
||||
{.name = "mark3",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK),
|
||||
.startTime = 2.0},
|
||||
{.name = "mark4",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK),
|
||||
.startTime = 2.0},
|
||||
{.name = "measure6",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
.startTime = 2.0,
|
||||
.duration = 0.0},
|
||||
{.name = "measure5",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MEASURE),
|
||||
.startTime = 2.0,
|
||||
.duration = 1.5},
|
||||
{.name = "mark4",
|
||||
.entryType = static_cast<int>(PerformanceEntryType::MARK),
|
||||
.startTime = 3.0}};
|
||||
|
||||
ASSERT_EQ(expected, entries);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user