diff --git a/test-app/app/src/main/assets/app/package.json b/test-app/app/src/main/assets/app/package.json index 12e844166..149463fc3 100644 --- a/test-app/app/src/main/assets/app/package.json +++ b/test-app/app/src/main/assets/app/package.json @@ -7,6 +7,7 @@ "memoryCheckInterval": 10, "freeMemoryRatio": 0.50, "markingMode": "full", - "maxLogcatObjectSize": 1024 + "maxLogcatObjectSize": 1024, + "forceLog": false } } \ No newline at end of file diff --git a/test-app/runtime/src/main/cpp/Runtime.cpp b/test-app/runtime/src/main/cpp/Runtime.cpp index f9eb748bb..e88d36c0c 100644 --- a/test-app/runtime/src/main/cpp/Runtime.cpp +++ b/test-app/runtime/src/main/cpp/Runtime.cpp @@ -148,17 +148,17 @@ ObjectManager* Runtime::GetObjectManager() const { return m_objectManager; } -void Runtime::Init(JNIEnv* _env, jobject obj, int runtimeId, jstring filesPath, jstring nativeLibDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize) { +void Runtime::Init(JNIEnv* _env, jobject obj, int runtimeId, jstring filesPath, jstring nativeLibDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize, bool forceLog) { JEnv env(_env); auto runtime = new Runtime(env, obj, runtimeId); auto enableLog = verboseLoggingEnabled == JNI_TRUE; - runtime->Init(filesPath, nativeLibDir, enableLog, isDebuggable, packageName, args, callingDir, maxLogcatObjectSize); + runtime->Init(filesPath, nativeLibDir, enableLog, isDebuggable, packageName, args, callingDir, maxLogcatObjectSize, forceLog); } -void Runtime::Init(jstring filesPath, jstring nativeLibDir, bool verboseLoggingEnabled, bool isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize) { +void Runtime::Init(jstring filesPath, jstring nativeLibDir, bool verboseLoggingEnabled, bool isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize, bool forceLog) { LogEnabled = verboseLoggingEnabled; auto filesRoot = ArgConverter::jstringToString(filesPath); @@ -183,7 +183,7 @@ void Runtime::Init(jstring filesPath, jstring nativeLibDir, bool verboseLoggingE auto profilerOutputDirStr = ArgConverter::jstringToString(profilerOutputDir); NativeScriptException::Init(m_objectManager); - m_isolate = PrepareV8Runtime(filesRoot, nativeLibDirStr, packageNameStr, isDebuggable, callingDirStr, profilerOutputDirStr, maxLogcatObjectSize); + m_isolate = PrepareV8Runtime(filesRoot, nativeLibDirStr, packageNameStr, isDebuggable, callingDirStr, profilerOutputDirStr, maxLogcatObjectSize, forceLog); s_isolate2RuntimesCache.insert(make_pair(m_isolate, this)); } @@ -408,7 +408,7 @@ static void InitializeV8() { V8::Initialize(); } -Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& nativeLibDir, const string& packageName, bool isDebuggable, const string& callingDir, const string& profilerOutputDir, const int maxLogcatObjectSize) { +Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& nativeLibDir, const string& packageName, bool isDebuggable, const string& callingDir, const string& profilerOutputDir, const int maxLogcatObjectSize, const bool forceLog) { tns::instrumentation::Frame frame("Runtime.PrepareV8Runtime"); Isolate::CreateParams create_params; @@ -611,9 +611,9 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native } #ifdef APPLICATION_IN_DEBUG - v8::Local console = Console::createConsole(context, JsV8InspectorClient::consoleLogCallback, maxLogcatObjectSize); + v8::Local console = Console::createConsole(context, JsV8InspectorClient::consoleLogCallback, maxLogcatObjectSize, forceLog); #else - v8::Local console = Console::createConsole(context, nullptr, maxLogcatObjectSize); + v8::Local console = Console::createConsole(context, nullptr, maxLogcatObjectSize, forceLog); #endif /* diff --git a/test-app/runtime/src/main/cpp/Runtime.h b/test-app/runtime/src/main/cpp/Runtime.h index b4aa72254..af102ddf4 100644 --- a/test-app/runtime/src/main/cpp/Runtime.h +++ b/test-app/runtime/src/main/cpp/Runtime.h @@ -29,11 +29,12 @@ class Runtime { static void Init(JavaVM* vm, void* reserved); - static void Init(JNIEnv* _env, jobject obj, int runtimeId, jstring filesPath, jstring nativeLibsDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize); + static void Init(JNIEnv* _env, jobject obj, int runtimeId, jstring filesPath, jstring nativeLibsDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize, + bool forceLog); static void SetManualInstrumentationMode(jstring mode); - void Init(jstring filesPath, jstring nativeLibsDir, bool verboseLoggingEnabled, bool isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize); + void Init(jstring filesPath, jstring nativeLibsDir, bool verboseLoggingEnabled, bool isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize, bool forceLog); v8::Isolate* GetIsolate() const; @@ -83,7 +84,7 @@ class Runtime { v8::Persistent* m_gcFunc; volatile bool m_runGC; - v8::Isolate* PrepareV8Runtime(const std::string& filesPath, const std::string& nativeLibsDir, const std::string& packageName, bool isDebuggable, const std::string& callingDir, const std::string& profilerOutputDir, const int maxLogcatObjectSize); + v8::Isolate* PrepareV8Runtime(const std::string& filesPath, const std::string& nativeLibsDir, const std::string& packageName, bool isDebuggable, const std::string& callingDir, const std::string& profilerOutputDir, const int maxLogcatObjectSize, const bool forceLog); jobject ConvertJsValueToJavaObject(JEnv& env, const v8::Local& value, int classReturnType); static int GetAndroidVersion(); static int m_androidVersion; diff --git a/test-app/runtime/src/main/cpp/com_tns_Runtime.cpp b/test-app/runtime/src/main/cpp/com_tns_Runtime.cpp index 67a27e9e1..cf4163c8a 100644 --- a/test-app/runtime/src/main/cpp/com_tns_Runtime.cpp +++ b/test-app/runtime/src/main/cpp/com_tns_Runtime.cpp @@ -34,9 +34,9 @@ extern "C" JNIEXPORT void Java_com_tns_Runtime_SetManualInstrumentationMode(JNIE } } -extern "C" JNIEXPORT void Java_com_tns_Runtime_initNativeScript(JNIEnv* _env, jobject obj, jint runtimeId, jstring filesPath, jstring nativeLibDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, jint maxLogcatObjectSize) { +extern "C" JNIEXPORT void Java_com_tns_Runtime_initNativeScript(JNIEnv* _env, jobject obj, jint runtimeId, jstring filesPath, jstring nativeLibDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, jint maxLogcatObjectSize, jboolean forceLog) { try { - Runtime::Init(_env, obj, runtimeId, filesPath, nativeLibDir, verboseLoggingEnabled, isDebuggable, packageName, args, callingDir, maxLogcatObjectSize); + Runtime::Init(_env, obj, runtimeId, filesPath, nativeLibDir, verboseLoggingEnabled, isDebuggable, packageName, args, callingDir, maxLogcatObjectSize, forceLog); } catch (NativeScriptException& e) { e.ReThrowToJava(); } catch (std::exception e) { diff --git a/test-app/runtime/src/main/cpp/console/Console.cpp b/test-app/runtime/src/main/cpp/console/Console.cpp index e2be6a142..dab68ad4e 100644 --- a/test-app/runtime/src/main/cpp/console/Console.cpp +++ b/test-app/runtime/src/main/cpp/console/Console.cpp @@ -15,9 +15,10 @@ namespace tns { -v8::Local Console::createConsole(v8::Local context, ConsoleCallback callback, const int maxLogcatObjectSize) { +v8::Local Console::createConsole(v8::Local context, ConsoleCallback callback, const int maxLogcatObjectSize, const bool forceLog) { m_callback = callback; m_maxLogcatObjectSize = maxLogcatObjectSize; + m_forceLog = forceLog; v8::Context::Scope contextScope(context); v8::Isolate* isolate = context->GetIsolate(); @@ -165,7 +166,7 @@ const std::string buildLogString(const v8::FunctionCallbackInfo& info } void Console::assertCallback(const v8::FunctionCallbackInfo& info) { - if (!isApplicationInDebug) { + if (!shouldLog()) { return; } try { @@ -203,7 +204,7 @@ void Console::assertCallback(const v8::FunctionCallbackInfo& info) { } void Console::errorCallback(const v8::FunctionCallbackInfo & info) { - if (!isApplicationInDebug) { + if (!shouldLog()) { return; } try { @@ -225,7 +226,7 @@ void Console::errorCallback(const v8::FunctionCallbackInfo & info) { } void Console::infoCallback(const v8::FunctionCallbackInfo& info) { - if (!isApplicationInDebug) { + if (!shouldLog()) { return; } try { @@ -247,7 +248,7 @@ void Console::infoCallback(const v8::FunctionCallbackInfo& info) { } void Console::logCallback(const v8::FunctionCallbackInfo& info) { - if (!isApplicationInDebug) { + if (!shouldLog()) { return; } try { @@ -269,7 +270,7 @@ void Console::logCallback(const v8::FunctionCallbackInfo& info) { } void Console::warnCallback(const v8::FunctionCallbackInfo& info) { - if (!isApplicationInDebug) { + if (!shouldLog()) { return; } try { @@ -291,7 +292,7 @@ void Console::warnCallback(const v8::FunctionCallbackInfo& info) { } void Console::dirCallback(const v8::FunctionCallbackInfo& info) { - if (!isApplicationInDebug) { + if (!shouldLog()) { return; } try { @@ -408,7 +409,7 @@ const std::string buildStacktraceFrameMessage(v8::Local frame) { } void Console::traceCallback(const v8::FunctionCallbackInfo& info) { - if (!isApplicationInDebug) { + if (!shouldLog()) { return; } try { @@ -454,7 +455,7 @@ void Console::traceCallback(const v8::FunctionCallbackInfo& info) { } void Console::timeCallback(const v8::FunctionCallbackInfo& info) { - if (!isApplicationInDebug) { + if (!shouldLog()) { return; } try { @@ -493,7 +494,7 @@ void Console::timeCallback(const v8::FunctionCallbackInfo& info) { } void Console::timeEndCallback(const v8::FunctionCallbackInfo& info) { - if (!isApplicationInDebug) { + if (!shouldLog()) { return; } try { @@ -555,6 +556,7 @@ const char* Console::LOG_TAG = "JS"; std::map> Console::s_isolateToConsoleTimersMap; ConsoleCallback Console::m_callback = nullptr; int Console::m_maxLogcatObjectSize; +bool Console::m_forceLog; #ifdef APPLICATION_IN_DEBUG bool Console::isApplicationInDebug = true; diff --git a/test-app/runtime/src/main/cpp/console/Console.h b/test-app/runtime/src/main/cpp/console/Console.h index 1aa7680c1..5b55c0c7f 100644 --- a/test-app/runtime/src/main/cpp/console/Console.h +++ b/test-app/runtime/src/main/cpp/console/Console.h @@ -15,7 +15,7 @@ typedef void (*ConsoleCallback)(const std::string& message, const std::string& l class Console { public: - static v8::Local createConsole(v8::Local context, ConsoleCallback callback, const int maxLogcatObjectSize); + static v8::Local createConsole(v8::Local context, ConsoleCallback callback, const int maxLogcatObjectSize, const bool forceLog); static void assertCallback(const v8::FunctionCallbackInfo& info); static void errorCallback(const v8::FunctionCallbackInfo& info); @@ -29,11 +29,15 @@ class Console { private: static int m_maxLogcatObjectSize; + static bool m_forceLog; static ConsoleCallback m_callback; static const char* LOG_TAG; static std::map> s_isolateToConsoleTimersMap; static bool isApplicationInDebug; + static bool shouldLog() { + return m_forceLog || isApplicationInDebug; + } // heavily inspired by 'createBoundFunctionProperty' of V8's v8-console.h static void bindFunctionProperty(v8::Local context, diff --git a/test-app/runtime/src/main/java/com/tns/AppConfig.java b/test-app/runtime/src/main/java/com/tns/AppConfig.java index 0872d7ad7..9e3b55955 100644 --- a/test-app/runtime/src/main/java/com/tns/AppConfig.java +++ b/test-app/runtime/src/main/java/com/tns/AppConfig.java @@ -18,7 +18,8 @@ protected enum KnownKeys { Profiling("profiling", ""), MarkingMode("markingMode", com.tns.MarkingMode.full), HandleTimeZoneChanges("handleTimeZoneChanges", false), - MaxLogcatObjectSize("maxLogcatObjectSize", 1024); + MaxLogcatObjectSize("maxLogcatObjectSize", 1024), + ForceLog("forceLog", false); private final String name; private final Object defaultValue; @@ -108,6 +109,9 @@ public AppConfig(File appDir) { if (androidObject.has(KnownKeys.MaxLogcatObjectSize.getName())) { values[KnownKeys.MaxLogcatObjectSize.ordinal()] = androidObject.getInt(KnownKeys.MaxLogcatObjectSize.getName()); } + if (androidObject.has(KnownKeys.ForceLog.getName())) { + values[KnownKeys.ForceLog.ordinal()] = androidObject.getBoolean(KnownKeys.ForceLog.getName()); + } } } } catch (Exception e) { @@ -154,4 +158,8 @@ public boolean handleTimeZoneChanges() { public int getMaxLogcatObjectSize() { return (int)values[KnownKeys.MaxLogcatObjectSize.ordinal()]; } + + public boolean getForceLog() { + return (boolean)values[KnownKeys.ForceLog.ordinal()]; + } } diff --git a/test-app/runtime/src/main/java/com/tns/Runtime.java b/test-app/runtime/src/main/java/com/tns/Runtime.java index fd71d384a..4540660b4 100644 --- a/test-app/runtime/src/main/java/com/tns/Runtime.java +++ b/test-app/runtime/src/main/java/com/tns/Runtime.java @@ -32,7 +32,7 @@ import com.tns.bindings.ProxyGenerator; public class Runtime { - private native void initNativeScript(int runtimeId, String filesPath, String nativeLibDir, boolean verboseLoggingEnabled, boolean isDebuggable, String packageName, Object[] v8Options, String callingDir, int maxLogcatObjectSize); + private native void initNativeScript(int runtimeId, String filesPath, String nativeLibDir, boolean verboseLoggingEnabled, boolean isDebuggable, String packageName, Object[] v8Options, String callingDir, int maxLogcatObjectSize, boolean forceLog); private native void runModule(int runtimeId, String filePath) throws NativeScriptException; @@ -490,7 +490,10 @@ private void init(Logger logger, String appName, String nativeLibDir, File rootD throw new RuntimeException("Fail to initialize Require class", ex); } - initNativeScript(getRuntimeId(), Module.getApplicationFilesPath(), nativeLibDir, logger.isEnabled(), isDebuggable, appName, appConfig.getAsArray(), callingJsDir, appConfig.getMaxLogcatObjectSize()); + boolean forceConsoleLog = appConfig.getForceLog() || "timeline".equalsIgnoreCase(appConfig.getProfilingMode()); + + initNativeScript(getRuntimeId(), Module.getApplicationFilesPath(), nativeLibDir, logger.isEnabled(), isDebuggable, appName, appConfig.getAsArray(), + callingJsDir, appConfig.getMaxLogcatObjectSize(), forceConsoleLog); //clearStartupData(getRuntimeId()); // It's safe to delete the data after the V8 debugger is initialized