Skip to content

Instantly share code, notes, and snippets.

@jamesreggio
Created January 20, 2019 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesreggio/afc177f90889d582667072ff9293e73c to your computer and use it in GitHub Desktop.
Save jamesreggio/afc177f90889d582667072ff9293e73c to your computer and use it in GitHub Desktop.
Patch to instrument JavaScriptCore startup time in React Native 0.56.0
From 76ad8283e5de2a0733cbac375c0c16d1d03de891 Mon Sep 17 00:00:00 2001
From: James Reggio <james.reggio@gmail.com>
Date: Wed, 14 Feb 2018 18:57:24 -0500
Subject: [PATCH] add trace statements to JSCLoadApp fn
---
ReactCommon/cxxreact/JSCExecutor.cpp | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp
index 65ee3bd..b12f175 100644
--- a/ReactCommon/cxxreact/JSCExecutor.cpp
+++ b/ReactCommon/cxxreact/JSCExecutor.cpp
@@ -42,6 +42,25 @@
#include "RecoverableError.h"
#include "SystraceSection.h"
+#include <time.h>
+#if defined(__APPLE__)
+#include <os/log.h>
+#define LOGF(...) os_log(OS_LOG_DEFAULT, __VA_ARGS__)
+#else
+#include <android/log.h>
+#define LOGF(...) __android_log_print(ANDROID_LOG_INFO, "lifecycle", __VA_ARGS__)
+#endif
+
+int64_t getTimeNsec() {
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ return (int64_t) now.tv_sec * 1000000000LL + now.tv_nsec;
+}
+
+#if defined(WITH_JSC_MEMORY_PRESSURE)
+#include <jsc_memory.h>
+#endif
+
#if defined(WITH_FB_JSC_TUNING) && defined(__ANDROID__)
#include <jsc_config_android.h>
#endif
@@ -419,6 +438,7 @@ void JSCExecutor::loadApplicationScript(
SystraceSection s(
"JSCExecutor::loadApplicationScript", "sourceURL", sourceURL);
+ auto startLoad = getTimeNsec();
std::string scriptName = simpleBasename(sourceURL);
ReactMarker::logTaggedMarker(
ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str());
@@ -476,6 +496,7 @@ void JSCExecutor::loadApplicationScript(
#endif
{
String jsScript;
+ auto startAdopt = getTimeNsec();
JSContextLock lock(m_context);
{
SystraceSection s_(
@@ -484,11 +505,22 @@ void JSCExecutor::loadApplicationScript(
jsScript = adoptString(std::move(script));
ReactMarker::logMarker(ReactMarker::JS_BUNDLE_STRING_CONVERT_STOP);
}
+ auto endAdopt = getTimeNsec();
+ double durationAdopt = ((double) (endAdopt - startAdopt)) / 1000000;
+ LOGF("JSC_EXEC_ADOPT_TIME: %lf", durationAdopt);
SystraceSection s_("JSCExecutor::loadApplicationScript-evaluateScript");
+ auto startEval = getTimeNsec();
evaluateScript(m_context, jsScript, jsSourceURL);
+ auto endEval = getTimeNsec();
+ double durationEval = ((double) (endEval - startEval)) / 1000000;
+ LOGF("JSC_EXEC_EVAL_TIME: %lf", durationEval);
}
+ auto endLoad = getTimeNsec();
+ double durationLoad = ((double) (endLoad - startLoad)) / 1000000;
+ LOGF("JSC_EXEC_TOTAL_LOAD_TIME: %lf", durationLoad);
+
flush();
ReactMarker::logMarker(ReactMarker::CREATE_REACT_CONTEXT_STOP);
--
2.7.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment