first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
# 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.
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)
include(${REACT_COMMON_DIR}/cmake-utils/react-native-flags.cmake)
file(GLOB react_nativemodule_cpu_SRC CONFIGURE_DEPENDS *.cpp)
add_library(react_nativemodule_cpu OBJECT ${react_nativemodule_cpu_SRC})
target_include_directories(react_nativemodule_cpu PUBLIC ${REACT_COMMON_DIR})
target_link_libraries(react_nativemodule_cpu
react_codegen_rncore
)
target_compile_reactnative_options(react_nativemodule_cpu PRIVATE)
target_compile_options(react_nativemodule_cpu PRIVATE -Wpedantic)

View File

@@ -0,0 +1,86 @@
/*
* 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
#if defined USE_POSIX_TIME
#include <time.h>
#elif defined __MACH__
#include <mach/mach_time.h>
#else
#include <chrono>
#endif
#ifdef USE_POSIX_TIME
namespace {
const double NANOSECONDS_IN_A_SECOND = 1000000000;
} // namespace
#endif
#ifdef __MACH__
namespace {
inline double getConversionFactor()
{
double conversionFactor;
mach_timebase_info_data_t info;
mach_timebase_info(&info);
conversionFactor = static_cast<double>(info.numer) / info.denom;
return conversionFactor;
}
} // namespace
#endif
namespace facebook::react {
#if defined USE_POSIX_TIME
inline double getCPUTimeNanos()
{
struct timespec time{};
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &time);
return static_cast<double>(time.tv_sec) * NANOSECONDS_IN_A_SECOND + static_cast<double>(time.tv_nsec);
}
inline bool hasAccurateCPUTimeNanosForBenchmarks()
{
return true;
}
#elif defined __MACH__
inline double getCPUTimeNanos()
{
static auto conversionFactor = getConversionFactor();
uint64_t time = mach_absolute_time();
return static_cast<double>(time) * conversionFactor;
}
inline bool hasAccurateCPUTimeNanosForBenchmarks()
{
return true;
}
#else
inline double getCPUTimeNanos()
{
auto now = std::chrono::steady_clock::now();
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count());
}
inline bool hasAccurateCPUTimeNanosForBenchmarks()
{
return false;
}
#endif
} // namespace facebook::react

View File

@@ -0,0 +1,35 @@
/*
* 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.
*/
#include "NativeCPUTime.h"
#include "CPUTime.h"
#ifdef RN_DISABLE_OSS_PLUGIN_HEADER
#include "Plugins.h"
#endif
std::shared_ptr<facebook::react::TurboModule> NativeCPUTimeModuleProvider(
std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
return std::make_shared<facebook::react::NativeCPUTime>(std::move(jsInvoker));
}
namespace facebook::react {
NativeCPUTime::NativeCPUTime(std::shared_ptr<CallInvoker> jsInvoker)
: NativeCPUTimeCxxSpec(std::move(jsInvoker)) {}
double NativeCPUTime::getCPUTimeNanos(jsi::Runtime& /*runtime*/) {
return facebook::react::getCPUTimeNanos();
}
bool NativeCPUTime::hasAccurateCPUTimeNanosForBenchmarks(
jsi::Runtime& /*runtime*/) {
return facebook::react::hasAccurateCPUTimeNanosForBenchmarks();
}
} // namespace facebook::react

View File

@@ -0,0 +1,28 @@
/*
* 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
#if __has_include("rncoreJSI.h") // Cmake headers on Android
#include "rncoreJSI.h"
#elif __has_include("FBReactNativeSpecJSI.h") // CocoaPod headers on Apple
#include "FBReactNativeSpecJSI.h"
#else
#include <FBReactNativeSpec/FBReactNativeSpecJSI.h>
#endif
namespace facebook::react {
class NativeCPUTime : public NativeCPUTimeCxxSpec<NativeCPUTime> {
public:
explicit NativeCPUTime(std::shared_ptr<CallInvoker> jsInvoker);
double getCPUTimeNanos(jsi::Runtime &runtime);
bool hasAccurateCPUTimeNanosForBenchmarks(jsi::Runtime &runtime);
};
} // namespace facebook::react