Skip to content

Commit 3f67853

Browse files
committed
Addres peer review
1 parent 5ef6e8d commit 3f67853

File tree

8 files changed

+33
-40
lines changed

8 files changed

+33
-40
lines changed

build-artifacts/project-template-gradle/src/main/java/com/tns/RuntimeHelper.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,7 @@ public static Runtime initRuntime(Application app) {
119119
}
120120

121121
AppConfig appConfig = new AppConfig(appDir);
122-
switch (appConfig.getProfilingMode()) {
123-
case "timeline":
124-
ManualInstrumentation.setMode(ManualInstrumentation.Mode.Timeline);
125-
break;
126-
default:
127-
ManualInstrumentation.setMode(ManualInstrumentation.Mode.Disabled);
128-
}
129-
Runtime.SetManualInstrumentationMode(appConfig.getProfilingMode());
122+
ManualInstrumentation.setMode(appConfig.getProfilingMode());
130123

131124
ClassLoader classLoader = app.getClassLoader();
132125
File dexDir = new File(rootDir, "code_cache/secondary-dexes");

runtime/src/main/java/com/tns/ManualInstrumentation.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
public class ManualInstrumentation {
1111
private static Mode mode = Mode.Pending;
1212

13+
public static void setMode(String mode) {
14+
switch (mode) {
15+
case "timeline":
16+
ManualInstrumentation.setMode(ManualInstrumentation.Mode.Timeline);
17+
break;
18+
default:
19+
ManualInstrumentation.setMode(ManualInstrumentation.Mode.Disabled);
20+
}
21+
Runtime.SetManualInstrumentationMode(mode);
22+
}
23+
1324
public static void setMode(Mode mode) {
1425
if (ManualInstrumentation.mode == Mode.Pending) {
1526
switch(mode) {

runtime/src/main/jni/ManualInstrumentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
#include "ManualInstrumentation.h"
66

77
bool tns::instrumentation::Frame::disabled = true;
8-
const std::chrono::steady_clock::time_point tns::instrumentation::Frame::disabled_time = std::chrono::steady_clock::now();
8+
const std::chrono::steady_clock::time_point tns::instrumentation::Frame::disabled_time = std::chrono::steady_clock::time_point();

runtime/src/main/jni/ManualInstrumentation.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
// Created by Panayot Cankov on 26/05/2017.
33
//
44

5-
#ifndef TEST_APP_MANUALINSTRUMENTATION_H
6-
#define TEST_APP_MANUALINSTRUMENTATION_H
5+
#ifndef MANUALINSTRUMENTATION_H
6+
#define MANUALINSTRUMENTATION_H
77

88
#include "v8.h"
99
#import <chrono>
1010
#import <NativeScriptAssert.h>
11+
#include <string>
1112

1213
namespace tns {
1314
namespace instrumentation {
1415
class Frame {
1516
public:
16-
inline Frame() : Frame(nullptr) { }
17-
inline Frame(const char *name) : name(name), start(disabled ? disabled_time : std::chrono::steady_clock::now()) {}
17+
inline Frame() : Frame("") { }
18+
inline Frame(std::string name) : name(name), start(disabled ? disabled_time : std::chrono::steady_clock::now()) {}
1819

1920
inline ~Frame() {
20-
if (name && check()) {
21+
if (!name.empty() && check()) {
2122
log(name);
2223
}
2324
}
@@ -42,6 +43,10 @@ namespace tns {
4243
__android_log_print(ANDROID_LOG_DEBUG, "JS", "Timeline: %.3fms: Runtime: %s (%.3fms - %.3fms)", duration / 1000.0, message, startMilis, endMilis);
4344
}
4445

46+
inline void log(const std::string& message) {
47+
log(message.c_str());
48+
}
49+
4550
static inline void enable() { disabled = false; }
4651
static inline void disable() { disabled = true; }
4752

@@ -50,7 +55,7 @@ namespace tns {
5055
static const std::chrono::steady_clock::time_point disabled_time; // Couldn't find reasonable constant
5156

5257
const std::chrono::steady_clock::time_point start;
53-
const char *name;
58+
const std::string name;
5459

5560
Frame(const Frame &) = delete;
5661
Frame &operator=(const Frame &) = delete;
@@ -63,4 +68,4 @@ namespace tns {
6368
*/
6469
#define TNSPERF() tns::instrumentation::Frame __tns_manual_instrumentation(__func__)
6570

66-
#endif //TEST_APP_MANUALINSTRUMENTATION_H
71+
#endif //MANUALINSTRUMENTATION_H

runtime/src/main/jni/MetadataNode.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,7 @@ Local<FunctionTemplate> MetadataNode::GetConstructorFunctionTemplate(Isolate* is
756756
SetTypeMetadata(isolate, wrappedCtorFunc, new TypeMetadata(s_metadataReader.ReadTypeName(treeNode)));
757757

758758
if (frame.check()) {
759-
std::string log = "Materizlizing class: " + node->m_name;
760-
frame.log(log.c_str());
759+
frame.log("Materizlizing class: " + node->m_name);
761760
}
762761

763762
return ctorFuncTemplate;
@@ -896,8 +895,7 @@ void MetadataNode::InterfaceConstructorCallback(const v8::FunctionCallbackInfo<v
896895
auto success = CallbackHandlers::RegisterInstance(isolate, thiz, className, argWrapper, implementationObject, true);
897896

898897
if (frame.check()) {
899-
std::string msg = "Interface constructor: " + node->m_name;
900-
frame.log(msg.c_str());
898+
frame.log("Interface constructor: " + node->m_name);
901899
}
902900
} catch (NativeScriptException& e) {
903901
e.ReThrowToV8();
@@ -1377,8 +1375,7 @@ void MetadataNode::ExtendMethodCallback(const v8::FunctionCallbackInfo<v8::Value
13771375
cache->ExtendedCtorFuncCache.insert(make_pair(fullExtendedName, cacheData));
13781376

13791377
if (frame.check()) {
1380-
std::string msg = "Extending: " + node->m_name;
1381-
frame.log(msg.c_str());
1378+
frame.log("Extending: " + node->m_name);
13821379
}
13831380
} catch (NativeScriptException& e) {
13841381
e.ReThrowToV8();

runtime/src/main/jni/ModuleInternal.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ void ModuleInternal::RequireCallbackImpl(const v8::FunctionCallbackInfo<v8::Valu
157157
}
158158

159159
string moduleName = ArgConverter::ConvertToString(args[0].As<String>());
160-
string frameName("RequireCallback " + moduleName);
161-
tns::instrumentation::Frame frame(frameName.c_str());
160+
tns::instrumentation::Frame frame(("RequireCallback " + moduleName).c_str());
162161
string callingModuleDirName = ArgConverter::ConvertToString(args[1].As<String>());
163162
auto isData = false;
164163

runtime/src/main/jni/ObjectManager.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,9 @@ void ObjectManager::MarkReachableObjects(Isolate* isolate, const Local<Object>&
520520

521521
if (frame.check()) {
522522
auto cls = fromJsInfo->ObjectClazz;
523-
JEnv env;
524-
jclass clsClazz = env.GetObjectClass(cls);
525-
jmethodID methodId = env.GetMethodID(clsClazz, "getSimpleName", "()Ljava/lang/String;");
526-
jstring className = (jstring) env.CallObjectMethod(cls, methodId);
527-
const char* str = env.GetStringUTFChars(className, NULL);
528-
auto jsObjClassName = "MarkReachableObjects: " + std::string(str);
529-
frame.log(jsObjClassName.c_str());
530-
env.ReleaseStringUTFChars(className, str);
523+
jclass clsClazz = m_env.GetObjectClass(cls);
524+
jstring className = (jstring) m_env.CallObjectMethod(cls, GET_NAME_METHOD_ID);
525+
frame.log("MarkReachableObjects: " + ArgConverter::jstringToString(className));
531526
}
532527
}
533528

test-app/app/src/main/java/com/tns/RuntimeHelper.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,7 @@ public static Runtime initRuntime(Application app) {
119119
}
120120

121121
AppConfig appConfig = new AppConfig(appDir);
122-
switch (appConfig.getProfilingMode()) {
123-
case "timeline":
124-
ManualInstrumentation.setMode(ManualInstrumentation.Mode.Timeline);
125-
break;
126-
default:
127-
ManualInstrumentation.setMode(ManualInstrumentation.Mode.Disabled);
128-
}
129-
Runtime.SetManualInstrumentationMode(appConfig.getProfilingMode());
122+
ManualInstrumentation.setMode(appConfig.getProfilingMode());
130123

131124
ClassLoader classLoader = app.getClassLoader();
132125
File dexDir = new File(rootDir, "code_cache/secondary-dexes");

0 commit comments

Comments
 (0)