1 package samples.hotspot; 2 3 import alt.jiapi.*; 4 import alt.jiapi.util.*; 5 6 import org.apache.log4j.Category; 7 8 public class Sample2 extends HotSpotAdvice { 9 public static void main(String [] args) throws Exception { 10 String className = "samples.Foo"; 11 String resolution = "*"; if (args.length > 0) { 13 className = args[0]; 14 } 15 if (args.length > 1) { 16 resolution = args[1]; 17 } 18 19 new Sample2(className, resolution); 20 } 21 22 23 public Sample2(String className, String resolution) throws Exception { 24 InstrumentationContext ctx = new InstrumentationContext(); 26 InstrumentationDescriptor id = new InstrumentationDescriptor(); 27 id.addInclusionRule("samples.*"); 28 ctx.addInstrumentationDescriptor(id); 29 30 HotSpotAdvisor hsi = 31 new HotSpotAdvisor(id, this,HotSpotAdvisor.INVOCATIONS,resolution); 32 33 Bootstrapper.launch(className, null, ctx, 35 InstrumentingClassLoader.createClassLoader(ctx)); 36 } 37 38 39 47 public void advice() { 48 System.out.println("Calling a method: " + getHotSpotName()); 49 doHotSpot(); 50 System.out.println("Returned from method: " + getHotSpotName()); 51 } 52 } 53 | Popular Tags |