原创

btrace进行性能测试

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://xxlcube.blog.csdn.net/article/details/40297797

使用BTrace 做性能测试

在官网https://kenai.com/projects/btrace/downloads/directory/releases/release-1.2.4

下载对应的jar包

 

测试时后,将btrace测试类和被测试类放在同一个机器上

 

将btrace测试类写好,放在btrace解压的bin目录下

调用如下命令进行测试

 

sh btrace pid BtraceTest.java

 

pid可通过jps命令来查看,默认端口是2020端口,如果被测试类有多个进程,则端口号累加

2021  2022   2023 ……

 sh bin/btrace -p 2021  41479 bin/App.java > exeTime.txt

Btrace类

import com.sun.btrace.annotations.BTrace;

import com.sun.btrace.annotations.Kind;

import com.sun.btrace.annotations.Location;

import com.sun.btrace.annotations.OnMethod;

import com.sun.btrace.annotations.ProbeClassName;

import com.sun.btrace.annotations.ProbeMethodName;

import com.sun.btrace.annotations.TLS;

 

import static com.sun.btrace.BTraceUtils.*;

 

@BTrace

public class BtraceTest {

 

         @TLS

    private static long startTime=0;

    @OnMethod(clazz = "/*/", method = "/.*/", location = @Location(value=Kind.ENTRY, clazz="/.*/", method="/.*/"))

    public static void startMethod() {

       startTime =timeMillis();

    }

   

    @OnMethod(clazz = "/*/", method = "/.*/", location = @Location(value=Kind.RETURN, clazz="/.*/", method="/.*/"))

    public static void endMethod(@ProbeClassName String className, @ProbeMethodName String methodName) {

        println(concat("threadId:", str(threadId(currentThread()))));

        println(strcat("className:", className)); 

        println(strcat("methodName:", methodName));

        println(strcat("exeTime:", str(timeMillis()-startTime))); 

 

    }

   

    @OnMethod(clazz = "//", method = "sendHttpRequest", location = @Location(value=Kind.RETURN, clazz="/.*/", method="/.*/"))

    public static void endMethod2(@ProbeClassName String className, @ProbeMethodName String methodName) {

             println("CommonBizImpl----sendHttpRequest----------");

             //System.out.println("CommonBizImpl----sendHttpRequest----------");

        println(concat("threadId:", str(threadId(currentThread()))));

        println(strcat("className:", className)); 

        println(strcat("methodName:", methodName));

        println(strcat("exeTime:", str(timeMillis()-startTime))); 

 

    }

   

}


以上*为你要监测的类或者方法名,这里注释掉了 


threadId:34746

className:*l

methodName:getCacheByTid

exeTime:4

threadId:34754

className:*

methodName:getCacheByTid

exeTime:4

threadId:34746

className:*

methodName:getCacheByTid

exeTime:4

threadId:34746

className:*

methodName:getCacheByTid

exeTime:3

 

 

 

 

 

 

 

 

 

文章最后发布于: 2014-10-20 11:01:04
展开阅读全文
0 个人打赏
私信求帮助

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 酷酷鲨 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览