Skip to content

Instantly share code, notes, and snippets.

@tnishada
Last active April 24, 2020 11:35
Show Gist options
  • Save tnishada/dc95e5a04a85e8052c6f6c7e4727fb9a to your computer and use it in GitHub Desktop.
Save tnishada/dc95e5a04a85e8052c6f6c7e4727fb9a to your computer and use it in GitHub Desktop.
public class MyAdvices {
@Advice.OnMethodEnter(suppress = Throwable.class)
static long enter(@Advice.This Object thisObject,
@Advice.Origin String origin,
@Advice.Origin("#t #m") String detaildOrigin,
@Advice.AllArguments Object[] ary,
@Advice.FieldValue(value = "name", readOnly = false) String nameField){
System.out.println("Inside enter method . . . ");
if(ary != null) {
for(int i =0 ; i < ary.length ; i++){
System.out.println("Argument: " + i + " is " + ary[i]);
}
}
System.out.println("Origin :" + origin);
System.out.println("Detailed Origin :" + detaildOrigin);
nameField = "Jack";
return System.nanoTime();
}
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
static void exit(@Advice.Enter long time){
System.out.println("Inside exit method . . .");
System.out.println("Method Execution Time: " + (System.nanoTime() - time) + " nano seconds");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment