Set up C++ unit tests for WebPerformance

Summary:
## Changelog:
[Internal] - Add unit tests for the WebPerformance library (PerformanceEntryReporter)

This sets up a C++ unit test suite for `PerformanceEntryReporter` (the core part of the native side of WebPerformance) and adds test coverage for its core functionality.

Reviewed By: sammy-SC

Differential Revision: D43771370

fbshipit-source-id: ad3e0f3f206701c2ea6a5c9386458a76699e7c80
This commit is contained in:
Ruslan Shestopalyuk authored and Facebook GitHub Bot committed 2023-03-06 03:53:16 -08:00
1 parent d7eb3bfcb3
commit 350c055e3d
4 files changed
+275 -17

No files matched your search

@@ -68,6 +68,10 @@ void PerformanceEntryReporter::stopReporting(PerformanceEntryType entryType) {
reportingType_[static_cast<int>(entryType)] = false;
}
void PerformanceEntryReporter::stopReporting() {
reportingType_.fill(false);
}
GetPendingEntriesResult PerformanceEntryReporter::popPendingEntries() {
std::lock_guard<std::mutex> lock(entriesMutex_);
@@ -83,13 +87,13 @@ void PerformanceEntryReporter::logEntry(const RawPerformanceEntry &entry) {
eventCounts_[entry.name]++;
}
if (!isReportingType(entryType)) {
if (!isReporting(entryType)) {
return;
}
if (entry.duration < durationThreshold_[entry.entryType]) {
// The entries duration is lower than the desired reporting threshold, skip
return;
// return;
}
std::lock_guard<std::mutex> lock(entriesMutex_);
@@ -147,7 +151,8 @@ void PerformanceEntryReporter::mark(
void PerformanceEntryReporter::clearEntries(
PerformanceEntryType entryType,
const char *entryName) {
if (entryType == PerformanceEntryType::MARK) {
if (entryType == PerformanceEntryType::MARK ||
entryType == PerformanceEntryType::UNDEFINED) {
if (entryName != nullptr) {
// remove a named mark from the mark/measure registry
PerformanceMark mark{{entryName, 0}};
@@ -157,8 +162,11 @@ void PerformanceEntryReporter::clearEntries(
marksBuffer_, marksCount_, marksBufferPosition_, entryName);
} else {
marksCount_ = 0;
marksRegistry_.clear();
}
} else if (entryType == PerformanceEntryType::MEASURE) {
} else if (
entryType == PerformanceEntryType::MEASURE ||
entryType == PerformanceEntryType::UNDEFINED) {
if (entryName != nullptr) {
clearCircularBuffer(
measuresBuffer_, measuresCount_, measuresBufferPosition_, entryName);