mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Implement native logic for performance event reporting (#35526)
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e2c4941c80
commit
14e69db482
@@ -7,45 +7,53 @@
|
||||
|
||||
#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)) {}
|
||||
: NativePerformanceObserverCxxSpec(std::move(jsInvoker)),
|
||||
reporter_(std::make_unique<PerformanceEntryReporter>()) {}
|
||||
|
||||
NativePerformanceObserver::~NativePerformanceObserver() {}
|
||||
|
||||
void NativePerformanceObserver::startReporting(
|
||||
jsi::Runtime &rt,
|
||||
std::string entryType) {
|
||||
LOG(INFO) << "Started reporting perf entry type: " << entryType;
|
||||
reporter_->startReporting(stringToPerformanceEntryType(entryType));
|
||||
}
|
||||
|
||||
void NativePerformanceObserver::stopReporting(
|
||||
jsi::Runtime &rt,
|
||||
std::string entryType) {
|
||||
LOG(INFO) << "Stopped reporting perf entry type: " << entryType;
|
||||
reporter_->stopReporting(stringToPerformanceEntryType(entryType));
|
||||
}
|
||||
|
||||
std::vector<RawPerformanceEntry> NativePerformanceObserver::getPendingEntries(
|
||||
jsi::Runtime &rt) {
|
||||
return std::vector<RawPerformanceEntry>{};
|
||||
return reporter_->popPendingEntries();
|
||||
}
|
||||
|
||||
void NativePerformanceObserver::setOnPerformanceEntryCallback(
|
||||
jsi::Runtime &rt,
|
||||
std::optional<AsyncCallback<>> callback) {
|
||||
callback_ = callback;
|
||||
LOG(INFO) << "setOnPerformanceEntryCallback: "
|
||||
<< (callback ? "non-empty" : "empty");
|
||||
reporter_->setReportingCallback(callback);
|
||||
}
|
||||
|
||||
void NativePerformanceObserver::logEntryForDebug(
|
||||
jsi::Runtime &rt,
|
||||
RawPerformanceEntry entry) {
|
||||
LOG(INFO) << "NativePerformanceObserver::logEntry: "
|
||||
<< "name=" << entry.name << " type=" << entry.entryType
|
||||
<< " startTime=" << entry.startTime
|
||||
<< " duration=" << entry.duration;
|
||||
reporter_->logEntry(entry);
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
Reference in New Issue
Block a user