mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
14e69db482
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35526 [Changelog][Internal] This closes the full loop according to the [technical design](https://fb.quip.com/MdqgAk1Eb2dV) of the WebPerf API implementation, with the main components and the working central data flow in place. The next step is to add some buffering/throttling, as in this diff we just spawn an idle-priority task after every performance entry coming (even though they still naturally do come in batches, because they manage to accumulate before the task is executed). Reviewed By: christophpurrer Differential Revision: D41496082 fbshipit-source-id: 5fd4cf22e75806f7bc98d1d1b6691596ccadf8b9
53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "PerformanceEntryReporter.h"
|
|
#include <glog/logging.h>
|
|
#include <react/renderer/runtimescheduler/RuntimeScheduler.h>
|
|
#include "NativePerformanceObserver.h"
|
|
|
|
namespace facebook::react {
|
|
void PerformanceEntryReporter::setReportingCallback(
|
|
std::optional<AsyncCallback<>> callback) {
|
|
callback_ = callback;
|
|
}
|
|
|
|
void PerformanceEntryReporter::startReporting(PerformanceEntryType entryType) {
|
|
reportingType_[static_cast<int>(entryType)] = true;
|
|
}
|
|
void PerformanceEntryReporter::stopReporting(PerformanceEntryType entryType) {
|
|
reportingType_[static_cast<int>(entryType)] = false;
|
|
}
|
|
|
|
std::vector<RawPerformanceEntry> PerformanceEntryReporter::getPendingEntries()
|
|
const {
|
|
return entries_;
|
|
}
|
|
|
|
std::vector<RawPerformanceEntry> PerformanceEntryReporter::popPendingEntries() {
|
|
auto entriesToReturn = std::move(entries_);
|
|
entries_ = {};
|
|
return entriesToReturn;
|
|
}
|
|
|
|
void PerformanceEntryReporter::clearPendingEntries() {
|
|
entries_.clear();
|
|
}
|
|
|
|
void PerformanceEntryReporter::logEntry(const RawPerformanceEntry &entry) {
|
|
if (!isReportingType(static_cast<PerformanceEntryType>(entry.entryType))) {
|
|
return;
|
|
}
|
|
|
|
entries_.emplace_back(entry);
|
|
|
|
// TODO: Add buffering/throttling - but for testing this works as well, for
|
|
// now
|
|
callback_->callWithPriority(SchedulerPriority::IdlePriority);
|
|
}
|
|
} // namespace facebook::react
|