Btrace是一个实时监控工具
http://blog.csdn.net/gzh0222/article/details/9731031
Btrace是一个实时监控工具,可以无需修改应用代码(事实上它修改了字节码),来达到不可告人的秘密!这是性能调优和诊断的利器!
它可以获取应用程序代码的执行时间,他可以让你无需修改代码,帮你做时间的打点。它还可以做的有很多多!
但是,你需要编写btrace脚本,它是一个java文件。在Eclipse中编写java类很简单,在linux上,vm不熟悉的可能就会比较痛苦了,并且脚本可复制性很强。
因此,我对btrace做了一个封装和拓展,你无须再编写java脚本,只需要敲几个命令,便可以实现你想要的功能!
为了减少重复工作的增加,拓展工具提供了以下特色功能:
1) 命令行交互式方式
2) 封装了常见的方法监控命令,无需再编写btrace脚本
3) 集成了一些典型的监控对象,如druid连接池,sql监控,isearch等
4) 未改变原有的btrace功能,仍然支持btrace脚本方式
软件获取和运行
github:https://github.com/xxzmxx/btrace_extend/
svn co 到linux/windows某个位置,进入bin目录
Linux: chmod +x btrace (赋予btrace 可执行权限)
windows无需操作。
命令行下,执行命令
./btrace [pid] |
【pid可以通过jps获取】
进入交互界面

提供命令行交互
原有的btrace是通过形如 btrace pid xx.java文件。通过本次改造,我们提供了命令行交互方式,增加用户体验:
输入help,获取可用的命令
btrace>help-------------------------------------------------------------------------------------------------------------------------------| CommandName CommandArgs CommandUsage| time {clazzname methodname}[interval] collect response time ,and it can be executed by a interval set(s),;Example| time java.lang.Thread start 2|| aggre {clazzname methodname}[interval] aggregation response time,it's a well fuction;Example| aggre java.lang.Thread start 2|| call {clazzname methodname}[interval] when method called,it prints;Example| call java.lang.Thread start 2|| jstack {clazzname methodname} when method called,it prints stackTrace;Example:| jstack java.lang.Thread start 2|| file {filePath} based on old btrace funtion,it can be run from a java file.Example:| file Test.java|| druid Monitor druid dataSource?Example| druid|| isearch Monitor Isearch execute time ;Example| isearch|| sql Monitor sql execute time ;Example| sql|| sqlde Monitor sql execute time and print Sql ;Example| sqlde|| quit exit btrace| quit| ------------------------------------------------------------------------------------------------------------------------------- |
btrace运行操作
btrace在运行监控时,控制台是阻塞输入的。只有通过Ctrl+c,来向应用发送信号,btrace会有3个选项供选择:
btrace>time java.lang.Thread startStartMonitor [java.lang.Thread.start()] time(ms)Please enter your option: 1. exit 2. send an event 3. send a named event |
1代表退出监控,回到btrace交互模式;
2代表发送一个事件,会触发btrace去打印监控信息到控制台。如aggre 、file、druid、isearch、sql、sqlde命令均可以通过该方式,打印出监控信息
3发送一个指定名称的事件,暂时未支持
命令演示
本次拓展,共支持9个命令功能。
1)time
usage:time clazzname method [interval]
time功能为获取指定类的方法的响应时间。并且它包含一个可选参数,即可以提供。
例子:我们想监控类com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp 中方法storeProductToDraftOrNormal的耗时情况。则输入命令
btrace>time com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp storeProductToDraftOrNormalStartMonitor [com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal()] time(ms) |
btrace就开始收集这个方法调用的时间,如果这个方法被调用,就会打印出时间信息。
btrace>time com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp storeProductToDraftOrNormalStartMonitor [com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal()] time(ms)[Clazz.method] Time(ms)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 19[Clazz.method] Time(ms)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 7[Clazz.method] Time(ms)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 7[Clazz.method] Time(ms)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 7[Clazz.method] Time(ms)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 7[Clazz.method] Time(ms)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 7[Clazz.method] Time(ms)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 8[Clazz.method] Time(ms)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 7[Clazz.method] Time(ms)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 7[Clazz.method] Time(ms)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 8 |
但是如果我的时间调用次数很多,就会出现残酷的刷屏现象,我希望每隔2s进行采样。输入如下命令:
btrace>time com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp storeProductToDraftOrNormal 2StartMonitor [com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal()] time(ms)[Clazz.method] AvgTime(ms) Count(total)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 6 3[Clazz.method] AvgTime(ms) Count(total)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 7 13[Clazz.method] AvgTime(ms) Count(total)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 7 20[Clazz.method] AvgTime(ms) Count(total)com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal 7 20 |
btrace会每隔2s收集一次信息,并对每次的信息做统计,包括均值和调用次数总计。
2)aggre
usage:time clazzname method [interval]
如果我们觉得time命令还是不够满足我需求,我希望能够提供一些更详细的值,比如在采集的这段时间,rt的最大值,最小值,均值,以及分布,还有调用总数。此时可以通过聚合命令来完成
例子:我们想监控类com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp 中方法storeProductToDraftOrNormal的耗时,并提供聚合报告。则输入命令
btrace>aggre com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp storeProductToDraftOrNormalStartMonitor [com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal()] By Aggregation time(ms) |
通过触发Ctrl+c,选择选项2,获取输出结果:
btrace>aggre com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp storeProductToDraftOrNormalStartMonitor [com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal()] By Aggregation time(ms)Please enter your option: 1. exit 2. send an event 3. send a named event2QUANTIZE com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp value ------------- Distribution ------------- count 2 | 0 4 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 45 8 |@@@ 4 16 | 1 32 | 0AVERAGE com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp 7MAXIMUM com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp 19SUM com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp 361COUNT com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp 50 |
这里提供了针对时间的聚合信息,以ms为单位。并提供了时间分布的功能,可以清晰的看出该模块时间是否稳定。
3)call
这个命令和time命令用法基本相同,请参考time命令
4)jstack
usage:jstack clazzname method
当应用中存在调用clazzname的method时,会打印出调用堆栈,这个方便我们查找问题。
例如想监控com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp 中方法storeProductToDraftOrNormal是否被调用,如果调用,希望看到它的堆栈。
btrace>jstack com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp storeProductToDraftOrNormalStartMonitor [com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal()] && Print java stack info!-------------------------------stack info--------------------------com.alibaba.intl.ae.module.wsproduct.utils.WholesaleProductHelp.storeProductToDraftOrNormal(WholesaleProductHelp.java)com.alibaba.intl.ae.module.wsproduct.persistent.AeProductForMysqlPersistent.persistent(AeProductForMysqlPersistent.java:32)com.alibaba.intl.ae.morina.core.actionhandler.BasePublishActionHandler.invoke(BasePublishActionHandler.java:69)com.alibaba.intl.ae.morina.core.skeleton.publish.impl.ActionHandlerInterceptorChainInvocation.invoke(ActionHandlerInterceptorChainInvocation.java:67)com.alibaba.intl.ae.module.wsproduct.interceptor.AeProductDetailInterceptor.intercept(AeProductDetailInterceptor.java:40)com.alibaba.intl.ae.morina.core.skeleton.publish.impl.ActionHandlerInterceptorChainInvocation.invoke(ActionHandlerInterceptorChainInvocation.java:63)com.alibaba.intl.ae.module.wsproduct.interceptor.AeProductCatPropertyInterceptor.intercept(AeProductCatPropertyInterceptor.java:101)com.alibaba.intl.ae.morina.core.skeleton.publish.impl.ActionHandlerInterceptorChainInvocation.invoke(ActionHandlerInterceptorChainInvocation.java:63)com.alibaba.intl.ae.module.wsproduct.interceptor.AeProductPostCountCheckInterceptor.intercept(AeProductPostCountCheckInterceptor.java:51)com.alibaba.intl.ae.morina.core.skeleton.publish.impl.ActionHandlerInterceptorChainInvocation.invoke(ActionHandlerInterceptorChainInvocation.java:63)com.alibaba.intl.ae.module.wsproduct.interceptor.AeProductPersonAuthInterceptor.intercept(AeProductPersonAuthInterceptor.java:45)com.alibaba.intl.ae.morina.core.skeleton.publish.impl.ActionHandlerInterceptorChainInvocation.invoke(ActionHandlerInterceptorChainInvocation.java:63)com.alibaba.intl.ae.module.wsproduct.interceptor.AeProductPunishInterceptor.intercept(AeProductPunishInterceptor.java:32)com.alibaba.intl.ae.morina.core.skeleton.publish.impl.ActionHandlerInterceptorChainInvocation.invoke(ActionHandlerInterceptorChainInvocation.java:63)com.alibaba.intl.ae.module.wsproduct.interceptor.AutoValidateProductInterceptor.intercept(AutoValidateProductInterceptor.java:36)com.alibaba.intl.ae.morina.core.skeleton.publish.impl.ActionHandlerInterceptorChainInvocation.invoke(ActionHandlerInterceptorChainInvocation.java:63)com.alibaba.intl.ae.module.wsproduct.interceptor.MemberInfoInitializationInterceptor.intercept(MemberInfoInitializationInterceptor.java:73)com.alibaba.intl.ae.morina.core.skeleton.publish.impl.ActionHandlerInterceptorChainInvocation.invoke(ActionHandlerInterceptorChainInvocation.java:63)com.alibaba.intl.ae.morina.core.skeleton.publish.impl.AeProductPublishController.invoke(AeProductPublishController.java:50)com.alibaba.intl.ae.morina.core.skeleton.publish.impl.AeProductPublishController.invoke(AeProductPublishController.java:25)com.alibaba.intl.ae.morina.core.portal.InvocationControllerAutowirePostProcessor$1.intercept(InvocationControllerAutowirePostProcessor.java:44)com.alibaba.intl.ae.morina.core.portal.InvocationControllerPortal$$EnhancerByCGLIB$$276335c.invoke(<generated>)com.alibaba.intl.ae.module.wsproduct.service.AeProductPublishRemoteServiceImpl.postAeProduct(AeProductPublishRemoteServiceImpl.java:36)sun.reflect.GeneratedMethodAccessor380.invoke(Unknown Source) |
5)file
这个命令其实是为了保留btrace原始的监控方式。所以如果你编写了btrace 脚本,那么直接使用:
file script.java
6)druid
该命令没有参数,直接输入druid即可。druid是一个数据库连接池。在性能测试时,时常要监控连接池的饱满情况,以及是否存在性能瓶颈,那么监控连接池的活动情况是很直接的方法。
例子如下:
btrace>druidStartMonitor druid Connection DataSourcePlease enter your option: 1. exit 2. send an event 3. send a named event2------------------------------JDBC-URL------------------------------- avalibleConn activeConn totalConn Allconn useage%dbc:mysql://10.20.147.144:3306/ws_product_press 4 0 4 20 20.0dbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.20.149. 8 2 10 20 50.0dbc:mysql://10.20.147.144:3306/ws_sku_press 6 0 6 50 12.0dbc:alibaba:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10 7 2 9 10 90.0 |
7)sql
该命令没有参数,直接输入sql即可。如果你的应用包含数据库操作,且使用ibatis框架,那么它会列出所有sql的操作时间,但是不显示详细sql,只显示ibatis-id。如果要显示详细sql,使用sqlde命令获取
btrace>sqlStartMonitor Ibtis SqlPlease enter your option: 1. exit 2. send an event 3. send a named event2---------------------------------------------Count FREIGHT_TEMPLATE.selectByPrimaryKey 1290 WS_PRODUCT_DETAIL_DRAFT.selectByPrimaryKey 1290 WS_PRODUCT_DETAIL_DRAFT.deleteByPrimaryKey 1290Min FREIGHT_TEMPLATE.selectByPrimaryKey 0 WS_PRODUCT_DETAIL_DRAFT.selectByPrimaryKey 0 WS_PRODUCT_DETAIL_DRAFT.deleteByPrimaryKey 0Max WS_PRODUCT_DETAIL_DRAFT.selectByPrimaryKey 14 WS_PRODUCT_DETAIL_DRAFT.deleteByPrimaryKey 14 FREIGHT_TEMPLATE.selectByPrimaryKey 15Average FREIGHT_TEMPLATE.selectByPrimaryKey 0 WS_PRODUCT_DETAIL_DRAFT.selectByPrimaryKey 0 WS_PRODUCT_DETAIL_DRAFT.deleteByPrimaryKey 0Sum FREIGHT_TEMPLATE.selectByPrimaryKey 144 WS_PRODUCT_DETAIL_DRAFT.deleteByPrimaryKey 161 WS_PRODUCT_DETAIL_DRAFT.selectByPrimaryKey 186Histogram WS_CATE_CONSULT_CFGT.selectOldCategoryAttriNumber value ------------- Distribution ------------- count -1 | 0 0 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 469 1 |@@@@@@@ 127 2 |@ 28 4 | 12 8 | 7 16 | 2 32 | 0 WHOLESALE_STORE.findWholesaleStoreDOByCompanyId value ------------- Distribution ------------- count -1 | 0 0 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 587 1 |@@ 37 2 | 8 4 | 6 8 | 6 16 | 1 32 | 0Global Count 19150 |
ps.上述内容过于繁多,只选择了部分。
8)sqlde
该命令没有参数,直接输入sqlde即可。该命令不但会聚合所有sql的rt,也会打印sql详情。不过这个sql的排版目前做的还不是很好。会有些乱。建议还是使用sql命令来看。sql少的话,使用sqlde命令。 
Btrace是一个实时监控工具的更多相关文章
- Linux下网络流量实时监控工具
Linux下网络流量实时监控工具大全 在工作中发现,经常因为业务的原因,需要即时了解某台服务器网卡的流量,虽然公司也部署了cacti软件,但cacti是五分钟统计的,没有即时性,并且有时候打开监控页面 ...
- linux网络流量实时监控工具之iptraf
这个工具还是很强大 linux网络流量实时监控工具之iptraf [我的Linux,让Linux更易用]IPTraf是一个网络监控工具,功能比nload更强大,可以监控所有的流量,IP流量,按协议分的 ...
- Linux 网络流量实时监控工具之ntopng详解
大纲一.前言二.ntopng 简介三.ntopng 功能说明 四.ntopng 安装详解五.ntopng 配置详解 六.ntopng 使用详解注,操作系统 CentOS 5.5 X86_64,软件版本 ...
- linux网络流量实时监控工具之iptraf 【个人比较喜欢用的流量监控软件】
linux网络流量实时监控工具之iptraf IPTraf是一个网络监控工具,功能比nload更强大,可以监控所有的流量,IP流量,按协议分的流量,还可以设置过滤器等,如下图 对监控网络来说,这个更适 ...
- 界面酷炫,功能强大!这款 Linux 性能实时监控工具超好用!
对于维护.管理Linux系统来说,它的性能监控非常重要,特别是实时监控数据,这个数据有利于我们判断服务器的负载压力,及时调整资源调配,也有助于更好的服务于业务.所以,今天民工哥给大家安利一款 Linu ...
- react实例之todo,做一个实时响应的列表操作
react实例之todo, 做一个实时响应的列表操作 在所有的mvc框架中,最常见的例子不是hello world,而是todo,由于reactjs的简单性,在不引用flux和redux的情况下,我们 ...
- 用Vue开发一个实时性时间转换功能,看这篇文章就够了
前言 最近有一个说法,如果你看见某个网站的某个功能,你就大概能猜出背后的业务逻辑是怎么样的,以及你能动手开发一个一毛一样的功能,那么你的前端技能算是进阶中高级水平了.比如咱们今天要聊的这个话题:如何用 ...
- 用Vue+axios写一个实时搜索
刚刚在学vue,试着写了一个实时搜索文件. 思路:1.input 通过v-model绑定.2.通过watch检测输入结果变化.3根据结果变化从api调用不同的数据. 代码如下: <!DOCTYP ...
- ngxtop(nginx实时监控工具)
原文内容来自于LZ(楼主)的印象笔记,如出现排版异常或图片丢失等问题,可查看当前链接:https://app.yinxiang.com/shard/s17/nl/19391737/dea1ca3a-7 ...
随机推荐
- skiplist 跳表(1)
最近学习中遇到一种新的数据结构,很实用,搬过来学习. 原文地址:skiplist 跳表 为什么选择跳表 目前经常使用的平衡数据结构有:B树,红黑树,AVL树,Splay Tree, Treep等. ...
- mooc
Coursera 课程来源 2014年前已与斯坦福.普林斯顿等近90所大学和教育机构达成合作关系. 用户类型 主要类别为学生.求职者.公司人.其中,求职者可在Coursera上获得<成就报告&g ...
- jQuery获取屏幕的宽度
Javascript: 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.b ...
- BZOJ 1636: [Usaco2007 Jan]Balanced Lineup
noip要来了,刷点基础水题. 题意: RMQ,给你N个数,Q个询问,每次查询[l,r]内,最大值减最小值是多少. 写的ST. 代码: #include<iostream> #includ ...
- Li Fei-fei写给她学生的一封信,如何做好研究以及写好PAPER
Li Fei-fei写给她学生的一封信,如何做好研究以及写好PAPER 在微博上看到的,读完还是有些收获的,首先是端正做research的态度. 我是从这里看到的:http://www.vjianke ...
- 今天,安装了一个GANGLIA玩玩,以后再测试NAGIOS吧。
说不定以后派得上用场呢.. 还有,NGINX也要学,不能老是凭站IIS,APACHE混饭吃吧,现在它都这么流行了..新浪,网易,腾讯.
- Hibernate 注解时 hibernate.hbm.xml的配置方法 以及与SSH整合里的配置方式
①纯Hibernate开发: 当你在Bean中写入注解后,需要告诉hibernate哪些类使用了注解. 方法是在hibernate.hbm.xml文件中配置 <!DOCTYPE hibernat ...
- 【LA 5713 】 Qin Shi Huang's National Road System (MST)
[题意] 秦始皇要在n个城市之间修路,而徐福声可以用法术位秦始皇免费修1条路,每个城市还有人口数,现要求徐福声所修之路的两城市的人口数之和A尽量大,而使n个城市互通需要修的路长B尽量短,从而使得A/B ...
- C#下多进程共同读写同一文件
最近遇到这样一个需求,用C#写一个界面,在界面上实时输出一个日志文件. 实时检测文件变化,以便刷新界面显示,可以用FileSystemWatcher组件,响应Changed事件即可. 关键是在Chan ...
- HDOJ -- 4632 区间DP
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...