Make the pattern for adding systrace sections more concise
Reviewed By: astreet Differential Revision: D3234834 fbshipit-source-id: 73e191deb4dd0e06d4c242e46a582051d4bcc9ba
This commit is contained in:
Родитель
267264f1ec
Коммит
f433ed716c
|
@ -4,14 +4,15 @@
|
|||
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
#include <fbsystrace.h>
|
||||
using fbsystrace::FbSystraceSection;
|
||||
using fbsystrace::FbSystraceAsyncFlow;
|
||||
#endif
|
||||
|
||||
#include <folly/json.h>
|
||||
#include <folly/Memory.h>
|
||||
#include <folly/MoveWrapper.h>
|
||||
|
||||
#include "Platform.h"
|
||||
#include "SystraceSection.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
@ -75,7 +76,7 @@ void Bridge::callFunction(
|
|||
TRACE_TAG_REACT_CXX_BRIDGE,
|
||||
tracingName.c_str(),
|
||||
systraceCookie);
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, tracingName.c_str());
|
||||
SystraceSection s(tracingName.c_str());
|
||||
#endif
|
||||
|
||||
// This is safe because we are running on the executor's thread: it won't
|
||||
|
@ -100,7 +101,7 @@ void Bridge::invokeCallback(ExecutorToken executorToken, const double callbackId
|
|||
TRACE_TAG_REACT_CXX_BRIDGE,
|
||||
"<callback>",
|
||||
systraceCookie);
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "Bridge.invokeCallback");
|
||||
SystraceSection s("Bridge.invokeCallback");
|
||||
#endif
|
||||
|
||||
executor->invokeCallback(callbackId, arguments);
|
||||
|
|
|
@ -4,11 +4,7 @@
|
|||
|
||||
#include "Executor.h"
|
||||
#include "MethodCall.h"
|
||||
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
#include <fbsystrace.h>
|
||||
using fbsystrace::FbSystraceSection;
|
||||
#endif
|
||||
#include "SystraceSection.h"
|
||||
|
||||
#include <folly/json.h>
|
||||
#include <folly/Memory.h>
|
||||
|
@ -77,17 +73,13 @@ void Instance::initializeBridge(
|
|||
bridge_ = folly::make_unique<Bridge>(
|
||||
jsef.get(), jsQueue_, folly::make_unique<ExecutorTokenFactoryImpl>(callback_.get()), folly::make_unique<BridgeCallbackImpl>(this));
|
||||
});
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "setBatchedBridgeConfig");
|
||||
#endif
|
||||
SystraceSection s("setBatchedBridgeConfig");
|
||||
|
||||
CHECK(bridge_);
|
||||
|
||||
folly::dynamic nativeModuleDescriptions = folly::dynamic::array();
|
||||
{
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "collectNativeModuleDescriptions");
|
||||
#endif
|
||||
SystraceSection s("collectNativeModuleDescriptions");
|
||||
nativeModuleDescriptions = moduleRegistry_->moduleDescriptions();
|
||||
}
|
||||
|
||||
|
@ -95,9 +87,7 @@ void Instance::initializeBridge(
|
|||
folly::dynamic::object
|
||||
("remoteModuleConfig", std::move(nativeModuleDescriptions));
|
||||
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection t(TRACE_TAG_REACT_CXX_BRIDGE, "setGlobalVariable");
|
||||
#endif
|
||||
SystraceSection t("setGlobalVariable");
|
||||
setGlobalVariable(
|
||||
"__fbBatchedBridgeConfig",
|
||||
folly::toJson(config));
|
||||
|
@ -106,11 +96,8 @@ void Instance::initializeBridge(
|
|||
void Instance::loadScriptFromString(const std::string& string,
|
||||
const std::string& sourceURL) {
|
||||
callback_->incrementPendingJSCalls();
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE,
|
||||
"reactbridge_xplat_loadScriptFromString",
|
||||
"sourceURL", sourceURL);
|
||||
#endif
|
||||
SystraceSection s("reactbridge_xplat_loadScriptFromString",
|
||||
"sourceURL", sourceURL);
|
||||
// TODO mhorowitz: ReactMarker around loadApplicationScript
|
||||
bridge_->loadApplicationScript(string, sourceURL);
|
||||
}
|
||||
|
@ -120,11 +107,8 @@ void Instance::loadScriptFromFile(const std::string& filename,
|
|||
// TODO mhorowitz: ReactMarker around file read
|
||||
std::string script;
|
||||
{
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE,
|
||||
"reactbridge_xplat_loadScriptFromFile",
|
||||
"fileName", filename);
|
||||
#endif
|
||||
SystraceSection s("reactbridge_xplat_loadScriptFromFile",
|
||||
"fileName", filename);
|
||||
|
||||
std::ifstream jsfile(filename);
|
||||
if (!jsfile) {
|
||||
|
@ -146,10 +130,7 @@ void Instance::loadUnbundle(std::unique_ptr<JSModulesUnbundle> unbundle,
|
|||
const std::string& startupScript,
|
||||
const std::string& startupScriptSourceURL) {
|
||||
callback_->incrementPendingJSCalls();
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE,
|
||||
"reactbridge_xplat_setJSModulesUnbundle");
|
||||
#endif
|
||||
SystraceSection s("reactbridge_xplat_setJSModulesUnbundle");
|
||||
bridge_->loadApplicationUnbundle(std::move(unbundle), startupScript, startupScriptSourceURL);
|
||||
}
|
||||
|
||||
|
@ -172,17 +153,13 @@ void Instance::setGlobalVariable(const std::string& propName,
|
|||
|
||||
void Instance::callJSFunction(ExecutorToken token, const std::string& module, const std::string& method,
|
||||
folly::dynamic&& params, const std::string& tracingName) {
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, tracingName.c_str());
|
||||
#endif
|
||||
SystraceSection s(tracingName.c_str());
|
||||
callback_->incrementPendingJSCalls();
|
||||
bridge_->callFunction(token, module, method, std::move(params), tracingName);
|
||||
}
|
||||
|
||||
void Instance::callJSCallback(ExecutorToken token, uint64_t callbackId, folly::dynamic&& params) {
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "<callback>");
|
||||
#endif
|
||||
SystraceSection s("<callback>");
|
||||
callback_->incrementPendingJSCalls();
|
||||
bridge_->invokeCallback(token, (double) callbackId, std::move(params));
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "Bridge.h"
|
||||
#include "JSCHelpers.h"
|
||||
#include "Platform.h"
|
||||
#include "SystraceSection.h"
|
||||
#include "Value.h"
|
||||
|
||||
#if defined(WITH_JSC_EXTRA_TRACING) || DEBUG
|
||||
|
@ -32,11 +33,6 @@
|
|||
#include <jsc_memory.h>
|
||||
#endif
|
||||
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
#include <fbsystrace.h>
|
||||
using fbsystrace::FbSystraceSection;
|
||||
#endif
|
||||
|
||||
#ifdef WITH_FB_MEMORY_PROFILING
|
||||
#include "JSCMemory.h"
|
||||
#endif
|
||||
|
@ -97,11 +93,8 @@ static std::string executeJSCallWithJSC(
|
|||
JSGlobalContextRef ctx,
|
||||
const std::string& methodName,
|
||||
const std::vector<folly::dynamic>& arguments) {
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(
|
||||
TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor.executeJSCall",
|
||||
"method", methodName);
|
||||
#endif
|
||||
SystraceSection s("JSCExecutor.executeJSCall",
|
||||
"method", methodName);
|
||||
|
||||
// Evaluate script with JSC
|
||||
folly::dynamic jsonArgs(arguments.begin(), arguments.end());
|
||||
|
@ -181,10 +174,7 @@ void JSCExecutor::destroy() {
|
|||
}
|
||||
|
||||
void JSCExecutor::initOnJSVMThread() {
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(
|
||||
TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor.initOnJSVMThread");
|
||||
#endif
|
||||
SystraceSection s("JSCExecutor.initOnJSVMThread");
|
||||
|
||||
#if defined(WITH_FB_JSC_TUNING)
|
||||
configureJSCForAndroid(m_jscConfig);
|
||||
|
@ -249,10 +239,8 @@ void JSCExecutor::terminateOnJSVMThread() {
|
|||
void JSCExecutor::loadApplicationScript(
|
||||
const std::string& script,
|
||||
const std::string& sourceURL) {
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "JSCExecutor::loadApplicationScript",
|
||||
"sourceURL", sourceURL);
|
||||
#endif
|
||||
SystraceSection s("JSCExecutor::loadApplicationScript",
|
||||
"sourceURL", sourceURL);
|
||||
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
fbsystrace_begin_section(
|
||||
|
|
|
@ -3,11 +3,7 @@
|
|||
#include "ModuleRegistry.h"
|
||||
|
||||
#include "NativeModule.h"
|
||||
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
#include <fbsystrace.h>
|
||||
using fbsystrace::FbSystraceSection;
|
||||
#endif
|
||||
#include "SystraceSection.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
@ -24,9 +20,8 @@ folly::dynamic ModuleRegistry::moduleDescriptions() {
|
|||
folly::dynamic methodDescs = folly::dynamic::object;
|
||||
std::vector<MethodDescriptor> methods;
|
||||
{
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "getMethods", "module", module->getName());
|
||||
#endif
|
||||
SystraceSection s("getMethods",
|
||||
"module", module->getName());
|
||||
methods = module->getMethods();
|
||||
}
|
||||
for (size_t methodId = 0; methodId < methods.size(); ++methodId) {
|
||||
|
@ -38,9 +33,8 @@ folly::dynamic ModuleRegistry::moduleDescriptions() {
|
|||
|
||||
folly::dynamic constants = folly::dynamic::array();
|
||||
{
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "getConstants", "module", module->getName());
|
||||
#endif
|
||||
SystraceSection s("getConstants",
|
||||
"module", module->getName());
|
||||
constants = module->getConstants();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
#include <fbsystrace.h>
|
||||
#endif
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
/**
|
||||
* This is a convenience class to avoid lots of verbose profiling
|
||||
* #ifdefs. If WITH_FBSYSTRACE is not defined, the optimizer will
|
||||
* remove this completely. If it is defined, it will behave as
|
||||
* FbSystraceSection, with the right tag provided.
|
||||
*/
|
||||
struct SystraceSection {
|
||||
public:
|
||||
template<typename... ConvertsToStringPiece>
|
||||
explicit SystraceSection(const char* name, ConvertsToStringPiece&&... args)
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
: m_section(TRACE_TAG_REACT_CXX_BRIDGE, name, args...)
|
||||
#endif
|
||||
{}
|
||||
|
||||
private:
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
fbsystrace::FbSystraceSection m_section;
|
||||
#endif
|
||||
};
|
||||
|
||||
}}
|
Загрузка…
Ссылка в новой задаче