Skip to content

Commit

Permalink
Move PerformanceEntryReporter to its own target (facebook#43854)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#43854

Changelog: [internal]

## Context

This is part of a refactor to decouple the performance entry reporter from the rendering infra and from the native module that uses it.

## Changes

This moves the `PerformanceEntryReporter` and related classes to their own target in `ReactCommon/react/performance/timeline` that's not coupled with any rendering logic.

Differential Revision: D55646391
  • Loading branch information
rubennorte authored and facebook-github-bot committed Apr 8, 2024
1 parent 42d75ee commit 35b1a4d
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 20 deletions.
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 Down Expand Up @@ -80,7 +80,14 @@ NativePerformanceObserver::popPendingEntries(jsi::Runtime& /*rt*/) {
void NativePerformanceObserver::setOnPerformanceEntryCallback(
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#pragma once

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

namespace facebook::react {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ PerformanceEntryReporter::PerformanceEntryReporter() {
}

void PerformanceEntryReporter::setReportingCallback(
std::optional<AsyncCallback<>> callback) {
callback_ = callback;
std::function<void()> callback) {
callback_ = std::move(callback);
}

DOMHighResTimeStamp PerformanceEntryReporter::getCurrentTimeStamp() const {
Expand Down Expand Up @@ -295,7 +295,7 @@ void PerformanceEntryReporter::logEventEntry(

void PerformanceEntryReporter::scheduleFlushBuffer() {
if (callback_) {
callback_->callWithPriority(SchedulerPriority::IdlePriority);
callback_();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#pragma once

#include <react/bridging/Function.h>
#include <react/renderer/core/EventLogger.h>
#include <array>
#include <functional>
Expand Down Expand Up @@ -99,7 +98,7 @@ class PerformanceEntryReporter : public EventLogger, public UIManagerMountHook {
uint32_t droppedEntriesCount;
};

void setReportingCallback(std::optional<AsyncCallback<>> callback);
void setReportingCallback(std::function<void()> callback);
void startReporting(PerformanceEntryType entryType);
void stopReporting(PerformanceEntryType entryType);
void stopReporting();
Expand Down Expand Up @@ -174,11 +173,11 @@ class PerformanceEntryReporter : public EventLogger, public UIManagerMountHook {
}

void setTimeStampProvider(std::function<double()> provider) {
timeStampProvider_ = provider;
timeStampProvider_ = std::move(provider);
}

private:
std::optional<AsyncCallback<>> callback_;
std::function<void()> callback_;

mutable std::mutex entriesMutex_;
std::array<PerformanceEntryBuffer, NUM_PERFORMANCE_ENTRY_TYPES> buffers_;
Expand Down

0 comments on commit 35b1a4d

Please sign in to comment.