import com.sun.btrace.BTraceUtils;
import static com.sun.btrace.BTraceUtils.*;
import com.sun.btrace.annotations.*;
import javax.servlet.http.HttpServletResponse;
//import org.geowebcache.layer.TileLayer;

@BTrace(unsafe=true)
public class Cache{

  @OnMethod(clazz="org.geowebcache.arcgis.layer.ArcGISCacheLayer"
        ,method = "setExpirationHeader",
        location=@Location(Kind.RETURN)
  )
  public static void setExpirationHeader(HttpServletResponse response, int zoomLevel){
    println(zoomLevel);
    println(response.getHeader("Cache-Control"));
    //jstack();
    //jstackAll();
  }

  @OnMethod(clazz="/org.geowebcache.layer\\..*/",method="getExpireClients",location=@Location(Kind.RETURN))
  public static void getExpireClients(@Return int zoomLevel){
    println("expire:"+zoomLevel);
  }

  @OnMethod(clazz="org.geowebcache.arcgis.layer.ArcGISCacheLayer" ,method="getTilePath" ,location=@Location(Kind.RETURN))
  public static void getTilePath(@Return String path){
    println(path);
  }

}

遇到的问题:

  1. 编译完用class文件执行报错,没有解决

    ./btrace 13801 Cache.class

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4202
	at com.sun.btrace.org.objectweb.asm.Cla***eader.readClass(Unknown Source)
	at com.sun.btrace.org.objectweb.asm.Cla***eader.accept(Unknown Source)
	at com.sun.btrace.org.objectweb.asm.Cla***eader.accept(Unknown Source)
	at com.sun.btrace.client.Client.getDTraceSource(Client.java:579)
	at com.sun.btrace.client.Client.submitDTrace(Client.java:554)
	at com.sun.btrace.client.Client.submit(Client.java:366)
	at com.sun.btrace.client.Main.main(Main.java:206)
Exception in thread "Thread-0" java.lang.IllegalStateException
	at com.sun.btrace.client.Client.send(Client.java:502)
	at com.sun.btrace.client.Client.sendExit(Client.java:436)
	at com.sun.btrace.client.Main$2.run(Main.java:239)
	at java.lang.Thread.run(Thread.java:748)

不编译加载多余的classpath报错,没有解决

Connection reset by peer


不编译加载正常的java文件可以运行

./btrace -v  -cp .:/data/gisserver/geoserver/lib/javax.servlet-api-3.1.0.jar 29733  Cache.java



开启非安全模式

编辑btrace脚本,在java启动命令中增加下面的参数

-Dcom.sun.btrace.unsafe=true

在java脚本中增加

@BTrace(unsafe=true)

注解