-
-
Notifications
You must be signed in to change notification settings - Fork 140
How to profile JavaScript
Note: this functionality may change in future
NativeScript runtime for Android provides __startCPUProfiler and __stopCPUProfiler global functions which help you to profile your JavaScript code. To enable these methods you need to set the profilerOutputDir key in your app/package.json next to v8Flags inside the android section:
{
"android": {
"v8Flags": "--expose_gc",
"profilerOutputDir": "/sdcard/"
},
"main": "main.js",
...
}
Here is an example usage:
__startCPUProfiler("myprofile");
// some JavaScript code
__stopCPUProfiler("myprofile");This will create a new file with the following naming scheme /sdcard/<package name>-<profile>-<timestamp>.cpuprofile. For example, if your application package name is org.nativescript.app1 then the output file will be named something like org.nativescript.app1-myprofile-19388793.672149.cpuprofile. Once you have a *.cpuprofile file you can pull it from the device with adb pull command. In our case the command will be:
adb pull /sdcard/org.nativescript.app1-myprofile-19388793.672149.cpuprofileNOTE: If there is not
.cpuprofilefile generated - try giving the app thestoragepermission explicitly by going tosettings -> app -> <myapp> -> permissionand enable thestoragepermission.
Then you can load the file with Chrome DevTools.