Skip to content

Commit

Permalink
Rename SystraceSection to TraceSection (facebook#48383)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#48383

## Changelog:
[Internal] -

This changes the name of `SystraceSection` class to `TraceSection`, the purpose being to make it Systrace/FBSystrace agnostic (and that it can be mapped to e.g. Perfetto instead).

It changes all the internal callsites to the RN code code, and also adds a shim include, `<cxxreact/SystraceSection.h`, for backward compatibility with the external callers for now (which will be addressed separately).

Reviewed By: javache

Differential Revision: D67621914
  • Loading branch information
rshest authored and facebook-github-bot committed Dec 24, 2024
1 parent 17a644a commit 71ddb92
Show file tree
Hide file tree
Showing 37 changed files with 352 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#import <React/RCTFollyConvert.h>
#import <React/RCTLog.h>
#import <React/RCTUtils.h>
#import <cxxreact/SystraceSection.h>
#import <cxxreact/TraceSection.h>
#import <react/renderer/components/root/RootShadowNode.h>
#import <react/renderer/core/LayoutableShadowNode.h>
#import <react/renderer/core/RawProps.h>
Expand Down Expand Up @@ -45,7 +45,7 @@ static void RCTPerformMountInstructions(
RCTMountingTransactionObserverCoordinator &observerCoordinator,
SurfaceId surfaceId)
{
SystraceSection s("RCTPerformMountInstructions");
TraceSection s("RCTPerformMountInstructions");

for (const auto &mutation : mutations) {
switch (mutation.type) {
Expand Down Expand Up @@ -232,7 +232,7 @@ - (void)sendAccessibilityEvent:(ReactTag)reactTag eventType:(NSString *)eventTyp

- (void)initiateTransaction:(const MountingCoordinator &)mountingCoordinator
{
SystraceSection s("-[RCTMountingManager initiateTransaction:]");
TraceSection s("-[RCTMountingManager initiateTransaction:]");
RCTAssertMainQueue();

if (_transactionInFlight) {
Expand All @@ -250,7 +250,7 @@ - (void)initiateTransaction:(const MountingCoordinator &)mountingCoordinator

- (void)performTransaction:(const MountingCoordinator &)mountingCoordinator
{
SystraceSection s("-[RCTMountingManager performTransaction:]");
TraceSection s("-[RCTMountingManager performTransaction:]");
RCTAssertMainQueue();

auto surfaceId = mountingCoordinator.getSurfaceId();
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/Fabric/RCTScheduler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#import "RCTScheduler.h"

#import <cxxreact/SystraceSection.h>
#import <cxxreact/TraceSection.h>
#import <react/featureflags/ReactNativeFeatureFlags.h>
#import <react/renderer/animations/LayoutAnimationDriver.h>
#import <react/renderer/componentregistry/ComponentDescriptorFactory.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "MountItem.h"
#include "StateWrapperImpl.h"

#include <cxxreact/SystraceSection.h>
#include <cxxreact/TraceSection.h>
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/renderer/components/scrollview/ScrollViewProps.h>
Expand Down Expand Up @@ -446,7 +446,7 @@ inline void writeUpdateOverflowInsetMountItem(

void FabricMountingManager::executeMount(
const MountingTransaction& transaction) {
SystraceSection section("FabricMountingManager::executeMount");
TraceSection section("FabricMountingManager::executeMount");

std::scoped_lock lock(commitMutex_);
auto finishTransactionStartTime = telemetryTimePointNow();
Expand Down Expand Up @@ -939,7 +939,7 @@ void FabricMountingManager::maybePreallocateShadowNode(

void FabricMountingManager::preallocateShadowView(
const ShadowView& shadowView) {
SystraceSection section("FabricMountingManager::preallocateShadowView");
TraceSection section("FabricMountingManager::preallocateShadowView");

{
std::lock_guard lock(allocatedViewsMutex_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "EventEmitterWrapper.h"
#include "FabricMountingManager.h"

#include <cxxreact/SystraceSection.h>
#include <cxxreact/TraceSection.h>
#include <fbjni/fbjni.h>
#include <glog/logging.h>
#include <jsi/JSIDynamic.h>
Expand Down Expand Up @@ -135,7 +135,7 @@ void FabricUIManagerBinding::startSurfaceWithSurfaceHandler(
jint surfaceId,
jni::alias_ref<SurfaceHandlerBinding::jhybridobject> surfaceHandlerBinding,
jboolean isMountable) {
SystraceSection s("FabricUIManagerBinding::startSurfaceWithSurfaceHandler");
TraceSection s("FabricUIManagerBinding::startSurfaceWithSurfaceHandler");
if (enableFabricLogs_) {
LOG(WARNING)
<< "FabricUIManagerBinding::startSurfaceWithSurfaceHandler() was called (address: "
Expand Down Expand Up @@ -180,7 +180,7 @@ void FabricUIManagerBinding::startSurface(
jint surfaceId,
jni::alias_ref<jstring> moduleName,
NativeMap* initialProps) {
SystraceSection s("FabricUIManagerBinding::startSurface");
TraceSection s("FabricUIManagerBinding::startSurface");

if (enableFabricLogs_) {
LOG(WARNING)
Expand Down Expand Up @@ -235,7 +235,7 @@ void FabricUIManagerBinding::startSurfaceWithConstraints(
jfloat offsetY,
jboolean isRTL,
jboolean doLeftAndRightSwapInRTL) {
SystraceSection s("FabricUIManagerBinding::startSurfaceWithConstraints");
TraceSection s("FabricUIManagerBinding::startSurfaceWithConstraints");

if (enableFabricLogs_) {
LOG(WARNING)
Expand Down Expand Up @@ -293,7 +293,7 @@ void FabricUIManagerBinding::startSurfaceWithConstraints(

// Used by non-bridgeless+Fabric
void FabricUIManagerBinding::stopSurface(jint surfaceId) {
SystraceSection s("FabricUIManagerBinding::stopSurface");
TraceSection s("FabricUIManagerBinding::stopSurface");
if (enableFabricLogs_) {
LOG(WARNING)
<< "FabricUIManagerBinding::stopSurface() was called (address: " << this
Expand Down Expand Up @@ -336,7 +336,7 @@ void FabricUIManagerBinding::stopSurface(jint surfaceId) {
void FabricUIManagerBinding::stopSurfaceWithSurfaceHandler(
jni::alias_ref<SurfaceHandlerBinding::jhybridobject>
surfaceHandlerBinding) {
SystraceSection s("FabricUIManagerBinding::stopSurfaceWithSurfaceHandler");
TraceSection s("FabricUIManagerBinding::stopSurfaceWithSurfaceHandler");
const auto& surfaceHandler =
surfaceHandlerBinding->cthis()->getSurfaceHandler();
if (enableFabricLogs_) {
Expand Down Expand Up @@ -377,7 +377,7 @@ void FabricUIManagerBinding::setConstraints(
jfloat offsetY,
jboolean isRTL,
jboolean doLeftAndRightSwapInRTL) {
SystraceSection s("FabricUIManagerBinding::setConstraints");
TraceSection s("FabricUIManagerBinding::setConstraints");

auto scheduler = getScheduler();
if (!scheduler) {
Expand Down Expand Up @@ -425,7 +425,7 @@ void FabricUIManagerBinding::installFabricUIManager(
jni::alias_ref<JFabricUIManager::javaobject> javaUIManager,
EventBeatManager* eventBeatManager,
ComponentFactory* componentsRegistry) {
SystraceSection s("FabricUIManagerBinding::installFabricUIManager");
TraceSection s("FabricUIManagerBinding::installFabricUIManager");

enableFabricLogs_ = ReactNativeFeatureFlags::enableFabricLogs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <cxxreact/JSBigString.h>
#include <cxxreact/ModuleRegistry.h>
#include <cxxreact/SystraceSection.h>
#include <cxxreact/TraceSection.h>
#include <fb/assert.h>
#include <folly/json.h>

Expand Down Expand Up @@ -53,7 +53,7 @@ void ProxyExecutor::initializeRuntime() {
folly::dynamic nativeModuleConfig = folly::dynamic::array;

{
SystraceSection s("collectNativeModuleDescriptions");
TraceSection s("collectNativeModuleDescriptions");
auto moduleRegistry = m_delegate->getModuleRegistry();
for (const auto& name : moduleRegistry->moduleNames()) {
auto config = moduleRegistry->getConfig(name);
Expand All @@ -65,7 +65,7 @@ void ProxyExecutor::initializeRuntime() {
"remoteModuleConfig", std::move(nativeModuleConfig));

{
SystraceSection t("setGlobalVariable");
TraceSection t("setGlobalVariable");
setGlobalVariable(
"__fbBatchedBridgeConfig",
std::make_unique<JSBigStdString>(folly::toJson(config)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "JsArgumentHelpers.h"
#include "MessageQueueThread.h"
#include "SystraceSection.h"
#include "TraceSection.h"

#include <logger/react_native_log.h>

Expand Down Expand Up @@ -188,7 +188,7 @@ void CxxNativeModule::invoke(
// mhorowitz #7128529: convert C++ exceptions to Java

const auto& moduleName = name_;
SystraceSection s(
TraceSection s(
"CxxMethodCallQueue", "module", moduleName, "method", method.name);
messageQueueThread_->runOnQueue([method,
moduleName,
Expand All @@ -203,7 +203,7 @@ void CxxNativeModule::invoke(
#else
(void)(callId);
#endif
SystraceSection s(
TraceSection s(
"CxxMethodCallDispatch", "module", moduleName, "method", method.name);
try {
method.func(std::move(params), first, second);
Expand Down
12 changes: 6 additions & 6 deletions packages/react-native/ReactCommon/cxxreact/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "NativeToJsBridge.h"
#include "RAMBundleRegistry.h"
#include "RecoverableError.h"
#include "SystraceSection.h"
#include "TraceSection.h"

#include <cxxreact/JSIndexedRAMBundle.h>
#include <folly/json.h>
Expand Down Expand Up @@ -133,7 +133,7 @@ void Instance::loadBundle(
std::unique_ptr<const JSBigString> string,
std::string sourceURL) {
callback_->incrementPendingJSCalls();
SystraceSection s("Instance::loadBundle", "sourceURL", sourceURL);
TraceSection s("Instance::loadBundle", "sourceURL", sourceURL);
nativeToJsBridge_->loadBundle(
std::move(bundleRegistry), std::move(string), std::move(sourceURL));
}
Expand All @@ -145,14 +145,14 @@ void Instance::loadBundleSync(
std::unique_lock<std::mutex> lock(m_syncMutex);
m_syncCV.wait(lock, [this] { return m_syncReady; });

SystraceSection s("Instance::loadBundleSync", "sourceURL", sourceURL);
TraceSection s("Instance::loadBundleSync", "sourceURL", sourceURL);
nativeToJsBridge_->loadBundleSync(
std::move(bundleRegistry), std::move(string), std::move(sourceURL));
}

void Instance::setSourceURL(std::string sourceURL) {
callback_->incrementPendingJSCalls();
SystraceSection s("Instance::setSourceURL", "sourceURL", sourceURL);
TraceSection s("Instance::setSourceURL", "sourceURL", sourceURL);

nativeToJsBridge_->loadBundle(nullptr, nullptr, std::move(sourceURL));
}
Expand All @@ -161,7 +161,7 @@ void Instance::loadScriptFromString(
std::unique_ptr<const JSBigString> string,
std::string sourceURL,
bool loadSynchronously) {
SystraceSection s("Instance::loadScriptFromString", "sourceURL", sourceURL);
TraceSection s("Instance::loadScriptFromString", "sourceURL", sourceURL);
if (loadSynchronously) {
loadBundleSync(nullptr, std::move(string), std::move(sourceURL));
} else {
Expand Down Expand Up @@ -241,7 +241,7 @@ void Instance::callJSFunction(
}

void Instance::callJSCallback(uint64_t callbackId, folly::dynamic&& params) {
SystraceSection s("Instance::callJSCallback");
TraceSection s("Instance::callJSCallback");
callback_->incrementPendingJSCalls();
nativeToJsBridge_->invokeCallback((double)callbackId, std::move(params));
}
Expand Down
12 changes: 6 additions & 6 deletions packages/react-native/ReactCommon/cxxreact/ModuleRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <reactperflogger/BridgeNativeModulePerfLogger.h>

#include "NativeModule.h"
#include "SystraceSection.h"
#include "TraceSection.h"

namespace facebook::react {

Expand Down Expand Up @@ -46,7 +46,7 @@ void ModuleRegistry::updateModuleNamesFromIndex(size_t index) {

void ModuleRegistry::registerModules(
std::vector<std::unique_ptr<NativeModule>> modules) {
SystraceSection s_("ModuleRegistry::registerModules");
TraceSection s_("ModuleRegistry::registerModules");
// Noop if there are no NativeModules to add
if (modules.empty()) {
return;
Expand Down Expand Up @@ -81,7 +81,7 @@ void ModuleRegistry::registerModules(
}

std::vector<std::string> ModuleRegistry::moduleNames() {
SystraceSection s_("ModuleRegistry::moduleNames");
TraceSection s_("ModuleRegistry::moduleNames");
std::vector<std::string> names;
for (size_t i = 0; i < modules_.size(); i++) {
std::string name = normalizeName(modules_[i]->getName());
Expand All @@ -92,7 +92,7 @@ std::vector<std::string> ModuleRegistry::moduleNames() {
}

std::optional<ModuleConfig> ModuleRegistry::getConfig(const std::string& name) {
SystraceSection s("ModuleRegistry::getConfig", "module", name);
TraceSection s("ModuleRegistry::getConfig", "module", name);

// Initialize modulesByName_
if (modulesByName_.empty() && !modules_.empty()) {
Expand Down Expand Up @@ -144,7 +144,7 @@ std::optional<ModuleConfig> ModuleRegistry::getConfig(const std::string& name) {
folly::dynamic config = folly::dynamic::array(name);

{
SystraceSection s_("ModuleRegistry::getConstants", "module", name);
TraceSection s_("ModuleRegistry::getConstants", "module", name);
/**
* In the case that there are constants, we'll initialize the NativeModule,
* and signal moduleJSRequireEndingStart. Otherwise, we'll simply signal the
Expand All @@ -155,7 +155,7 @@ std::optional<ModuleConfig> ModuleRegistry::getConfig(const std::string& name) {
}

{
SystraceSection s_("ModuleRegistry::getMethods", "module", name);
TraceSection s_("ModuleRegistry::getMethods", "module", name);
std::vector<MethodDescriptor> methods = module->getMethods();

folly::dynamic methodNames = folly::dynamic::array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "ModuleRegistry.h"
#include "MoveWrapper.h"
#include "RAMBundleRegistry.h"
#include "SystraceSection.h"
#include "TraceSection.h"

#include <memory>

Expand Down Expand Up @@ -194,7 +194,7 @@ void NativeToJsBridge::callFunction(
#ifdef WITH_FBSYSTRACE
FbSystraceAsyncFlow::end(
TRACE_TAG_REACT_CXX_BRIDGE, "JSCall", systraceCookie);
SystraceSection s(
TraceSection s(
"NativeToJsBridge::callFunction", "module", module, "method", method);
#else
(void)(systraceCookie);
Expand Down Expand Up @@ -229,7 +229,7 @@ void NativeToJsBridge::invokeCallback(
#ifdef WITH_FBSYSTRACE
FbSystraceAsyncFlow::end(
TRACE_TAG_REACT_CXX_BRIDGE, "<callback>", systraceCookie);
SystraceSection s("NativeToJsBridge::invokeCallback");
TraceSection s("NativeToJsBridge::invokeCallback");
#else
(void)(systraceCookie);
#endif
Expand Down
Loading

0 comments on commit 71ddb92

Please sign in to comment.