2011-10-03

How to profile JIT code with VTune

I wrote the way to profile JIT code with CodeAnalyst before. Here, I write how to profile it with VTune.

If you profile a program using JIT code, then VTune can't know about it.


The Function "[Unknown stack frame(s)]" in this screenshot shows a JIT code, but VTune can't go into details.

So, lets' tell VTune the information of JIT code by calling VTune's API.

At first, include "jitprofiling.h" in /Intel/VTune Amplifier XE/include and link some libraries.


#include "jitprofiling.h"
#pragma comment(lib, "libittnotify.lib")
#pragma comment(lib, "jitprofiling.lib")

Next, make an utility function to register a JIT code as following:

void SetJitCode(void *ptr, size_t size, const char *name)
{
  iJIT_Method_Load jmethod = {0};
  jmethod.method_id = iJIT_GetNewMethodID();
  jmethod.class_file_name = "";
  jmethod.source_file_name = __FILE__;

  jmethod.method_load_address = ptr;
  jmethod.method_size = size;
  jmethod.line_number_size = 0;

  jmethod.method_name = const_cast(name);
  int ret = iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void*)&jmethod);
  printf("iJIT_NotifyEvent ret=%d\n", ret);
}

Call SetJitCode with a pointer of JIT function, size of it and name in your code.

Finaly, call iJIT_NotifyEvent(iJVM_EVENT_TYPE_SHUTDOWN, NULL); to notify VTune about the end of profiling.


Profile the modified program with VTune, then we can get the following results:



The area of "[Unknown stack frame(s)]" splits into some different functions such as "Fp2Dbl::mod", "Fp2Dbl::mulOpt2" and so on.
Moreover, we can see the generated assembly code of these functions.

 

I write a sample code for JIT profiling.
Please see prof.cpp and mkprof.bat.