Sometimes you need some rough estimates on your code performances, there are a lot of tools to do that but a quick solution to get an idea is to use Apache Sirona. Let see how to set it up on TomEE Maven Plugin pretty quickly.

Apache Sirona has a lot of instrumentation modes but I'll use the javaagent one since it avoids to modify the deployment. I'll use the snapshot to be able to dump the performances in the log but you can also install the webapp to visually see it:

<javaagents>
  <javaagent>org.apache.sirona:sirona-javaagent:0.5-incubating-SNAPSHOT:jar:shaded</javaagent>
</javaagents>

Then we need to configure it, let say I want to identify some hotspot in com.oracle.driver and com.company.business packages, I'll activate counter instrumentation (method execution time), skip the path tracking (execution hierarchy) and include these packages. The easiest is to put it in system properties so in tomee it looks like:

<systemVariables>
  <org.apache.sirona.store.counter.CounterDataStore>org.apache.sirona.store.counter.LoggingCounterDataStore</org.apache.sirona.store.counter.CounterDataStore>
  <org.apache.sirona.logging.counter.period>15000</org.apache.sirona.logging.counter.period>
  <org.apache.sirona.javaagent.path.tracking.activate>false</org.apache.sirona.javaagent.path.tracking.activate>
  <org.apache.sirona.javaagent.listener.CounterListener.includes>prefix:com.company.business.,prefix:com.oracle.driver.</org.apache.sirona.javaagent.listener.CounterListener.includes>
</systemVariables>

You can note I put only 15s as "dump" period to have a faster feedback, the default is 1mn.

Then just run tomee and you will get in the logs this kind of lines each 15s:

INFOS - DefaultCounter{concurrency=0, key=name=com.oracle.driver.Blog.demo(com.oracle.driver.TableMetadata), maxConcurrency=1, statistics=OptimizedStatistics{n=53, sum=12678.0, min=192.0, max=1112.0, m1=239.20754716981133, m2=805232.716981132}}

Works well but you get a cumulative counter with that which means it is hard to know the diff between 2 dumps if the startup was long compared the 15s run, to avoid it you can add this property:

<org.apache.sirona.logging.counter.clearOnCollect>true</org.apache.sirona.logging.counter.clearOnCollect>

Where do all the xml goes? just straight in tomee-maven-plugin configuration block:

<plugin>
  <groupId>org.apache.tomee.maven</groupId>
  <artifactId>tomee-maven-plugin</artifactId>
  <version>${version.tomee}</version>
  <configuration>
    <javaagents>
      <javaagent>org.apache.sirona:sirona-javaagent:0.5-incubating-SNAPSHOT:jar:shaded</javaagent>
    </javaagents>
    <systemVariables>
      <org.apache.sirona.store.counter.CounterDataStore>org.apache.sirona.store.counter.LoggingCounterDataStore</org.apache.sirona.store.counter.CounterDataStore>
      <org.apache.sirona.logging.counter.period>15000</org.apache.sirona.logging.counter.period>
      <org.apache.sirona.javaagent.path.tracking.activate>false</org.apache.sirona.javaagent.path.tracking.activate>
      <org.apache.sirona.javaagent.listener.CounterListener.includes>prefix:com.company.</org.apache.sirona.javaagent.listener.CounterListener.includes>
    </systemVariables>
  </configuration>
</plugin>

Another tip is, if you want to get access to these metrics through JMX just add in system properties:

<org.apache.sirona.counter.with-jmx>true</org.apache.sirona.counter.with-jmx>

Finally if you want to import it as CSV in Excel or Calc you can use:

sed 's/.* key=name=//' /tmp/perf | sed 's/statistics=OptimizedStatistics{//' | sed 's/}}//' | sed 's/(.*)//' | sed 's/,[^,]*=/,/g'

Columns will be: 

name concurrency count sum min max m1 m2

If you want to avoid that use the CsvLoggingCounterDataStore flavor instead of the previous one and it will directly log a csv format with these columns:

name role count concurrency max min mean sum stddev

Happy investigations ;)

From the same author:

In the same category: