2009/06/05

솔라리스에서 dtrace로 자바 메모리 활동 추적하기

Sun의 Jim Fiori가 제시한 방식입니다.

#!/usr/sbin/dtrace -qs

/*

* Show object allocation, aggregating the Java stack, methods,

* and object sizes

*

*/



hotspot$1:::object-alloc

{

       this->class = copyinstr(arg1,arg2);

       this->sz = arg3;

       @[jstack(40, 8000)] = count();

       @objs[this->class] = count();

       @sizes["Sizes"] = quantize(this->sz);

}

END

{



       trunc(@,20);

       trunc(@objs,10);

       printf ("\n****************Top Java stacks for memory
allocations*************\n");

       printa(@);

       printf ("\n****************Top Objects for memory
allocations*************\n");

       printa(@objs);

       printf ("\n****************Object sizes*************\n");

       printa(@sizes);



}

Pass in the JVM pid. You will have to use this startup flag for the JVM:



# java -XX:+ExtendedDTraceProbes



If you can't use Java 6, I've got something similar that uses the DTrace
VM agents.



To add looking at "heap" allocations via libumem, just add some PID
provider probes like:



pid$1::malloc:entry

{

   @mall_stack[jstack(40, 8000)] = count();

   @mall_sz = quantize(arg0);

}

<솔라리스, 디트레이스,자바, Solaris, dtrace, java>