分享

btrace与匿名内部类

 碧海山城 2012-08-22

今天想跟踪下线上hbase几个方法的调用情况,主要是HTableget方法

 public Result get(final Get get) throws IOException {

    return new ServerCallable<Result>(connection, tableName, get.getRow(), operationTimeout) {

          public Result call() throws IOException {

            return server.get(location.getRegionInfo().getRegionName(), get);

          }

        }.withRetries();

  }a

里面有个匿名内部类,ServerCallable,先看看整体的get方法:

  @OnMethod(

      clazz="org.apache.hadoop.hbase.client.HTable",

      method="get",

      location=@Location(value=Kind.RETURN)

   )

   public static void trawwwwwceegin(@Duration long durationL){

        if(durationL>10000000){

                 println("more than 10 ms");

 

        }

  }

输出===============================================

org.apache.hadoop.hbase.client.HTable@a622ad

println("more than 10 ms");

正常输出,发现有蛮多大于10ms的,因此想看看withRetries方法内部的一些情况

 

Btrace脚本:

 @OnMethod(

      clazz="org.apache.hadoop.hbase.client.ServerCallable",

        method="withRetries",

      location=@Location(value=Kind.RETURN)

   )

   public static void tragin(@Self Object instance,@Return Object result,@Duration long durationL){

 

        if(durationL>10000000){

                println(instance);

                println(durationL);

                println(result);

        }

   }

输出如下

org.apache.hadoop.hbase.client.Result@54b34266

org.apache.hadoop.hbase.client.HTable$3@53a67d71

133527000

可以看到不能打出一个ServerCallable,而是HTable$3的实例

 

withRetries里面调用call

public T withRetries() {

    ......

    for (int tries = 0; tries < numRetries; tries++) {

      try {

        beforeCall();

        connect(tries != 0);

        return call();

      } catch (Throwable t) {

       .....

      }

      ......

    }

    return null;

  }

 

 

private static long count;

 @OnMethod(

      clazz="org.apache.hadoop.hbase.client.ServerCallable",

        method="withRetries",

       location=@Location(value=Kind.CALL, clazz="org.apache.hadoop.hbase.client.ServerCallable", method="call")

   )

   public static void tragin(@Self Object instance1,@ProbeClassName String pcm, @ProbeMethodName String pmn,@TargetInstance Object instance,  @TargetMethodOrField String method){

 

    println(strcat("ProbeClassName: ",pcm));   

     println(strcat("ProbeMethodName: ",pmn));  

     println(strcat("TargetInstance: ",str(classOf(instance))));  

println(strcat("self: ",str(classOf(instance1))));

     println(strcat("TargetMethodOrField : ",str(method)));  

 

   }

ProbeClassName: org/apache/hadoop/hbase/client/ServerCallable

ProbeMethodName: withRetries

TargetInstance: class org.apache.hadoop.hbase.client.HTable$3

self: class org.apache.hadoop.hbase.client.HTable$3

TargetMethodOrField : call

可以看到Class也变成HTable$3

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多