/* * 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 #include #include #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> callback); void startReporting(PerformanceEntryType entryType); void stopReporting(PerformanceEntryType entryType); const std::vector &getPendingEntries() const; std::vector popPendingEntries(); void clearPendingEntries(); void logEntry(const RawPerformanceEntry &entry); bool isReportingType(PerformanceEntryType entryType) const { return reportingType_[static_cast(entryType)]; } void mark(const std::string &name, double startTime, double duration); private: PerformanceEntryReporter() {} std::optional> callback_; std::vector entries_; std::array reportingType_{false}; }; } // namespace facebook::react