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
60 lines
1.6 KiB
C++
60 lines
1.6 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 "NativePerformanceObserver.h"
|
|
#include <glog/logging.h>
|
|
#include "PerformanceEntryReporter.h"
|
|
|
|
namespace facebook::react {
|
|
|
|
static PerformanceEntryType stringToPerformanceEntryType(
|
|
const std::string &entryType) {
|
|
if (entryType == "mark") {
|
|
return PerformanceEntryType::MARK;
|
|
} else {
|
|
return PerformanceEntryType::UNDEFINED;
|
|
}
|
|
}
|
|
|
|
NativePerformanceObserver::NativePerformanceObserver(
|
|
std::shared_ptr<CallInvoker> jsInvoker)
|
|
: NativePerformanceObserverCxxSpec(std::move(jsInvoker)),
|
|
reporter_(std::make_unique<PerformanceEntryReporter>()) {}
|
|
|
|
NativePerformanceObserver::~NativePerformanceObserver() {}
|
|
|
|
void NativePerformanceObserver::startReporting(
|
|
jsi::Runtime &rt,
|
|
std::string entryType) {
|
|
reporter_->startReporting(stringToPerformanceEntryType(entryType));
|
|
}
|
|
|
|
void NativePerformanceObserver::stopReporting(
|
|
jsi::Runtime &rt,
|
|
std::string entryType) {
|
|
reporter_->stopReporting(stringToPerformanceEntryType(entryType));
|
|
}
|
|
|
|
std::vector<RawPerformanceEntry> NativePerformanceObserver::getPendingEntries(
|
|
jsi::Runtime &rt) {
|
|
return reporter_->popPendingEntries();
|
|
}
|
|
|
|
void NativePerformanceObserver::setOnPerformanceEntryCallback(
|
|
jsi::Runtime &rt,
|
|
std::optional<AsyncCallback<>> callback) {
|
|
reporter_->setReportingCallback(callback);
|
|
}
|
|
|
|
void NativePerformanceObserver::logEntryForDebug(
|
|
jsi::Runtime &rt,
|
|
RawPerformanceEntry entry) {
|
|
reporter_->logEntry(entry);
|
|
}
|
|
|
|
} // namespace facebook::react
|