Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move PerformanceEntryReporter to its own target #43854

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <cxxreact/JSExecutor.h>
#include <cxxreact/ReactMarker.h>
#include <jsi/instrumentation.h>
#include <react/performance/timeline/PerformanceEntryReporter.h>
#include "NativePerformance.h"
#include "PerformanceEntryReporter.h"

#include "Plugins.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@
#include <memory>
#include <string>

#include "NativePerformanceObserver.h"

namespace facebook::react {
class PerformanceEntryReporter;

#pragma mark - Structs

#pragma mark - implementation

class NativePerformance : public NativePerformanceCxxSpec<NativePerformance> {
public:
Expand Down Expand Up @@ -54,8 +47,6 @@ class NativePerformance : public NativePerformanceCxxSpec<NativePerformance> {
// tracking.
std::unordered_map<std::string, double> getReactNativeStartupTiming(
jsi::Runtime& rt);

private:
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <memory>

#include "NativePerformanceObserver.h"
#include "PerformanceEntryReporter.h"

#include <react/performance/timeline/PerformanceEntryReporter.h>
#include <react/renderer/uimanager/UIManagerBinding.h>
#include <react/utils/CoreFeatures.h>

Expand All @@ -36,14 +36,12 @@ NativePerformanceObserver::~NativePerformanceObserver() {

void NativePerformanceObserver::startReporting(
jsi::Runtime& rt,
int32_t entryType) {
PerformanceEntryType entryType) {
PerformanceEntryReporter& reporter = PerformanceEntryReporter::getInstance();

PerformanceEntryType entryTypeEnum =
static_cast<PerformanceEntryType>(entryType);
reporter.startReporting(entryTypeEnum);
reporter.startReporting(entryType);

if (entryTypeEnum == PerformanceEntryType::EVENT &&
if (entryType == PerformanceEntryType::EVENT &&
CoreFeatures::enableReportEventPaintTime) {
UIManagerBinding::getBinding(rt)->getUIManager().registerMountHook(
reporter);
Expand All @@ -52,88 +50,91 @@ void NativePerformanceObserver::startReporting(

void NativePerformanceObserver::stopReporting(
jsi::Runtime& rt,
int32_t entryType) {
PerformanceEntryType entryType) {
PerformanceEntryReporter& reporter = PerformanceEntryReporter::getInstance();

PerformanceEntryType entryTypeEnum =
static_cast<PerformanceEntryType>(entryType);
reporter.stopReporting(entryTypeEnum);
reporter.stopReporting(entryType);

if (entryTypeEnum == PerformanceEntryType::EVENT &&
if (entryType == PerformanceEntryType::EVENT &&
CoreFeatures::enableReportEventPaintTime) {
UIManagerBinding::getBinding(rt)->getUIManager().unregisterMountHook(
reporter);
}
}

void NativePerformanceObserver::setIsBuffered(
jsi::Runtime& rt,
std::vector<int32_t> entryTypes,
jsi::Runtime& /*rt*/,
const std::vector<PerformanceEntryType> entryTypes,
bool isBuffered) {
for (const int32_t entryType : entryTypes) {
for (const PerformanceEntryType entryType : entryTypes) {
PerformanceEntryReporter::getInstance().setAlwaysLogged(
static_cast<PerformanceEntryType>(entryType), isBuffered);
entryType, isBuffered);
}
}

GetPendingEntriesResult NativePerformanceObserver::popPendingEntries(
jsi::Runtime& rt) {
PerformanceEntryReporter::PopPendingEntriesResult
NativePerformanceObserver::popPendingEntries(jsi::Runtime& /*rt*/) {
return PerformanceEntryReporter::getInstance().popPendingEntries();
}

void NativePerformanceObserver::setOnPerformanceEntryCallback(
jsi::Runtime& rt,
jsi::Runtime& /*rt*/,
std::optional<AsyncCallback<>> callback) {
PerformanceEntryReporter::getInstance().setReportingCallback(callback);
if (callback) {
PerformanceEntryReporter::getInstance().setReportingCallback(
[callback = std::move(callback)]() {
callback->callWithPriority(SchedulerPriority::IdlePriority);
});
} else {
PerformanceEntryReporter::getInstance().setReportingCallback(nullptr);
}
}

void NativePerformanceObserver::logRawEntry(
jsi::Runtime& rt,
RawPerformanceEntry entry) {
jsi::Runtime& /*rt*/,
const PerformanceEntry entry) {
PerformanceEntryReporter::getInstance().logEntry(entry);
}

std::vector<std::pair<std::string, uint32_t>>
NativePerformanceObserver::getEventCounts(jsi::Runtime& rt) {
NativePerformanceObserver::getEventCounts(jsi::Runtime& /*rt*/) {
const auto& eventCounts =
PerformanceEntryReporter::getInstance().getEventCounts();
return std::vector<std::pair<std::string, uint32_t>>(
eventCounts.begin(), eventCounts.end());
}

void NativePerformanceObserver::setDurationThreshold(
jsi::Runtime& rt,
int32_t entryType,
jsi::Runtime& /*rt*/,
PerformanceEntryType entryType,
double durationThreshold) {
PerformanceEntryReporter::getInstance().setDurationThreshold(
static_cast<PerformanceEntryType>(entryType), durationThreshold);
entryType, durationThreshold);
}

void NativePerformanceObserver::clearEntries(
jsi::Runtime& rt,
int32_t entryType,
jsi::Runtime& /*rt*/,
PerformanceEntryType entryType,
std::optional<std::string> entryName) {
PerformanceEntryReporter::getInstance().clearEntries(
static_cast<PerformanceEntryType>(entryType),
entryName ? entryName->c_str() : nullptr);
entryType, entryName ? entryName->c_str() : std::string_view{});
}

std::vector<RawPerformanceEntry> NativePerformanceObserver::getEntries(
jsi::Runtime& rt,
std::optional<int32_t> entryType,
std::vector<PerformanceEntry> NativePerformanceObserver::getEntries(
jsi::Runtime& /*rt*/,
std::optional<PerformanceEntryType> entryType,
std::optional<std::string> entryName) {
return PerformanceEntryReporter::getInstance().getEntries(
entryType ? std::optional{static_cast<PerformanceEntryType>(*entryType)}
: std::nullopt,
entryName ? entryName->c_str() : nullptr);
entryType, entryName ? entryName->c_str() : std::string_view{});
}

std::vector<RawPerformanceEntryType>
NativePerformanceObserver::getSupportedPerformanceEntryTypes(jsi::Runtime& rt) {
std::vector<PerformanceEntryType>
NativePerformanceObserver::getSupportedPerformanceEntryTypes(
jsi::Runtime& /*rt*/) {
return {
static_cast<RawPerformanceEntryType>(PerformanceEntryType::MARK),
static_cast<RawPerformanceEntryType>(PerformanceEntryType::MEASURE),
static_cast<RawPerformanceEntryType>(PerformanceEntryType::EVENT),
PerformanceEntryType::MARK,
PerformanceEntryType::MEASURE,
PerformanceEntryType::EVENT,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,40 @@
#pragma once

#include <FBReactNativeSpec/FBReactNativeSpecJSI.h>
#include <react/performance/timeline/PerformanceEntryReporter.h>
#include <functional>
#include <optional>
#include <string>
#include <vector>

namespace facebook::react {
class PerformanceEntryReporter;

#pragma mark - Structs

using RawPerformanceEntryType = int32_t;

using RawPerformanceEntry = NativePerformanceObserverCxxRawPerformanceEntry<
/* name */ std::string,
/* type */ RawPerformanceEntryType,
/* startTime */ double,
/* duration */ double,

// For "event" entries only:
/* processingStart */ std::optional<double>,
/* processingEnd */ std::optional<double>,
/* interactionId */ std::optional<uint32_t>>;
template <>
struct Bridging<PerformanceEntryType> {
static PerformanceEntryType fromJs(
jsi::Runtime& /*rt*/,
const jsi::Value& value) {
return static_cast<PerformanceEntryType>(value.asNumber());
}

static jsi::Value toJs(
jsi::Runtime& /*rt*/,
const PerformanceEntryType& value) {
return {static_cast<int>(value)};
}
};

template <>
struct Bridging<RawPerformanceEntry>
struct Bridging<PerformanceEntry>
: NativePerformanceObserverCxxRawPerformanceEntryBridging<
RawPerformanceEntry> {};

using GetPendingEntriesResult =
NativePerformanceObserverCxxGetPendingEntriesResult<
std::vector<RawPerformanceEntry>,
uint32_t>;
PerformanceEntry> {};

template <>
struct Bridging<GetPendingEntriesResult>
struct Bridging<PerformanceEntryReporter::PopPendingEntriesResult>
: NativePerformanceObserverCxxGetPendingEntriesResultBridging<
GetPendingEntriesResult> {};
PerformanceEntryReporter::PopPendingEntriesResult> {};

#pragma mark - implementation

Expand All @@ -54,45 +51,44 @@ class NativePerformanceObserver
NativePerformanceObserver(std::shared_ptr<CallInvoker> jsInvoker);
~NativePerformanceObserver();

void startReporting(jsi::Runtime& rt, int32_t entryType);
void startReporting(jsi::Runtime& rt, PerformanceEntryType entryType);

void stopReporting(jsi::Runtime& rt, int32_t entryType);
void stopReporting(jsi::Runtime& rt, PerformanceEntryType entryType);

void setIsBuffered(
jsi::Runtime& rt,
std::vector<int32_t> entryTypes,
const std::vector<PerformanceEntryType> entryTypes,
bool isBuffered);

GetPendingEntriesResult popPendingEntries(jsi::Runtime& rt);
PerformanceEntryReporter::PopPendingEntriesResult popPendingEntries(
jsi::Runtime& rt);

void setOnPerformanceEntryCallback(
jsi::Runtime& rt,
std::optional<AsyncCallback<>> callback);

void logRawEntry(jsi::Runtime& rt, RawPerformanceEntry entry);
void logRawEntry(jsi::Runtime& rt, const PerformanceEntry entry);

std::vector<std::pair<std::string, uint32_t>> getEventCounts(
jsi::Runtime& rt);

void setDurationThreshold(
jsi::Runtime& rt,
int32_t entryType,
double durationThreshold);
PerformanceEntryType entryType,
DOMHighResTimeStamp durationThreshold);

void clearEntries(
jsi::Runtime& rt,
int32_t entryType,
PerformanceEntryType entryType,
std::optional<std::string> entryName);

std::vector<RawPerformanceEntry> getEntries(
std::vector<PerformanceEntry> getEntries(
jsi::Runtime& rt,
std::optional<int32_t> entryType,
std::optional<PerformanceEntryType> entryType,
std::optional<std::string> entryName);

std::vector<RawPerformanceEntryType> getSupportedPerformanceEntryTypes(
std::vector<PerformanceEntryType> getSupportedPerformanceEntryTypes(
jsi::Runtime& rt);

private:
};

} // namespace facebook::react
Loading
Loading