Files
react-native/Libraries/WebPerformance/PerformanceEntryReporter.h
T
Ruslan Shestopalyuk cb552f62f2 Create NativePerformance C++ module
Summary:
[Changelog][Internal]

The NativePerformance module functionality corresponds to the [timing extensions of the Performance API standard interface](https://www.w3.org/TR/user-timing/#extensions-performance-interface).

As this is logically separate from `PerformanceObserver` (which may exist without it), it makes sense to have it as a different native module, so there is no coupling between both.

Reviewed By: christophpurrer

Differential Revision: D41690145

fbshipit-source-id: 7443f4c51f54cc2fdddbdb2e89f9a1fa457ab280
2022-12-03 08:32:58 -08:00

58 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 <react/bridging/Function.h>
#include <array>
#include <optional>
#include "NativePerformanceObserver.h"
namespace facebook::react {
enum class PerformanceEntryType {
UNDEFINED = 0,
MARK = 1,
_COUNT = 2,
};
class PerformanceEntryReporter {
public:
PerformanceEntryReporter(PerformanceEntryReporter const &) = delete;
void operator=(PerformanceEntryReporter const &) = delete;
// NOTE: This class is not thread safe, make sure that the calls are made from
// the same thread.
// TODO: Consider passing it as a parameter to the corresponding modules at
// creation time instead of having the singleton.
static PerformanceEntryReporter &getInstance();
void setReportingCallback(std::optional<AsyncCallback<>> callback);
void startReporting(PerformanceEntryType entryType);
void stopReporting(PerformanceEntryType entryType);
const std::vector<RawPerformanceEntry> &getPendingEntries() const;
std::vector<RawPerformanceEntry> popPendingEntries();
void clearPendingEntries();
void logEntry(const RawPerformanceEntry &entry);
bool isReportingType(PerformanceEntryType entryType) const {
return reportingType_[static_cast<int>(entryType)];
}
void mark(const std::string &name, double startTime, double duration);
private:
PerformanceEntryReporter() {}
std::optional<AsyncCallback<>> callback_;
std::vector<RawPerformanceEntry> entries_;
std::array<bool, (size_t)PerformanceEntryType::_COUNT> reportingType_{false};
};
} // namespace facebook::react