mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
14ab76ac30
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36312 ## Changelog: [Internal] - `clearMarks` and `clearMeasures` methods are incidental to the `NativePerformance` TurboModule functionality, as in reality this responsibility belongs more on the `NativePerformanceObserver` and `PerformanceEntryReporter` side. This is something that [the standard indirectly suggests](https://www.w3.org/TR/user-timing/#clearmarks-method) as well (referencing [performance entry buffer](https://www.w3.org/TR/performance-timeline/#dfn-performance-entry-buffer)). The new implementation should be also a little bit more efficient, as it avoids calling the predicate for each entry. Finally (and frankly, the main reason for this change, from my perspective), it will simplify mocking/testing the JS part of the PerfAPI code. Reviewed By: rubennorte Differential Revision: D43621174 fbshipit-source-id: c4217a0da1d8ecbce797240627f7b4f057d85b97
91 lines
2.3 KiB
C++
91 lines
2.3 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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <FBReactNativeSpec/FBReactNativeSpecJSI.h>
|
|
#include <functional>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace facebook::react {
|
|
class PerformanceEntryReporter;
|
|
|
|
#pragma mark - Structs
|
|
|
|
using RawPerformanceEntry = NativePerformanceObserverCxxBaseRawPerformanceEntry<
|
|
std::string,
|
|
int32_t,
|
|
double,
|
|
double,
|
|
// For "event" entries only:
|
|
std::optional<double>,
|
|
std::optional<double>,
|
|
std::optional<uint32_t>>;
|
|
|
|
template <>
|
|
struct Bridging<RawPerformanceEntry>
|
|
: NativePerformanceObserverCxxBaseRawPerformanceEntryBridging<
|
|
std::string,
|
|
int32_t,
|
|
double,
|
|
double,
|
|
std::optional<double>,
|
|
std::optional<double>,
|
|
std::optional<uint32_t>> {};
|
|
|
|
using GetPendingEntriesResult =
|
|
NativePerformanceObserverCxxBaseGetPendingEntriesResult<
|
|
std::vector<RawPerformanceEntry>,
|
|
uint32_t>;
|
|
|
|
template <>
|
|
struct Bridging<GetPendingEntriesResult>
|
|
: NativePerformanceObserverCxxBaseGetPendingEntriesResultBridging<
|
|
std::vector<RawPerformanceEntry>,
|
|
uint32_t> {};
|
|
|
|
#pragma mark - implementation
|
|
|
|
class NativePerformanceObserver
|
|
: public NativePerformanceObserverCxxSpec<NativePerformanceObserver>,
|
|
std::enable_shared_from_this<NativePerformanceObserver> {
|
|
public:
|
|
NativePerformanceObserver(std::shared_ptr<CallInvoker> jsInvoker);
|
|
~NativePerformanceObserver();
|
|
|
|
void startReporting(jsi::Runtime &rt, int32_t entryType);
|
|
|
|
void stopReporting(jsi::Runtime &rt, int32_t entryType);
|
|
|
|
GetPendingEntriesResult popPendingEntries(jsi::Runtime &rt);
|
|
|
|
void setOnPerformanceEntryCallback(
|
|
jsi::Runtime &rt,
|
|
std::optional<AsyncCallback<>> callback);
|
|
|
|
void logRawEntry(jsi::Runtime &rt, RawPerformanceEntry entry);
|
|
|
|
std::vector<std::pair<std::string, uint32_t>> getEventCounts(
|
|
jsi::Runtime &rt);
|
|
|
|
void setDurationThreshold(
|
|
jsi::Runtime &rt,
|
|
int32_t entryType,
|
|
double durationThreshold);
|
|
|
|
void clearEntries(
|
|
jsi::Runtime &rt,
|
|
int32_t entryType,
|
|
std::optional<std::string> entryName);
|
|
|
|
private:
|
|
};
|
|
|
|
} // namespace facebook::react
|