getThreadCpuTime trouble
My target is getting informations about the cpu used by all the threads running in the VM. Printing out I always see the some value for the cpu-time... and it's equal to the max_value of the cpuTimeInfo struct...
I can't understand what is wrong... can you help me please?
here is some parts of code:
void JNICALL VMInitCallback(jvmtiEnv *jvmti_env,JNIEnv* jni_env,jthread thread){
pid_routine=fork();
if (!pid_routine)
routine_cpu();
}
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved){
(*vm)->GetEnv(vm, (void**)&env, JVMTI_VERSION_1_0);
memset(&clbk,0,sizeof(clbk));
memset(&cap,0,sizeof(cap));
cap.can_get_thread_cpu_time=1;
clbk.VMInit=&VMInitCallback;
(*env)->AddCapabilities(env,&cap);
(*env)->SetEventCallbacks(env,&clbk,sizeof(clbk));
(*env)->SetEventNotificationMode(env,(jint)JVMTI_ENABLE,JVMTI_EVENT_VM_INIT,NULL);
return JNI_OK;
}
void routine_cpu(){
.....................
while(count){
sleep(INT);
(*env)->GetAllThreads(env,&thread_count,&thread_list);
errors = malloc(thread_count*sizeof(jvmtiError));
memset(errors,0,thread_count*sizeof(jvmtiError));
(*env)->SuspendThreadList(env,thread_count,thread_list,&errors);
for (i=0;i<thread_count;i++)
if(errors!=JVMTI_ERROR_NONE)
printf("error occurred on suspending thread#%d %d\n",i,(jvmtiError)errors);
if(thread_list != NULL)
for(i=0;i<thread_count;i++){
(*env)->GetThreadInfo(env,thread_list,&info);
retval=(*env)->GetThreadCpuTime(env,thread_list,&value);
printf("thread %s\tvalue %Lu\n",info,(jlong)val);
}
(*env)->ResumeThreadList(env,thread_count,thread_list,errors);
count--;
}
exit(0);
}
-
and this is the output running a simple test program:
thread Reference Handlervalue 18446744073709551615state 401
thread mainvalue 18446744073709551615state 5
thread Finalizervalue 18446744073709551615state 401
thread Reference Handlervalue 18446744073709551615state 401
thread mainvalue 18446744073709551615state 5
thread Finalizervalue 18446744073709551615state 401
thread Reference Handlervalue 18446744073709551615state 401
thread mainvalue 18446744073709551615state 5
thread Finalizervalue 18446744073709551615state 401
...... and so on
--

