mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary:
## Motivation
We got this crash T67304907, which shows a `EXC_BAD_ACCESS / KERN_INVALID_ADDRESS` when calling this line:
```
NativeModulePerfLogger::getInstance().asyncMethodCallBatchPreprocessStart();
```
There are no arguments in that call, so I figured the only error could be when we try to invoke `getInstance()` or `asyncMethodCallBatchPreprocessStart()`.
This diff:
1. Removes the `NativeModulePerfLogger::getInstance()` bit. Now NativeModulePerfLogger is used via regular static C functions. So, there's no way that simply invoking one of the logging functions crashes the application: there's no vtable lookup.
2. Inside each logging function, when perf-logging is disabled, the global perflogger should be `nullptr`. This diff makes it so that in that case, we won't execute any code in the control group of the perf-logging experiment.
## Changes
**How do we enable NativeModule perf-logging?**
- Previously:
- `NativeModulePerfLogger::setInstance(std::make_shared<FBReactNativeModulePerfLogger>(...))`
- `TurboModulePerfLogger::setInstance(std::make_shared<FBReactNativeModulePerfLogger>(...))`.
- Now:
- `BridgeNativeModulePerfLogger::enableLogging(std::make_unique<FBReactNativeModulePerfLogger>(...))`
- `TurboModulePerfLogger::enableLogging(std::make_unique<FBReactNativeModulePerfLogger>(...))`
**How do we do NativeModule perf-logging now?**
- Previously:
- `NativeModulePerfLogger::getInstance().command(...args)`
- `TurboModulePerfLogger::getInstance().command(...args)`.
- Now:
- `BridgeNativeModulePerfLogger::command(...args)`
- `TurboModulePerfLogger::command(...args)`.
The benefit of this approach is that each method in `BridgeNativeModulePerfLogger` is guarded with an if check. Example:
```
void moduleCreateConstructStart(const char *moduleName, int32_t id) {
NativeModulePerfLogger *logger = g_perfLogger.get();
if (logger != nullptr) {
logger->moduleCreateConstructStart(moduleName, id);
}
}
```
Therefore, we don't actually execute any code when perf-logging is disabled.
Changelog:
[Internal]
Reviewed By: fkgozali
Differential Revision: D21669888
fbshipit-source-id: 80c73754c430ce787404b563878bad146295e01f
112 lines
3.6 KiB
C++
112 lines
3.6 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its 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 <memory>
|
|
#include "NativeModulePerfLogger.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
namespace BridgeNativeModulePerfLogger {
|
|
void enableLogging(std::unique_ptr<NativeModulePerfLogger> &&logger);
|
|
|
|
void moduleDataCreateStart(const char *moduleName, int32_t id);
|
|
void moduleDataCreateEnd(const char *moduleName, int32_t id);
|
|
|
|
/**
|
|
* Create NativeModule platform object
|
|
*/
|
|
void moduleCreateStart(const char *moduleName, int32_t id);
|
|
void moduleCreateCacheHit(const char *moduleName, int32_t id);
|
|
void moduleCreateConstructStart(const char *moduleName, int32_t id);
|
|
void moduleCreateConstructEnd(const char *moduleName, int32_t id);
|
|
void moduleCreateSetUpStart(const char *moduleName, int32_t id);
|
|
void moduleCreateSetUpEnd(const char *moduleName, int32_t id);
|
|
void moduleCreateEnd(const char *moduleName, int32_t id);
|
|
void moduleCreateFail(const char *moduleName, int32_t id);
|
|
|
|
/**
|
|
* JS require beginning
|
|
*/
|
|
void moduleJSRequireBeginningStart(const char *moduleName);
|
|
void moduleJSRequireBeginningCacheHit(const char *moduleName);
|
|
void moduleJSRequireBeginningEnd(const char *moduleName);
|
|
void moduleJSRequireBeginningFail(const char *moduleName);
|
|
|
|
/**
|
|
* JS require ending
|
|
*/
|
|
void moduleJSRequireEndingStart(const char *moduleName);
|
|
void moduleJSRequireEndingEnd(const char *moduleName);
|
|
void moduleJSRequireEndingFail(const char *moduleName);
|
|
|
|
// Sync method calls
|
|
void syncMethodCallStart(const char *moduleName, const char *methodName);
|
|
void syncMethodCallArgConversionStart(
|
|
const char *moduleName,
|
|
const char *methodName);
|
|
void syncMethodCallArgConversionEnd(
|
|
const char *moduleName,
|
|
const char *methodName);
|
|
void syncMethodCallExecutionStart(
|
|
const char *moduleName,
|
|
const char *methodName);
|
|
void syncMethodCallExecutionEnd(const char *moduleName, const char *methodName);
|
|
void syncMethodCallReturnConversionStart(
|
|
const char *moduleName,
|
|
const char *methodName);
|
|
void syncMethodCallReturnConversionEnd(
|
|
const char *moduleName,
|
|
const char *methodName);
|
|
void syncMethodCallEnd(const char *moduleName, const char *methodName);
|
|
void syncMethodCallFail(const char *moduleName, const char *methodName);
|
|
|
|
// Async method calls
|
|
void asyncMethodCallStart(const char *moduleName, const char *methodName);
|
|
void asyncMethodCallArgConversionStart(
|
|
const char *moduleName,
|
|
const char *methodName);
|
|
void asyncMethodCallArgConversionEnd(
|
|
const char *moduleName,
|
|
const char *methodName);
|
|
void asyncMethodCallDispatch(const char *moduleName, const char *methodName);
|
|
void asyncMethodCallEnd(const char *moduleName, const char *methodName);
|
|
|
|
/**
|
|
* Pre-processing async method call batch
|
|
*/
|
|
void asyncMethodCallBatchPreprocessStart();
|
|
void asyncMethodCallBatchPreprocessEnd(int batchSize);
|
|
|
|
// Async method call execution
|
|
void asyncMethodCallExecutionStart(
|
|
const char *moduleName,
|
|
const char *methodName,
|
|
int32_t id);
|
|
void asyncMethodCallExecutionArgConversionStart(
|
|
const char *moduleName,
|
|
const char *methodName,
|
|
int32_t id);
|
|
void asyncMethodCallExecutionArgConversionEnd(
|
|
const char *moduleName,
|
|
const char *methodName,
|
|
int32_t id);
|
|
void asyncMethodCallExecutionEnd(
|
|
const char *moduleName,
|
|
const char *methodName,
|
|
int32_t id);
|
|
void asyncMethodCallExecutionFail(
|
|
const char *moduleName,
|
|
const char *methodName,
|
|
int32_t id);
|
|
|
|
} // namespace BridgeNativeModulePerfLogger
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|