package com.newatlanta.appengine.debug;

import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import com.google.apphosting.api.ApiProxy.Delegate;
import com.google.apphosting.api.ApiProxy.Environment;
import com.google.apphosting.api.ApiProxy.LogRecord;

public class ProfilingDelegate implements Delegate<Environment> {
    
    private static final Logger log = Logger.getLogger( ProfilingDelegate.class.getName() );
    
    private Delegate<Environment> parent;
    
    public ProfilingDelegate( Delegate<Environment> parent ) {
      this.parent = parent;
    }
    
    public byte[] makeSyncCall( Environment env, String pkg, String method, byte[] request ) {
      long start = System.nanoTime();
      byte[] result = parent.makeSyncCall( env, pkg, method, request );
      log.info( pkg + "." + method + ": " +
              TimeUnit.MILLISECONDS.convert( System.nanoTime() - start, TimeUnit.NANOSECONDS ) + "ms" );
      return result;
    }
    
    public void log(Environment env, LogRecord logRec) {
        parent.log(env, logRec);
    }

}

@@ -32,24 +32,61 @@
 e.debug;%0D%0A%0D%0A
+import java.util.concurrent.Future;%0D%0A
 import java.
@@ -144,24 +144,78 @@
 .Logger;%0D%0A%0D%0A
+import com.google.apphosting.api.ApiProxy.ApiConfig;%0D%0A
 import com.g
@@ -1074,32 +1074,510 @@
  result;%0D%0A    %7D%0D
+%0A%0D%0A    @Override%0D%0A    public Future%3Cbyte%5B%5D%3E makeAsyncCall( Environment env, String pkg, String method,%0D%0A            byte%5B%5D request, ApiConfig apiConfig ) %7B%0D%0A        long start = System.nanoTime();%0D%0A        Future%3Cbyte%5B%5D%3E result = parent.makeAsyncCall( env, pkg, method, request, apiConfig );%0D%0A        log.info( pkg + %22.%22 + method + %22: %22 +%0D%0A                TimeUnit.MILLISECONDS.convert( System.nanoTime() - start, TimeUnit.NANOSECONDS ) + %22ms%22 );%0D%0A        return result;%0D%0A    %7D%0D
 %0A    %0D%0A    publi
@@ -1659,20 +1659,18 @@
 gRec);%0D%0A
+
     %7D%0D%0A
-%0D%0A
 %7D%0D%0A

upgrade to SDK 1.2.8