资源介绍
JVMTI例子 截获方法进入和退出,并打印时间日志
0、安装gcc
1、tracer.c拷贝到/home/java/jvmti,修改c程序的TRACE_CLSNAME为需要拦截的包
2、敲入命令
BASE_HOME='/home/java/jvmti'
INCLUDES="-I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
gcc $BASE_HOME/tracer.c -fpic $INCLUDES -shared -o $BASE_HOME/tracer.so
3、在jboss启动脚本的java参数中加入
-agentpath:/home/java/jvmti/tracer.so=/home/java/jvmti/trace_log.txt
输入日志格式类似
CALL Lcom/xxx/cc/test/Mtrace; | | ()V | 2013/6/13 8:38:46 |
Exit Lcom/xxx/cc/test/Mtrace; | | ()V | 2013/6/13 8:38:46 |
CALL Lcom/xxx/cc/test/Mtrace; | main | ([Ljava/lang/String;)V | 2013/6/13 8:38:46 |
CALL Lcom/xxx/cc/test/Mtrace; | themytest | ()V | 2013/6/13 8:38:46 |
Exit Lcom/xxx/cc/test/Mtrace; | themytest | ()V | 2013/6/13 8:38:46 |
Exit Lcom/xxx/cc/test/Mtrace; | main | ([Ljava/lang/String;)V | 2013/6/13 8:38:46 |