Created
November 2, 2016 05:17
-
-
Save caoxudong/7a44d1270e87ed06c16e0d261e8a0653 to your computer and use it in GitHub Desktop.
统计某个方法中调用另一个方法的次数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.sun.btrace.annotations.*; | |
import static com.sun.btrace.BTraceUtils.*; | |
@BTrace | |
public class OfferTrace { | |
@TLS | |
private static long startTime = 0; | |
@TLS | |
private static boolean startCount = false; | |
@TLS | |
private static long callExchangeCount = 0; | |
@OnMethod(clazz = "org.springframework.web.client.RestTemplate", method = "exchange") | |
public static void startStatCallMethod(){ | |
if (startCount) { | |
callExchangeCount = callExchangeCount + 1; | |
} | |
} | |
@OnMethod(clazz = "demo.caoxudong.Demo", method = "testMethod") | |
public static void startMethod(){ | |
startTime = timeMillis(); | |
startCount = true; | |
} | |
@OnMethod(clazz = "demo.caoxudong.Demo", method = "testMethod", location = @Location(Kind.RETURN)) | |
public static void endMethod(){ | |
startCount = false; | |
print(str(callExchangeCount)); | |
// println( | |
// strcat( | |
// strcat( | |
// strcat( | |
// "the class method execute time=>", | |
// str(timeMillis() - startTime) | |
// ), | |
// ", call exchange times = " | |
// ), | |
// str(callExchangeCount) | |
// ) | |
// ); | |
println("-------------------------------------------"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment