<!--btrace start-->
<dependency>
<groupId>com.sun.tools.btrace</groupId>
<artifactId>btrace-agent</artifactId>
<version>1.3.11.3</version>
<scope>system</scope>
<systemPath>/Users/i075496/soft/btrace-bin-1.3.11.3/build/btrace-agent.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sun.tools.btrace</groupId>
<artifactId>btrace-boot</artifactId>
<version>1.3.11.3</version>
<scope>system</scope>
<systemPath>/Users/i075496/soft/btrace-bin-1.3.11.3/build/btrace-boot.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sun.tools.btrace</groupId>
<artifactId>btrace-client</artifactId>
<version>1.3.11.3</version>
<scope>system</scope>
<systemPath>/Users/i075496/soft/btrace-bin-1.3.11.3/build/btrace-client.jar</systemPath>
</dependency>
<!--btrace end-->
package com.sap.olingo.demo8.controller;
import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
//This is just a sample to demo method info, performance profiling and exception trace for BTrace
@GetMapping(path="btracetest")
public String btraceTest(@RequestParam String str1, @RequestParam int int2) {
Random rd = new Random();
try {
Thread.sleep(rd.nextInt(2000) + 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return str1 + " : " + int2;
}
}
import com.sun.btrace.BTraceUtils;
import com.sun.btrace.annotations.*;
@BTrace
public class BTraceTest {
@OnMethod(clazz = "com.sap.olingo.demo8.controller.HelloController", method = "btraceTest", location = @Location(Kind.RETURN))
public static void methodDetail(@Self Object self, String str1, int int2, @Return String result, @Duration long time) {
BTraceUtils.println();
BTraceUtils.println();
BTraceUtils.println("Invoke info from method detail trace: ");
BTraceUtils.println("parameter: str1=" + str1 + ", int2=" + int2);
BTraceUtils.println("return: result=" + result);
BTraceUtils.println("cost time(ns): " + time);
BTraceUtils.println();
}
}
import com.sun.btrace.BTraceUtils;
import com.sun.btrace.annotations.*;
@BTrace
public class BTraceTest {
@OnMethod(clazz = "com.sap.olingo.demo8.controller.HelloController", method="/.*/", location = @Location(Kind.RETURN))
public static void onProfiling(@ProbeClassName String className, @ProbeMethodName String methodName, @Duration long time) {
if(time / 1000000000L >= 2){
BTraceUtils.println();
BTraceUtils.println();
BTraceUtils.println("Invoke info from profiling trace: ");
BTraceUtils.println("className: " + className + ", methodName: " + methodName + ", duration: " + ((double)time) / 1000000000);
BTraceUtils.println();
}
}
}
import com.sun.btrace.BTraceUtils;
import com.sun.btrace.annotations.*;
@BTrace
public class BTraceTest {
@OnMethod(clazz="java.lang.Throwable",method="<init>",location=@Location(Kind.RETURN))
public static void excepionDetail(@Self Throwable self){
BTraceUtils.println();
BTraceUtils.println();
BTraceUtils.println("Invoke info from exception trace: ");
BTraceUtils.Threads.jstack(self);
BTraceUtils.println();
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |