{"id":1519,"date":"2017-05-14T15:42:37","date_gmt":"2017-05-14T07:42:37","guid":{"rendered":"http:\/\/coderbee.net\/?p=1519"},"modified":"2017-05-14T18:11:58","modified_gmt":"2017-05-14T10:11:58","slug":"btrace-%e7%94%a8%e6%88%b7%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/jvm\/20170514\/1519","title":{"rendered":"BTrace \u7528\u6237\u6307\u5357"},"content":{"rendered":"<p>\u539f\u6587\uff1a <a href=\"https:\/\/github.com\/btraceio\/btrace\/blob\/master\/docs\/usersguide.html\">BTrace-usersguide<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/btraceio\/btrace\">BTrace<\/a> \u662f\u7528\u4e8e Java \u7684\u5b89\u5168\u3001\u52a8\u6001\u8ddf\u8e2a\u5de5\u5177\u3002BTrace \u63d2\u5165\u8ddf\u8e2a\u52a8\u4f5c\u5230\u6b63\u5728\u8fd0\u884c\u7684 Java \u7a0b\u5e8f\u7c7b\u7684\u5b57\u8282\u7801\u5e76\u70ed\u66ff\u6362\u88ab\u8ddf\u8e2a\u7a0b\u5e8f\u7684\u7c7b\u3002<\/p>\n<h1>BTrace \u672f\u8bed<\/h1>\n<ul>\n<li>probe point\uff0c\u63a2\u67e5\u70b9\uff1a\u4e00\u7ec4\u4f4d\u7f6e\u6216\u4e8b\u4ef6\uff0c\u8ddf\u8e2a\u8bed\u53e5\u6267\u884c\u7684\u5730\u65b9\u3002\u4f4d\u7f6e\u6216\u4e8b\u4ef6\u662f\u6211\u4eec\u5e0c\u671b\u6267\u884c\u4e00\u4e9b\u8ddf\u8e2a\u8bed\u53e5\u7684\u611f\u5174\u8da3\u7684\u5730\u65b9\u3002<\/li>\n<li>trace action\uff0c\u8ddf\u8e2a\u52a8\u4f5c\uff1a\u8ddf\u8e2a\u8bed\u53e5\u662f\u63a2\u67e5\u88ab\u89e6\u53d1\u65f6\u6267\u884c\u7684\u3002<\/li>\n<li>action method\uff0c\u52a8\u4f5c\u65b9\u6cd5\uff1a\u5f53\u63a2\u67e5\u88ab\u89e6\u53d1\u65f6\uff0c\u88ab\u6267\u884c\u7684 BTrace \u8ddf\u8e2a\u8bed\u53e5\u5b9a\u4e49\u5728\u7c7b\u7684\u4e00\u4e2a\u9759\u6001\u65b9\u6cd5\u91cc\u3002\u8fd9\u6837\u7684\u65b9\u6cd5\u88ab\u79f0\u4e3a \u52a8\u4f5c \u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<h1>BTrace \u7a0b\u5e8f\u7ed3\u6784<\/h1>\n<p>BTrace \u7a0b\u5e8f\u662f\u4e00\u4e2a\u666e\u901a\u7684 Java \u7c7b\uff0c\u6709\u4e00\u4e2a\u6216\u591a\u4e2a\u6807\u8bb0\u6709 BTrace \u6ce8\u89e3\u7684 <code>public static void<\/code> \u65b9\u6cd5\u3002\u6ce8\u89e3\u7528\u4e8e\u6307\u5b9a\u8ddf\u8e2a\u7a0b\u5e8f\u7684 \u4f4d\u7f6e\u3002\u8ddf\u8e2a\u52a8\u4f5c\u6307\u5b9a\u5728\u9759\u6001\u65b9\u6cd5\u4f53\u91cc\u3002\u8fd9\u4e9b\u9759\u6001\u65b9\u6cd5\u88ab\u79f0\u4e3a \u52a8\u4f5c \u65b9\u6cd5\u3002<\/p>\n<h1>BTrace \u7684\u9650\u5236<\/h1>\n<p>\u4e3a\u4e86\u4fdd\u8bc1\u8ddf\u8e2a\u52a8\u4f5c\u662f \u53ea\u8bfb \u4e14\u53d7\u9650\u7684\uff0cBTrace \u53ea\u5141\u8bb8\u505a\u4e00\u4e9b\u4e25\u683c\u53d7\u9650\u7684\u52a8\u4f5c\u3002\u901a\u5e38\uff0cBTrace \u7c7b\uff1a<\/p>\n<ul>\n<li>\u4e0d\u80fd \u521b\u5efa\u65b0\u5bf9\u8c61\u3002<\/li>\n<li>\u4e0d\u80fd \u521b\u5efa\u65b0\u6570\u7ec4\u3002<\/li>\n<li>\u4e0d\u80fd \u629b\u51fa\u5f02\u5e38\u3002<\/li>\n<li>\u4e0d\u80fd \u6355\u83b7\u5f02\u5e38\u3002<\/li>\n<li>\u4e0d\u80fd \u8c03\u7528\u4efb\u610f\u5b9e\u4f8b\u6216\u9759\u6001\u65b9\u6cd5\u3002\u53ea\u80fd\u8c03\u7528 <code>com.sun.btrace.BTraceUtils<\/code> \u7c7b\u7684 <code>public static<\/code> \u65b9\u6cd5\u3002<\/li>\n<li>\u4e0d\u80fd \u7ed9\u76ee\u6807\u7a0b\u5e8f\u7684\u7c7b\u6216\u53d8\u91cf\u7684\u9759\u6001\u6216\u5b9e\u4f8b\u5b57\u6bb5\u8d4b\u503c\u3002\u4f46\u662f BTrace \u7c7b\u53ef\u4ee5\u7ed9\u5b83\u81ea\u5df1\u7684\u9759\u6001\u5b57\u6bb5\u8d4b\u503c\uff08\u8ddf\u8e2a\u72b6\u6001\u53ef\u4ee5\u6539\u53d8\uff09\u3002<\/li>\n<li>\u4e0d\u80fd \u6709\u5b9e\u4f8b\u5b57\u6bb5\u6216\u65b9\u6cd5\u3002BTrace \u7c7b\u53ea\u80fd\u6709 <code>public static void<\/code> \u65b9\u6cd5\uff0c\u6240\u6709\u7684\u5b57\u6bb5\u53ea\u80fd\u662f\u9759\u6001\u7684\u3002<\/li>\n<li>\u4e0d\u80fd \u6709\u5916\u90e8\u3001\u5185\u90e8\u3001\u5d4c\u5957\u7c7b\u6216\u672c\u5730\u7c7b\u3002<\/li>\n<li>\u4e0d\u80fd \u6709\u5faa\u73af\uff08<code>for<\/code>, <code>while<\/code>, <code>do ... while<\/code>\uff09\u3002<\/li>\n<li>\u4e0d\u80fd \u7ee7\u627f\u4efb\u610f\u7c7b\uff08\u7236\u7c7b\u5fc5\u987b\u662f <code>java.lang.Object<\/code>\uff09\u3002<\/li>\n<li>\u4e0d\u80fd \u5b9e\u73b0\u63a5\u53e3\u3002<\/li>\n<li>\u4e0d\u80fd \u5305\u542b <code>assert<\/code> \u8bed\u53e5\u3002<\/li>\n<li>\u4e0d\u80fd \u4f7f\u7528\u7c7b\u5b57\u9762\u91cf\u3002<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<h1>\u8fd0\u884c BTrace<\/h1>\n<ol>\n<li>\u627e\u5230 Java \u8fdb\u7a0b\u7684 ID\u3002\u53ef\u4ee5\u901a\u8fc7 jps \u5de5\u5177\u3002<\/li>\n<li>\u7f16\u5199 BTrace \u7a0b\u5e8f\u3002<\/li>\n<li>\u5728\u547d\u4ee4\u884c\u8fd0\u884c\u4e0b\u9762\u7684\u547d\u4ee4\uff1a <code>btrace &lt;pid&gt; &lt;btrace-script&gt;<\/code><\/li>\n<\/ol>\n<h1>BTrace \u547d\u4ee4\u884c<\/h1>\n<p>BTrace \u901a\u8fc7\u547d\u4ee4\u884c\u5de5\u5177 <code>btrace<\/code> \u6765\u8fd0\u884c\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code>btrace [-I &lt;include-path&gt;]  [-p &lt;port&gt;] [-cp &lt;classpath&gt;] &lt;pid&gt; &lt;btrace-script&gt; [&lt;args&gt;]\n<\/code><\/pre>\n<p>\u8bf4\u660e\uff1a<\/p>\n<ul>\n<li><code>include-path<\/code> \u662f\u4e00\u7ec4\u7528\u4e8e\u641c\u7d22\u5934\u6587\u4ef6\u7684\u5305\u542b\u76ee\u5f55\u3002BTrace \u5305\u542b\u4e00\u4e2a\u7b80\u5355\u7684\u9884\u5904\u7406\uff0c\u652f\u6301 <code>#define<\/code>, <code>#include<\/code> \u548c\u6761\u4ef6\u7f16\u8bd1\u3002\u5b83\u4e0d\u5b8c\u5168\u50cf C\/C++ \u7684\u9884\u5904\u7406\u5668 &#8212; \u4f46\u4e5f\u662f\u6709\u7528\u7684\u5b50\u96c6\u3002\u53c2\u8003 <code>ThreadBean.java<\/code> \u793a\u4f8b\u3002\u5982\u679c <code>-I<\/code> \u6ca1\u6709\u6307\u5b9a\uff0cBTrace \u8df3\u8fc7\u9884\u5904\u7406\u53d1\u8d77\u9636\u6bb5\u3002<\/li>\n<li><code>port<\/code> \u662f BTrace \u4ee3\u7406\u76d1\u542c\u7684\u7aef\u53e3\u3002\u53ef\u9009\u53c2\u6570\u3002<\/li>\n<li><code>classpath<\/code> \u662f\u76ee\u5f55\u3001jar \u6587\u4ef6\u7684\u96c6\u5408\uff0cBTrace \u5728\u7f16\u8bd1\u65f6\u641c\u7d22\u7c7b\u3002\u9ed8\u8ba4\u662f <code>.<\/code> \u3002<\/li>\n<li><code>pid<\/code> \u662f\u8981\u8ddf\u8e2a\u7684 Java \u7a0b\u5e8f\u7684\u8fdb\u7a0b ID\u3002<\/li>\n<li><code>trace-script<\/code> \u662f\u8ddf\u8e2a\u7a0b\u5e8f\u3002\u5982\u679c\u662f\u4e2a <code>.java<\/code>\uff0c\u5b83\u5c06\u5728\u63d0\u4ea4\u524d\u88ab\u7f16\u8bd1\u3002\u5426\u5219\uff0c\u5b83\u5c06\u88ab\u5047\u8bbe\u4e3a\u5df2\u7ecf\u7f16\u8bd1\u4e86\u7684\uff0c\u5e76\u63d0\u4ea4\u3002<\/li>\n<\/ul>\n<p>\u9009\u9879\uff1a<\/p>\n<ul>\n<li><code>port<\/code> BTrace \u4ee3\u7406\u7528\u4e8e\u76d1\u542c\u5ba2\u6237\u7aef\u7684 \u670d\u52a1\u5668\u5957\u63a5\u5b57\u7aef\u53e3\u3002\u9ed8\u8ba4\u662f 2020 \u3002<\/li>\n<li><code>path<\/code> \u7528\u4e8e\u7f16\u8bd1 BTrace \u7a0b\u5e8f\u7684 classpath\u3002\u9ed8\u8ba4\u662f <code>.<\/code> \u3002<\/li>\n<li><code>args<\/code> \u4f20\u9012\u7ed9 BTrace \u7a0b\u5e8f\u7684\u547d\u4ee4\u884c\u53c2\u6570\u3002BTrace \u53ef\u4ee5\u901a\u8fc7\u5185\u7f6e\u7684\u51fd\u6570 <code>$<\/code> \u548c <code>$length<\/code> \u6765\u8bbf\u95ee\u4ed6\u4eec\u3002<\/li>\n<\/ul>\n<h1>\u9884\u7f16\u8bd1 BTrace \u811a\u672c<\/h1>\n<p>\u53ef\u4ee5\u901a\u8fc7 <code>btracec<\/code> \u811a\u672c\u9884\u7f16\u8bd1 BTrace \u7a0b\u5e8f\u3002btracec \u7c7b\u4f3c\u4e8e javac \u7a0b\u5e8f\uff0c\u63a5\u6536\u4e00\u4e2a BTrace \u7a0b\u5e8f\uff0c\u751f\u6210\u4e00\u4e2a .class \u6587\u4ef6\u3002<\/p>\n<pre><code>btracec [-I &lt;include-path&gt;]  [-cp &lt;classpath&gt;]  [-d &lt;direcotry&gt;]  &lt;one-or-more-BTrace-.java files&gt;\n<\/code><\/pre>\n<p>\u8bf4\u660e\uff1a<\/p>\n<ul>\n<li>direcoryt \u662f\u7f16\u8bd1\u751f\u6210\u7684 .class \u6587\u4ef6\u7684\u5b58\u653e\u8def\u5f84\u3002\u9ed8\u8ba4 <code>.<\/code> \u3002<\/li>\n<\/ul>\n<h1>\u5e26 BTrace \u4ee3\u7406\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f<\/h1>\n<p>\u524d\u9762\u8bb2\u7684\u662f\u7528\u8ddf\u8e2a\u6b63\u5728\u8fd0\u884c\u7684 Java \u7a0b\u5e8f\uff0c\u4e5f\u53ef\u4ee5\u5728\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\u65f6\u5e26\u4e0a BTrace \u4ee3\u7406\u3002\u5982\u679c\u60f3\u5728\u5e94\u7528\u7a0b\u5e8f\u5df2\u542f\u52a8\u65f6\u5c31\u8fdb\u884c\u8ddf\u8e2a\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5e26\u4e0a BTrace \u4ee3\u7406\u53bb\u542f\u52a8\u5e94\u7528\uff0c\u5e76\u4e00\u8d77\u6307\u5b9a\u8ddf\u8e2a\u811a\u672c\u3002\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u542f\u52a8\u5e94\u7528\u5e76\u6307\u5b9a BTrace \u811a\u672c\u6587\u4ef6\u3002\u4f46\u8fd9\u79cd\u4f7f\u7528\u65b9\u5f0f\u9700\u8981\u63d0\u524d\u7f16\u8bd1 BTrace \u811a\u672c\u3002<\/p>\n<pre><code>java  -javaagent:btrace-agent.java=script=&lt;pre-compiled-script&gt;  &lt;MainClass&gt;  &lt;AppArguments&gt;\n<\/code><\/pre>\n<p>\u5f53\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u542f\u52a8\u5e94\u7528\u65f6\uff0c\u8ddf\u8e2a\u8f93\u51fa\u5c06\u8f93\u51fa\u5230\u5f53\u524d\u76ee\u5f55\u7684\u540d\u4e3a <code>&lt;btrace-class-file-name&gt;.btrace<\/code> \u7684\u6587\u4ef6\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u7ed9 BTrace \u4ee3\u7406\u6307\u5b9a\u53c2\u6570 <code>noServer=true<\/code> \u6765\u907f\u514d\u542f\u52a8\u7ed9\u8fdc\u7a0b BTrace \u5ba2\u6237\u7aef\u7684\u670d\u52a1\uff08\u7528\u4e8e\u8fdc\u7a0b\u63d0\u4ea4\u8ddf\u8e2a\u811a\u672c\uff09\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u5b8c\u6210\u4e0a\u8ff0\u64cd\u4f5c\u7684\u4fbf\u6377\u811a\u672c\uff0c\u79f0\u4e3a <code>btracer<\/code> \uff1a<\/p>\n<pre><code>btracer  &lt;pre-compiled-btrace.class&gt;  &lt;application-main-class&gt;  &lt;application-args&gt;\n<\/code><\/pre>\n<h1>BTrace \u6ce8\u89e3<\/h1>\n<h2>\u65b9\u6cd5\u6ce8\u89e3<\/h2>\n<ul>\n<li>\n<p><code>@com.sun.btrace.annotations.OnMethod<\/code>\uff1a\u8fd9\u4e2a\u6ce8\u89e3\u53ef\u7528\u4e8e\u6307\u5b9a\u76ee\u6807\u7c7b\u3001\u76ee\u6807\u65b9\u6cd5\u548c\u65b9\u6cd5\u5185\u7684\u4f4d\u7f6e\u3002\u5f53\u5339\u914d\u5230\u7684\u65b9\u6cd5\u5230\u8fbe\u6307\u5b9a\u7684\u4f4d\u7f6e\u65f6\uff0c\u6807\u8bb0\u6709\u8fd9\u4e2a\u6ce8\u89e3\u7684\u52a8\u4f5c\u65b9\u6cd5\u5c06\u88ab\u6267\u884c\u3002\u5728 <code>OnMethod<\/code> \u6ce8\u89e3\u91cc\uff0c\u8ddf\u8e2a\u7c7b\u7684\u540d\u5b57\u7531 <code>clazz<\/code> \u5c5e\u6027\u6307\u5b9a\uff0c\u65b9\u6cd5\u7531 <code>method<\/code> \u5c5e\u6027\u6307\u5b9a\u3002<code>clazz<\/code> \u53ef\u4ee5\u662f\u5168\u8def\u5f84\u7c7b\u540d\uff08\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\uff09\u3002\u6b63\u5728\u8868\u8fbe\u5f0f\u7528 <code>\/\/<\/code> \u6765\u6307\u5b9a\uff0c\u6240\u6709\u5339\u914d\u7684\u7c7b\u90fd\u5c06\u88ab\u589e\u5f3a\uff0c\u4f8b\u5982 <code>\/java\\\\.wat\\\\..+\/<\/code> \u5c06\u5339\u914d\u6240\u6709 <code>java.awt<\/code> \u5305\u4e0b\u7684\u7c7b\u3002\u540c\u6837\uff0c\u65b9\u6cd5\u540d\u4e5f\u53ef\u4ee5\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u6307\u5b9a\u3002\u8fd8\u6709\u53e6\u4e00\u79cd\u65b9\u5f0f\u53ef\u4ee5\u6307\u5b9a\u8981\u8ddf\u8e2a\u7684\u7c7b\u548c\u65b9\u6cd5\uff1a\u88ab\u8ddf\u8e2a\u7684\u7c7b\u548c\u65b9\u6cd5\u53ef\u4ee5\u6307\u5b9a\u6ce8\u89e3\u3002\u4f8b\u5982\uff0c\u5982\u679c <code>clazz<\/code> \u5c5e\u6027\u6307\u5b9a\u4e3a <code>@java.jws.WebService<\/code>\uff0cBTrace \u5c06\u5bf9\u6240\u6709\u6807\u8bb0\u6709 <code>WebService<\/code> \u6ce8\u89e3\u7684\u65b9\u6cd5\u8fdb\u884c\u589e\u5f3a\u3002\u540c\u6837\uff0c\u65b9\u6cd5\u7ea7\u522b\u4e5f\u53ef\u4ee5\u7528\u6ce8\u89e3\u6765\u6307\u5b9a\u3002\u53ef\u4ee5\u7ec4\u5408\u4f7f\u7528\u6ce8\u89e3\u548c\u6b63\u5728\u8868\u8fbe\u5f0f\uff0c\u4f8b\u5982 <code>@\/com\\\\.acme\\\\..+\/<\/code> \u5c06\u5339\u914d\u6807\u8bb0\u4e86\u5339\u914d\u6ce8\u89e3\u7684\u4efb\u610f\u7c7b\u3002\u8fd8\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u7236\u7c7b\u6765\u5339\u914d\u591a\u4e2a\u5b50\u7c7b\uff0c\u4f8b\u5982 <code>+java.lang.Runnable<\/code> \u5c06\u5339\u914d\u6240\u6709\u5b9e\u73b0\u4e86 <code>java.lang.Runnable<\/code> \u63a5\u53e3\u7684\u7c7b\u3002<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.OnTimer<\/code>\uff1a\u8be5\u6ce8\u89e3\u7528\u4e8e\u6307\u5b9a\u8ddf\u8e2a\u7684\u52a8\u4f5c\u6bcf\u9694 N \u6beb\u79d2\u6267\u884c\u4e00\u6b21\u3002\u65f6\u95f4\u95f4\u9694\u901a\u8fc7 long \u578b\u7684 <code>value<\/code> \u5c5e\u6027\u6307\u5b9a\u3002<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.OnError<\/code>\uff1a\u8be5\u6ce8\u89e3\u7528\u4e8e\u6307\u5b9a\u5f53\u540c\u4e00\u4e2a BTrace \u7c7b\u7684\u5176\u4ed6\u63a2\u67e5\u7684\u52a8\u4f5c\u629b\u51fa\u4efb\u610f\u5f02\u5e38\u65f6\u6267\u884c\u7684\u52a8\u4f5c\u3002<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.OnExit<\/code>\uff1a\u5f53 BTrace \u4ee3\u7801\u8c03\u7528\u5185\u5efa\u51fd\u6570 <code>exit(int)<\/code> \u4ee5\u7ed3\u675f\u8ddf\u8e2a\u4f1a\u8bdd\u65f6\u6267\u884c\u7684\u52a8\u4f5c\u3002<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.OnEvent<\/code>\uff1a<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.OnLowMemory<\/code>\uff1a\u5f53\u8ddf\u8e2a\u7684\u5185\u5b58\u8d85\u51fa\u6307\u5b9a\u7684\u9608\u503c\u65f6\u6267\u884c\u7684\u52a8\u4f5c\u3002<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"java\">@BTrace \npublic class MemAlerter {\n  @OnLowMemory(\n      pool = \"Tenured Gen\",\n      threshold=6000000     \n  )\n  public static void onLowMem(MemoryUsage mu) {\n      println(mu); \n  }\n}\n<\/code><\/pre>\n<ul>\n<li><code>@com.sun.btrace.annotations.OnProbe<\/code>\uff1a<\/li>\n<\/ul>\n<h2>\u53c2\u6570\u6ce8\u89e3<\/h2>\n<ul>\n<li>\n<p><code>@com.sun.btrace.annotations.Self<\/code>\uff1a\u6807\u8bb0\u53c2\u6570\u6301\u6709 <code>this<\/code> \u6216 <code>self<\/code> \u7684\u503c\u3002<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.Return<\/code>\uff1a\u6807\u8bb0\u53c2\u6570\u6301\u6709\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.CallInstance<\/code>\uff1a\u6807\u8bb0\u53c2\u6570\u6301\u6709\u88ab\u8c03\u7528\u5b9e\u4f8b\u7684\u5f15\u7528\u3002<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.CalledMethod<\/code>\uff1a\u6807\u8bb0\u53c2\u6570\u6301\u6709\u88ab\u8c03\u7528\u65b9\u6cd5\u7684\u540d\u5b57\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6ce8\uff1a\u6bd4\u5982 A \u7c7b\u7684\u65b9\u6cd5 <code>methodA<\/code> \u8c03\u7528 B \u7c7b\u7684\u65b9\u6cd5 <code>methodB<\/code>\uff0c\u90a3\u4e48\u4e0a\u8ff0\u7684 <code>Self<\/code> \u5f15\u7528\u7684\u662f A \u7c7b\u7684\u5b9e\u4f8b\uff0c<code>CalledInstance<\/code> \u5f15\u7528\u7684\u662f B \u7c7b\u7684\u5b9e\u4f8b\uff0c<code>calledMethod<\/code> \u5f15\u7528\u7684\u662f <code>methodB<\/code> \u3002<\/p>\n<h2>\u5b57\u6bb5\u6ce8\u89e3<\/h2>\n<ul>\n<li>\n<p><code>@com.sun.btrace.annotations.Export<\/code> \u6ce8\u89e3\u4e0e BTrace \u5b57\u6bb5\uff08\u9759\u6001\u5b57\u6bb5\uff09\u4e00\u8d77\u4f7f\u7528\uff0c\u7528\u4e8e\u6307\u5b9a\u5b57\u6bb5\u6620\u5c04\u5230 JVM \u72b6\u6001\u8ba1\u6570\u5668\u3002\u901a\u8fc7\u5b83\uff0cBTrace \u7a0b\u5e8f\u53ef\u4ee5\u66b4\u9732\u8ddf\u8e2a\u8ba1\u6570\u5668\u7ed9\u5916\u90e8 JVM \u72b6\u6001\u5ba2\u6237\u7aef\uff08\u4f8b\u5982 <code>jstat<\/code>\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.Property<\/code> \u6ce8\u89e3\u7528\u4e8e\u6807\u8bb0\u6307\u5b9a\uff08\u9759\u6001\uff09\u5b57\u6bb5\u4e3a MBean \u7684\u5c5e\u6027\u3002\u5982\u679c BTrace \u7c7b\u6709\u81f3\u5c11\u4e00\u4e2a\u6709 <code>@Property<\/code> \u5c5e\u6027\u7684\u9759\u6001\u5b57\u6bb5\uff0c\u90a3\u4e48\u5c06\u521b\u5efa\u4e00\u4e2a MBean \u5e76\u6ce8\u518c\u5230\u5e73\u53f0\u7684 MBean \u670d\u52a1\u5668\u4e0a\u3002JMX \u5ba2\u6237\u7aef\u5982 VisualVM, jconsole \u53ef\u4ee5\u67e5\u770b\u8fd9\u4e9b BTrace MBean \u3002<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.TLS<\/code> \u6ce8\u89e3\u7528\u5728 BTrace \u9759\u6001\u5b57\u6bb5\u4e0a\uff0c\u7528\u4e8e\u6307\u5b9a\u7ebf\u7a0b\u672c\u5730\u53d8\u91cf\u3002\u6bcf\u4e2a Java \u7ebf\u7a0b\u5f97\u5230\u4e00\u4e2a\u72ec\u7acb\u7684\u8fd9\u4e2a\u5b57\u6bb5\u7684\u62f7\u8d1d\u3002\u8fd9\u4e9b BTrace \u7a0b\u5e8f\u4f7f\u7528\u7684\u7ebf\u7a0b\u672c\u5730\u53d8\u91cf\u53ef\u7528\u4e8e\u6807\u8bc6\u662f\u5426\u5728\u540c\u4e00\u4e2a\u7ebf\u7a0b\u91cc\u5230\u8fbe\u591a\u4e2a\u63a2\u67e5\u52a8\u4f5c\u3002<\/p>\n<\/li>\n<\/ul>\n<h2>\u7c7b\u6ce8\u89e3<\/h2>\n<ul>\n<li>\n<p><code>@com.sun.btrace.annotations.DTrace<\/code> \u6ce8\u89e3\u7528\u4e8e\u5173\u8054\u4e00\u4e2a\u7b80\u5355\u7684\u5355\u884c D-script \uff08\u5185\u8054\u5230 BTrace \u7684 Java \u7c7b\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.DTraceRef<\/code> \u6ce8\u89e3\u7528\u4e8e\u5173\u8054\u4e00\u4e2a D-script \uff08\u5b58\u50a8\u5728\u72ec\u7acb\u7684\u6587\u4ef6\u91cc\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><code>@com.sun.btrace.annotations.BTrace<\/code> \u6ce8\u89e3\u5fc5\u987b\u7528\u4e8e\u7ed9\u5b9a\u7684 Java \u7c7b\u4ee5\u4f5c\u4e3a BTrace \u7a0b\u5e8f\u3002\u8fd9\u4e2a\u6ce8\u89e3\u662f BTrace \u7f16\u8bd1\u5668\u548c BTrace \u4ee3\u7406\u5f3a\u5236\u8981\u6c42\u7684\u3002<\/p>\n<\/li>\n<\/ul>\n<h1>DTrace \u96c6\u6210<\/h1>\n<p>Solaris DTrace \u662f\u52a8\u6001\u3001\u5b89\u5168\u7684 Solaris \u7a0b\u5e8f\u8ddf\u8e2a\u5de5\u5177\uff0c\u53ef\u7528\u4e8e\u5185\u6838\u548c\u7528\u6237\u6001\u7a0b\u5e8f\u3002Because of the obvious parallels b\/w DTrace and BTrace, it is natural to expect integration b\/w BTrace and DTrace. There are two ways in which BTrace is integrated with DTrace.<\/p>\n<ul>\n<li>BTrace program can raise a DTrace probe &#8211; by calling dtraceProbe &#8212; see BTraceUtils javadoc referred above. For this feature to work, you need to be running on Solaris 10 or beyond. For other platforms (Solaris 9 or below or any other OS), dtraceProbe() will be a no-op.<\/li>\n<li>BTrace program can associate a D-script with it&#8211; by @DTrace annotation (if the D-script is a simple one liner) or by @DTraceRef if the D-script is longer and hence stored outside of the BTrace program. See DTrace integration samples in the BTrace samples section below. This feature works using the DTrace Java API. For this DTrace feature to work (o.e., being able to run associated D-script), you need to be running on Solaris 11 build 35 or beyond. You may want to check whether you have \/usr\/share\/lib\/java\/dtrace.jar on your machine or not. @DTrace and @DTraceRef annotations are ignored on other platforms (Solaris 10 or below or any other OS). <\/li>\n<\/ul>\n<h1>\u5b9e\u4f8b\u4ee3\u7801<\/h1>\n<p>\u5b9e\u4f8b\u4ee3\u7801\u8bf7\u67e5\u770b <a href=\"https:\/\/github.com\/btraceio\/btrace\/tree\/master\/samples\">samples<\/a><\/p>\n<hr\/>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7: <strong>coderbee\u7b14\u8bb0<\/strong>\uff0c\u53ef\u4ee5\u66f4\u53ca\u65f6\u56de\u590d\u4f60\u7684\u8ba8\u8bba\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"258\" src=\"https:\/\/coderbee.net\/wp-content\/uploads\/2019\/01\/coderbee-note.jpg\" class=\"alignnone size-full wp-image-1707\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\uff1a BTrace-usersguide BTrace \u662f\u7528\u4e8e Java \u7684\u5b89 &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/jvm\/20170514\/1519\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[96],"tags":[273],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1519"}],"collection":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/comments?post=1519"}],"version-history":[{"count":5,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1519\/revisions"}],"predecessor-version":[{"id":1528,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1519\/revisions\/1528"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=1519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=1519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=1519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}