mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
a64319a2b2
Summary: [Changelog][Internal] Adds API definition for [Performance.mark](https://www.w3.org/TR/user-timing/#mark-method) support. This is a bare bone implementation, that just logs events on the native side. The next step is the native logic for queuing, flushing etc. Note that here I route both JS and native marks to native for now, for simplicity sake - ultimately this may not be what we want, as it may be more efficient to process marks, logged from JS, on the JS side. Reviewed By: rubennorte Differential Revision: D41472148 fbshipit-source-id: bdf2b182b8472a71a5500235849bca5af1c2f360
67 lines
1.7 KiB
C++
67 lines
1.7 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 <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace facebook::react {
|
|
|
|
#pragma mark - Structs
|
|
|
|
using RawPerformanceEntry = NativePerformanceObserverCxxBaseRawPerformanceEntry<
|
|
std::string,
|
|
int32_t,
|
|
double,
|
|
double,
|
|
// For "event" entries only:
|
|
std::optional<double>,
|
|
std::optional<double>,
|
|
std::optional<double>>;
|
|
|
|
template <>
|
|
struct Bridging<RawPerformanceEntry>
|
|
: NativePerformanceObserverCxxBaseRawPerformanceEntryBridging<
|
|
std::string,
|
|
int32_t,
|
|
double,
|
|
double,
|
|
std::optional<double>,
|
|
std::optional<double>,
|
|
std::optional<double>> {};
|
|
|
|
#pragma mark - implementation
|
|
|
|
class NativePerformanceObserver
|
|
: public NativePerformanceObserverCxxSpec<NativePerformanceObserver>,
|
|
std::enable_shared_from_this<NativePerformanceObserver> {
|
|
public:
|
|
NativePerformanceObserver(std::shared_ptr<CallInvoker> jsInvoker);
|
|
|
|
void startReporting(jsi::Runtime &rt, std::string entryType);
|
|
|
|
void stopReporting(jsi::Runtime &rt, std::string entryType);
|
|
|
|
std::vector<RawPerformanceEntry> getPendingEntries(jsi::Runtime &rt);
|
|
|
|
void setOnPerformanceEntryCallback(
|
|
jsi::Runtime &rt,
|
|
std::optional<AsyncCallback<>> callback);
|
|
|
|
void logEntryForDebug(jsi::Runtime &rt, RawPerformanceEntry entry);
|
|
|
|
private:
|
|
std::optional<AsyncCallback<>> callback_;
|
|
};
|
|
|
|
} // namespace facebook::react
|