Welcome!

Java Authors: Liz McMillan, Hovhannes Avoyan, Yeshim Deniz, Roger Strukhoff, David H Deans

Related Topics: Java, XML, SOA & WOA, AJAX & REA, Apache

Java: Article

Instrument Java Code Your Way: TraceView Java API

Have you seen a slowdown in your code, and have some methods you’d like to check?

When it comes to analyzing your web application's performance, TraceView already has instruments in a wide spectrum of Java components, such as application servers, frameworks and JDBC connections, all with the convenience of simply including TraceView Java agent jar in your JVM. However, have you come across situations that make you think, "It would have been nice if this was traced too"? You can do this with the TraceView Java API.

Don't feel like coding? Just annotate it!

Shame on you, tablecache.

Have you seen a slowdown in your code, and have some methods you'd like to check? The simplest way is to add the @LogMethod or @ProfileMethod annotation to those methods. Invocations to those methods will then be traced by the Java agent and reflected on your TraceView panels. Since you can assign different layer/profile names for those methods, you can easily group them and gather useful statistics from your TraceView pages! (Heat map, layer/profile summary etc). You might even turn on back trace tracking or store the method return values by tweaking various optional parameters. A simple guide could be found here.

Need more power? Add a few lines of code
TraceView Java Agent was built for web applications, so traces are normally triggered by web requests. However, this does not mean you are limited to tracing web applications. In fact, you can even trace stand-alone applications with TraceView Java Agent with just a couple lines of code!

For example, you may have a day-end process that perform several scheduled tasks which each run in its own separate thread, some tasks may involve database operations. Adding the 2 steps below not only measures the timing of the job, but also any of the database calls that were invoked during the task itself.

Java API

But wait... where is the code that traces the database operations? You do not need to worry about it! In fact, once you start a Trace using the API, anything comes down the calling stack with layer recognized by TraceView Java Agent (JDBC, Apache Http Client, etc.) will be instrumented.

java

Try it out.

That's it. Kick start the Java process with the TraceView Java Agent and you will start seeing traces of your custom layer on the jobs. By assigning different layer names, you can easily customize the groupings, and even handle different concurrency models by digging into the full API. Sign up for a free account, and start tracing today.

Related Articles

Tracing Black Boxes I: JMX Insight Into JVM Performance

Solving Slow Database Performance In Java and MySQL

TraceView: Now With Free Tracing (and more)!

More Stories By Patson Luk

A Java developer who has spent the better part of the last decade working on financial services applications with companies from HSBC to Mobilearth and Parasoft, Patson is experienced in various aspects of computer systems, from large scale enterprise banking system to lightweight mobile payment solutions. He now leads Java instrumentation and tool development for the TraceView product at AppNeta. Patson's focus is on using java bytecode manipulation technologies to gain greater visibility into the full spectrum of Java based technologies. This includes higher level application frameworks from Spring and Struts to Webflow, AppServers from TomCat to JBoss, and Databases from MySQL to Oracle. He's also writes frequently on the AppNeta blog - www.appneta.com/blog