Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis
Created January 25, 2013 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnoordhuis/4638749 to your computer and use it in GitHub Desktop.
Save bnoordhuis/4638749 to your computer and use it in GitHub Desktop.
Print real-time V8 JIT code events.
diff --git a/src/node.cc b/src/node.cc
index 32cff12..3c5b616 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -2954,6 +2954,36 @@ static char **copy_argv(int argc, char **argv) {
return argv_copy;
}
+
+static void OnJitCodeEvent(const JitCodeEvent* event) {
+ switch (event->type) {
+ case JitCodeEvent::CODE_ADDED:
+ printf("CODE_ADDED code_start=%p code_len=%zu name=\"%.*s\"\n",
+ event->code_start,
+ event->code_len,
+ (int) event->name.len,
+ event->name.str);
+ break;
+
+ case JitCodeEvent::CODE_MOVED:
+ printf("CODE_MOVED code_start=%p code_len=%zu new_code_start=%p\n",
+ event->code_start,
+ event->code_len,
+ event->new_code_start);
+ break;
+
+ case JitCodeEvent::CODE_REMOVED:
+ printf("CODE_REMOVED code_start=%p code_len=%zu\n",
+ event->code_start,
+ event->code_len);
+ break;
+
+ default:
+ ; // Ignore.
+ }
+}
+
+
int Start(int argc, char *argv[]) {
// Hack aroung with the argv pointer. Used for process.title = "blah".
argv = uv_setup_args(argc, argv);
@@ -2967,6 +2997,7 @@ int Start(int argc, char *argv[]) {
Init(argc, argv_copy);
V8::Initialize();
+ V8::SetJitCodeEventHandler(kJitCodeEventEnumExisting, OnJitCodeEvent);
{
Locker locker;
HandleScope handle_scope;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment