Skip to content

Conversation

PanayotCankov
Copy link
Contributor

Setting in app/package.json a:

{
  "main": "main.js",
  "profiling": "timeline"
}

Will enable tracing of slow manually instrumented methods.
The facility can trace both java and cpp frames, there is already a matching implementation in the modules. The complete feature lets us profile and trace times in cpp java and js in a single timeline.

@ns-bot
Copy link

ns-bot commented Jun 5, 2017

💚

… where the runtime block the JavaScript thread

Log all c++ frames, log some key methods in Java

Add package.json "profiling": "timeline" option to enable the logging of the manual instrumentation profiling
@PanayotCankov PanayotCankov force-pushed the display-blocking-js branch from 225be73 to 5ef6e8d Compare June 6, 2017 07:33
@ns-bot
Copy link

ns-bot commented Jun 6, 2017

💚

StaticConfiguration config = new StaticConfiguration(logger, appName, nativeLibDir, rootDir,
appDir, classLoader, dexDir, dexThumb, appConfig, isDebuggable);
AppConfig appConfig = new AppConfig(appDir);
switch (appConfig.getProfilingMode()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following lines concerning instrumentation can be moved to the ManualInstrumentation class in a method you call from RuntimeHelper

// Created by Panayot Cankov on 26/05/2017.
//

#ifndef TEST_APP_MANUALINSTRUMENTATION_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the TEST_APP_ prefix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

#include "ManualInstrumentation.h"

bool tns::instrumentation::Frame::disabled = true;
const std::chrono::steady_clock::time_point tns::instrumentation::Frame::disabled_time = std::chrono::steady_clock::now();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::chrono::steady_clock::time_point(); - the empty constructor defaults to duration::zero which should be good enough for a "disabled" value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

void MetadataNode::ExtendedClassConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
TNSPERF();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between using the TNSPERF macro and tns::instrumentation::Frame constructor? Can we make it consistent across the runtime code, and use just one of the two?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TNSPERF uses __func__ for name and is nothing but a shorthand for tns::instrumentation::Frame frame(__func__);

}

string moduleName = ArgConverter::ConvertToString(args[0].As<String>());
string frameName("RequireCallback " + moduleName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be inlined with the constructor on the following line? Or rename the frameName variable accordingly so that it becomes clear the RequireCallback moduleName string isn't part of the require logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tns::instrumentation::Frame frame(("RequireCallback " + moduleName).c_str());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string("RequireCallback " + moduleName).c_str() for readability

auto cls = fromJsInfo->ObjectClazz;
JEnv env;
jclass clsClazz = env.GetObjectClass(cls);
jmethodID methodId = env.GetMethodID(clsClazz, "getSimpleName", "()Ljava/lang/String;");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider caching the jclass and jmethodID in static variables in the Frame class if the frame.check() passes (profiling is enabled)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have GET_NAME_METHOD_ID handy at scope, I will reuse it instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along with m_env instead of new JEnv env?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    if (frame.check()) {
        auto cls = fromJsInfo->ObjectClazz;
        jclass clsClazz = m_env.GetObjectClass(cls);
        jstring className = (jstring) m_env.CallObjectMethod(cls, GET_NAME_METHOD_ID);
        frame.log(("MarkReachableObjects: " + ArgConverter::jstringToString(className)).c_str());
    }

Copy link
Contributor Author

@PanayotCankov PanayotCankov Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably frame.log needs a string& override

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a good idea, it will call internally to frame.log(char *)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for the constructor

jclass clsClazz = env.GetObjectClass(cls);
jmethodID methodId = env.GetMethodID(clsClazz, "getSimpleName", "()Ljava/lang/String;");
jstring className = (jstring) env.CallObjectMethod(cls, methodId);
const char* str = env.GetStringUTFChars(className, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 527, 528, 530 can be replaced with the following
auto jsObjClassName = "MarkReachableObjects: " + ArgConverter::jstringToString(className);

@PanayotCankov
Copy link
Contributor Author

@Pip3r4o most of the comments have been addressed (except the macro I think) could you take a look on the changes after the second commit?

@ns-bot
Copy link

ns-bot commented Jun 6, 2017

💚

@petekanev
Copy link
Contributor

Good job!

@PanayotCankov PanayotCankov merged commit d38f4f4 into master Jun 7, 2017
@PanayotCankov PanayotCankov deleted the display-blocking-js branch June 7, 2017 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants