Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

CPU Profiling #8

Closed
yunong opened this issue Jan 19, 2016 · 12 comments
Closed

CPU Profiling #8

yunong opened this issue Jan 19, 2016 · 12 comments
Assignees

Comments

@yunong
Copy link
Member

yunong commented Jan 19, 2016

Is there support for profiling of JS stack frames in Chakra? With the V8 engine, you could profile the stack frames at runtime. This is critical as it allows us to objectively observe, compare, and profile the CPU usage of our process. This is possible in both Linux (http://yunong.io/2015/11/23/generating-node-js-flame-graphs/) and Illumos (https://nodejs.org/en/blog/uncategorized/profiling-node-js/)

@brendangregg
Copy link

Perhaps one can do this using the profile provider from Windows DTrace? https://github.com/prash-wghats/DTrace-win32

For Linux perf_events, if frame pointers work, then it's just a matter of dumping a /tmp/perf-PID.map file for the symbol lookups (http://www.brendangregg.com/blog/2014-09-17/node-flame-graphs-on-linux.html).

@MikeHolman
Copy link
Contributor

Chakra registers js stack frames with ETW, so you can use any tool which reads this. I would recommend using tools WPR and WPA (included in the Windows SDK). It has a bit of a learning curve, but is very powerful!

@kunalspathak
Copy link
Member

Chakra registers js stack frames with ETW,

Chakra do register js stack frames, but Chakracore doesn't. So if you want to get profiling information, you might need node+chakra that runs with chakra.dll on your windows 8.1+ machines.
Using that and tools like WPA/WPR that @MikeHolman pointed out, you can record the ETW events and see it, something like this:

image

@MikeHolman
Copy link
Contributor

@kunalspathak Ah didn't realize this isn't supported in ChakraCore. I've opened chakra-core/ChakraCore#328 to discuss possibility of adding this.

kunalspathak added a commit to kunalspathak/node-chakracore that referenced this issue Jun 29, 2016
Chakra returns JsErrorOutOfMemory error code that shim ignores and doesn't
propagate to the user. Added jsrt helper SetOutOfMemoryErrorIfExist
that will check for the error code JsErrorOutOfMemory after function call,
running and parsing script. If this error code was returned, then set the
exception on the context which will be verified by subsequent try_catch.

Reviewed-By: jianchun

Fix nodejs#8
@digitalinfinity
Copy link
Contributor

@kunalspathak we should revisit this issue now that ChakraCore has ETW support.

@kunalspathak
Copy link
Member

I will play around with this when i get chance and update this issue with the instructions on how to use it. Note that this will not be usable until we bring ETW change into nodejs/chakracore-master.

@kfarnung
Copy link
Contributor

Windows has support for this and @MSLaguana is looking into adding support for Linux.

@MSLaguana
Copy link
Contributor

Node-chakracore now has support for JITted frames in ETW on windows, and using the linux perf tool on linux/mac. For the non-windows cases currently you need to compile the support in by defining =PERFMAP_TRACE_ENABLED=1, which will register a signal handler for SIGUSR2 (or another signal if you provide another define). When that signal handler is triggered, it will write out a file /tmp/perf-<pid>.map which can be parsed by the perf tool to give names to JIT compiled frames.

@yunong
Copy link
Member Author

yunong commented Sep 7, 2017

@MSLaguana This is great! Thanks so much for adding this, Chakra is definitely a step ahead of the competition when it comes to CPU profiling. Is it possible to provide a default signal and make this part of the default distribution of Chakra? This would then enable CPU profiling right out of the box for everyone.

@MSLaguana
Copy link
Contributor

I had considered that, but the number of available signals is fairly low, and node is already using sigusr1 so if I also caused node-chakracore to use sigusr2 as well then apps would have no signals left that they could override themselves. I discussed it with @digitalinfinity but I'm not sure we'd come to a solid conclusion either way.

@digitalinfinity
Copy link
Contributor

@yunong however we're still relatively new to the Linux world, so if you have thoughts on what the default behavior should be, we'd love to know! Right now, our thinking is that opt-in is the way to go, and maybe we can make it opt-in at runtime (perhaps with some form of signal-chaining?), but if you have some insight on how we should make it on by default without inconveniencing embedders, we're all ears!

@yunong
Copy link
Member Author

yunong commented Sep 8, 2017

@digitalinfinity What about providing a runtime argument to Chakra that can opt into this without having to recompile? Let me also chat with some folks at Netflix and get back to you with some possible other solutions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants