log script name with bundle loading perf event

Reviewed By: javache

Differential Revision: D5010638

fbshipit-source-id: 2e139201a8374245fa1dedc4f11a716dcf700fd7
This commit is contained in:
Ben Nham 2017-05-10 03:48:13 -07:00 committed by Facebook Github Bot
parent 5dcfb2c6ad
commit 65f22a5190
6 changed files with 32 additions and 9 deletions

View File

@ -76,7 +76,7 @@ static bool isRAMBundle(NSData *script) {
static void registerPerformanceLoggerHooks(RCTPerformanceLogger *performanceLogger) { static void registerPerformanceLoggerHooks(RCTPerformanceLogger *performanceLogger) {
__weak RCTPerformanceLogger *weakPerformanceLogger = performanceLogger; __weak RCTPerformanceLogger *weakPerformanceLogger = performanceLogger;
ReactMarker::logMarker = [weakPerformanceLogger](const ReactMarker::ReactMarkerId markerId) { ReactMarker::logTaggedMarker = [weakPerformanceLogger](const ReactMarker::ReactMarkerId markerId, const char* tag) {
switch (markerId) { switch (markerId) {
case ReactMarker::RUN_JS_BUNDLE_START: case ReactMarker::RUN_JS_BUNDLE_START:
[weakPerformanceLogger markStartForTag:RCTPLScriptExecution]; [weakPerformanceLogger markStartForTag:RCTPLScriptExecution];

View File

@ -45,7 +45,7 @@ JSValueRef nativePerformanceNow(
} }
void RCTPrepareJSCExecutor() { void RCTPrepareJSCExecutor() {
ReactMarker::logMarker = [](const ReactMarker::ReactMarkerId) {}; ReactMarker::logTaggedMarker = [](const ReactMarker::ReactMarkerId, const char* tag) {};
PerfLogging::installNativeHooks = RCTFBQuickPerformanceLoggerConfigureHooks; PerfLogging::installNativeHooks = RCTFBQuickPerformanceLoggerConfigureHooks;
JSNativeHooks::loggingHook = nativeLoggingHook; JSNativeHooks::loggingHook = nativeLoggingHook;
JSNativeHooks::nowHook = nativePerformanceNow; JSNativeHooks::nowHook = nativePerformanceNow;

View File

@ -84,11 +84,18 @@ class ProxyJavaScriptExecutorHolder : public HybridClass<ProxyJavaScriptExecutor
class JReactMarker : public JavaClass<JReactMarker> { class JReactMarker : public JavaClass<JReactMarker> {
public: public:
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/ReactMarker;"; static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/ReactMarker;";
static void logMarker(const std::string& marker) { static void logMarker(const std::string& marker) {
static auto cls = javaClassStatic(); static auto cls = javaClassStatic();
static auto meth = cls->getStaticMethod<void(std::string)>("logMarker"); static auto meth = cls->getStaticMethod<void(std::string)>("logMarker");
meth(cls, marker); meth(cls, marker);
} }
static void logMarker(const std::string& marker, const std::string& tag) {
static auto cls = javaClassStatic();
static auto meth = cls->getStaticMethod<void(std::string, std::string)>("logMarker");
meth(cls, marker, tag);
}
}; };
static JSValueRef nativePerformanceNow( static JSValueRef nativePerformanceNow(
@ -113,10 +120,10 @@ static JSValueRef nativePerformanceNow(
return Value::makeNumber(ctx, (nano / (double)NANOSECONDS_IN_MILLISECOND)); return Value::makeNumber(ctx, (nano / (double)NANOSECONDS_IN_MILLISECOND));
} }
static void logPerfMarker(const ReactMarker::ReactMarkerId markerId) { static void logPerfMarker(const ReactMarker::ReactMarkerId markerId, const char* tag) {
switch (markerId) { switch (markerId) {
case ReactMarker::RUN_JS_BUNDLE_START: case ReactMarker::RUN_JS_BUNDLE_START:
JReactMarker::logMarker("RUN_JS_BUNDLE_START"); JReactMarker::logMarker("RUN_JS_BUNDLE_START", tag);
break; break;
case ReactMarker::RUN_JS_BUNDLE_STOP: case ReactMarker::RUN_JS_BUNDLE_STOP:
JReactMarker::logMarker("RUN_JS_BUNDLE_END"); JReactMarker::logMarker("RUN_JS_BUNDLE_END");
@ -143,7 +150,7 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
return initialize(vm, [] { return initialize(vm, [] {
gloginit::initialize(); gloginit::initialize();
// Inject some behavior into react/ // Inject some behavior into react/
ReactMarker::logMarker = logPerfMarker; ReactMarker::logTaggedMarker = logPerfMarker;
PerfLogging::installNativeHooks = addNativePerfLoggingHooks; PerfLogging::installNativeHooks = addNativePerfLoggingHooks;
JSNativeHooks::loggingHook = nativeLoggingHook; JSNativeHooks::loggingHook = nativeLoggingHook;
JSNativeHooks::nowHook = nativePerformanceNow; JSNativeHooks::nowHook = nativePerformanceNow;

View File

@ -292,11 +292,18 @@ static const char* explainLoadSourceStatus(JSLoadSourceStatus status) {
} }
#endif #endif
// basename_r isn't in all iOS SDKs, so use this simple version instead.
static std::string simpleBasename(const std::string &path) {
size_t pos = path.rfind("/");
return (pos != std::string::npos) ? path.substr(pos) : path;
}
void JSCExecutor::loadApplicationScript(std::unique_ptr<const JSBigString> script, std::string sourceURL) { void JSCExecutor::loadApplicationScript(std::unique_ptr<const JSBigString> script, std::string sourceURL) {
SystraceSection s("JSCExecutor::loadApplicationScript", SystraceSection s("JSCExecutor::loadApplicationScript",
"sourceURL", sourceURL); "sourceURL", sourceURL);
ReactMarker::logMarker(ReactMarker::RUN_JS_BUNDLE_START); std::string scriptName = simpleBasename(sourceURL);
ReactMarker::logTaggedMarker(ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str());
String jsSourceURL(m_context, sourceURL.c_str()); String jsSourceURL(m_context, sourceURL.c_str());
// TODO t15069155: reduce the number of overrides here // TODO t15069155: reduce the number of overrides here

View File

@ -6,7 +6,12 @@ namespace facebook {
namespace react { namespace react {
namespace ReactMarker { namespace ReactMarker {
LogMarker logMarker; LogTaggedMarker logTaggedMarker;
void logMarker(const ReactMarkerId markerId) {
logTaggedMarker(markerId, nullptr);
}
}; };
namespace PerfLogging { namespace PerfLogging {

View File

@ -23,8 +23,12 @@ enum ReactMarkerId {
JS_BUNDLE_STRING_CONVERT_START, JS_BUNDLE_STRING_CONVERT_START,
JS_BUNDLE_STRING_CONVERT_STOP, JS_BUNDLE_STRING_CONVERT_STOP,
}; };
using LogMarker = std::function<void(const ReactMarkerId)>;
extern LogMarker logMarker; using LogTaggedMarker = std::function<void(const ReactMarkerId, const char* tag)>;
extern LogTaggedMarker logTaggedMarker;
extern void logMarker(const ReactMarkerId markerId);
}; };
namespace PerfLogging { namespace PerfLogging {