- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am able to profile native code which is being called from java code. But I could not able to profile java code which is being called from native code.
I have written a win32 application in Delphi. This application calls java methods using JNI. I want to find hotspots in both Delphi code and java code.
Friends please suggest me how to do this.
regards,
prasad.
I am able to profile native code which is being called from java code. But I could not able to profile java code which is being called from native code.
I have written a win32 application in Delphi. This application calls java methods using JNI. I want to find hotspots in both Delphi code and java code.
Friends please suggest me how to do this.
regards,
prasad.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
To load the profiler dll with the JVM you need to specify "-Xrunjavaperf" in the options field of the JavaVMInitArgs structure when you load the JVM.
(for call graph you need to specify "-Xrunjavaperf:cg")
I'll demonstrate it in C++ sample, but I guess it's the same for Delphi:
#include
#define USER_CLASSPATH "." /* where Prog.class is */
main() {
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
jint res;
JavaVMOption options[2];
options[0].optionString = "-Xrunjavaperf:cg";
options[1].optionString = "-Djava.class.path=" USER_CLASSPATH;
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 2;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (res < 0) {
printf("Error loading VM!! ");
return 1;
}
jclass cls = env->FindClass("JNITest");
jmethodID mid = env->GetStaticMethodID(cls, "test", "()V");
env->CallStaticVoidMethod(cls, mid);
jvm->DestroyJavaVM();
return 0;
}
I tried it with sun JVM 1.4.2 and I had segmentation fault, but with BEA JRockit 8.1 sp1 and IBM 1.3.1 it worked fine.
I hope it answer your question.
To load the profiler dll with the JVM you need to specify "-Xrunjavaperf" in the options field of the JavaVMInitArgs structure when you load the JVM.
(for call graph you need to specify "-Xrunjavaperf:cg")
I'll demonstrate it in C++ sample, but I guess it's the same for Delphi:
#include
#define USER_CLASSPATH "." /* where Prog.class is */
main() {
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
jint res;
JavaVMOption options[2];
options[0].optionString = "-Xrunjavaperf:cg";
options[1].optionString = "-Djava.class.path=" USER_CLASSPATH;
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 2;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (res < 0) {
printf("Error loading VM!! ");
return 1;
}
jclass cls = env->FindClass("JNITest");
jmethodID mid = env->GetStaticMethodID(cls, "test", "()V");
env->CallStaticVoidMethod(cls, mid);
jvm->DestroyJavaVM();
return 0;
}
I tried it with sun JVM 1.4.2 and I had segmentation fault, but with BEA JRockit 8.1 sp1 and IBM 1.3.1 it worked fine.
I hope it answer your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Haimc,
Thanks for the reply. Putting "cg" in command line option is new to me. I will try this and share the experience.
Can u please also tell me what is the command line option for sampling..?
Regards,
Prasad.
Thanks for the reply. Putting "cg" in command line option is new to me. I will try this and share the experience.
Can u please also tell me what is the command line option for sampling..?
Regards,
Prasad.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sampling is the default. Do not specify ":cg"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I'm trying to do the same thing, but I don't understand is how to configure the VTune activity. Do I creata Java sampling activity? If so, Do I choose Application, Script or Applet?
Maybe I'm going down the wrong path?
Thanks
Aaron
I'm trying to do the same thing, but I don't understand is how to configure the VTune activity. Do I creata Java sampling activity? If so, Do I choose Application, Script or Applet?
Maybe I'm going down the wrong path?
Thanks
Aaron

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page