Java Simon - usage of time by method (in percentage (%))

24 views
Skip to first unread message

michalwlo...@gmail.com

unread,
Jun 9, 2015, 3:55:57 AM6/9/15
to java...@googlegroups.com
Does there exist a possibility to receive 'usage of time by method (in percentage (%))' from the Java simon library? If so, how can I use it?

Richard Richter

unread,
Jun 9, 2015, 3:59:40 AM6/9/15
to java...@googlegroups.com
Hi

If you mean something like profiling the method, I doubt Java Simon is
the best tool for that. In any case, the numbers on a single Stopwatch
(associated with some method) are absolute. So you need to have the
"total" time of some kind to do the math. And - of course - from the
principle point, there is no way how to get % of so called "self-time"
of the method - unless again, you measure all the subcalls and do the
math. But this clearly calls for a profiler, not for this library.

Virgo

On Tue, Jun 9, 2015 at 9:50 AM, <michalwlo...@gmail.com> wrote:
> Does there exist a possibility to receive 'usage of time by method (in
> percentage (%))' from the Java simon library? If so, how can I use it?
>
> --
> You received this message because you are subscribed to the Google Groups
> "javasimon" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to javasimon+...@googlegroups.com.
> To post to this group, send email to java...@googlegroups.com.
> Visit this group at http://groups.google.com/group/javasimon.
> For more options, visit https://groups.google.com/d/optout.

michalwlo...@gmail.com

unread,
Jun 9, 2015, 4:34:12 AM6/9/15
to java...@googlegroups.com
Ok, thank you Virgo for your answer.

One more question, exist a possibility to receive output like this:

method: play 10s

  method: ala 6s

      method: bbb 2s

      method ccc: 2s

?


play = ala + bbb + ccc (10 = 6 + 2 + 2)

Richard Richter

unread,
Jun 9, 2015, 5:30:01 AM6/9/15
to java...@googlegroups.com
If you have Simons (in this case Stopwatch-es) in a hierarchy (like
ala, ala.bbb and ala.ccc) than you can calculate their aggregate on
demand with:

// somehow get hold of "ala" Simon, e.g.
Stopwatch ala = SimonManager.getStopwach("ala");
StopwatchAggregate aggregate = SimonUtils.calculateStopwatchAggregate(ala);

It is possible to filter the stopwatches you want using SimonFilter.
Please, check the Javadoc, which states that if Simon is not accepted
by the filter, the whole subtree is not aggregated. BTW, all counters
are ignored by default, as they are of different type but they don't
disrupt aggregation of the subtree, unless they don't match the
filter. You can use Simon attributes to mark those that should be
aggregated:
StopwatchAggregate aggregate =
SimonUtils.calculateStopwatchAggregate(SimonManager.getRootSimon(),
new SimonFilter() {
@Override
public boolean accept(Simon simon) {
return simon.getAttribute("aggregated") != null;
}
});

However currently it is not possible to traverse the hierarchy and
"cherry-pick" only aggregated Simons, because - as said above - if the
simon is not aggregated itself, it stops the aggregation of its
subtree.

Virgo

michalwlo...@gmail.com

unread,
Jun 9, 2015, 6:08:49 AM6/9/15
to java...@googlegroups.com
Thank you for your answer.

My "structure of methods":

methodA() {
  methodB()
}

Implementation (dirty code):

         ...
        Stopwatch stopwatch = SimonManager.getStopwatch(clazz + "." + method);
        Split split = stopwatch.start();
        Object ret = context.proceed();
        split.stop();

        CounterAggregate cA = SimonUtils.calculateCounterAggregate(stopwatch);
        StopwatchAggregate sA =SimonUtils.calculateStopwatchAggregate(stopwatch);
       
        if (simonLogger != null) {
            simonLogger.log(Level.INFO, SimonUtils.simonTreeString(SimonManager.getRootSimon()));
            simonLogger.log(Level.INFO, cA.toString());
            simonLogger.log(Level.INFO, sA.toString());
        }

INFO: (+): Unknown Simon:  [ ENABLED]
  g(+): Unknown Simon:  [g INHERIT]
    srv(+): Unknown Simon:  [g.srv INHERIT]
      GS(+): Unknown Simon:  [g.srv.GSl INHERIT]
        methodA(+): Simon Stopwatch: total 2.13 s, counter 1, max 2.13 s, min 2.13 s, mean 2.13 s [g.srv.GS.methodA INHERIT]

Jun 09, 2015 12:00:10 PM g.srv.util.logger.SimonLogger log
INFO: CounterAggregate{counter=0, incrementSum=0, decrementSum=0, max=undef, min=undef, maxTimestamp=undef, minTimestamp=undef}
Jun 09, 2015 12:00:10 PM g.srv.util.logger.SimonLogger log
INFO: StopwatchAggregate{total= 2.13 s, counter=1, min=2.13 s, max=2.13 s, minTimestamp=150609-120010.590, maxTimestamp=150609-120010.590, active=0, maxActive=1, maxActiveTimestamp=150609-120008.460}

In this way, I don't have any information about methodB...

Do I do something wrong ? I am confused

Richard Richter

unread,
Jun 9, 2015, 6:14:09 AM6/9/15
to java...@googlegroups.com
It seems you use some interceptor around the methods. Are you sure it
is working also around methodB() call? It doesn't seem so. I'm not
sure what kind of "container" you use, but e.g. in a Spring
@Component, if you call methodA() on @Autowired field from another
object, it does all the AOP work. But if you call methodB() inside the
same object, it doesn't. This is basic Spring stuff. I'm not sure if
this is the case or not. Debugger will tell you whether your
interceptor works everytime you think it does.

But this doesn't seem to be related to Simon anymore.

Cheers

Virgo
Reply all
Reply to author
Forward
0 new messages