Wednesday, December 19, 2012

Aspectj - trace method exection caller context details

http://mathewjhall.wordpress.com/2011/03/31/tracing-java-method-execution-with-aspectj/
:
Signature sig = thisJoinPointStaticPart.getSignature();
  String line =""+ thisJoinPointStaticPart.getSourceLocation().getLine();
  String sourceName = thisJoinPointStaticPart.getSourceLocation().getWithinType().getCanonicalName();
  Logger.getLogger("Tracing").log(
                Level.INFO, 
                "Call from "
                 +  sourceName
                    +" line " +
                    line
                    +" to " +sig.getDeclaringTypeName() + "." + sig.getName()
  );

jvisualvm remote tomcat

http://www.codefactorycr.com/java-visualvm-to-profile-a-remote-server.html
:
Start jstatd:
Given JAVA_HOME=/usr/lib/jvm/java-6-sun/bin
 Write following config to /usr/lib/jvm/java-6-sun/bin/jstatd.all.policy
grant codebase "file:<JAVA_HOME>/lib/tools.jar" {
permission java.security.AllPermission;};

 > /usr/lib/jvm/java-6-sun/bin/jstatd.all.policy

Then execute jstatd as
./jstatd -J-Djava.security.policy=jstatd.all.policy &


Identify jstatd ports as given in above link and make necessary firewall modifications.

Result: We can see the remote jstatd process in local jvisualvm as a remote process under the host.(plz add the host)

http://stackoverflow.com/questions/3892084/can-visualvm-connect-automatically-via-jmx-to-a-remote-process
:
Open tomcat's startup.sh and add following lines before the call
exec "$PRGDIR"/"$EXECUTABLE" start "$@"

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=60000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

 Now you can even see your server along with jstatd under the remote host.

For JConsole:
http://docs.oracle.com/javase/1.5.0/docs/guide/management/jconsole.html:
Just connect to <host>:60000 (port no. set in the jmx settings specified in JAVA_OPTS above) and it works.

Thanks,
Tapomay.