예제 #1
0
 /** {@inheritDoc} */
 public final CounterSample getCounterSample(String name) {
   Simon s = manager.getSimon(name);
   if (s != null && s instanceof Counter) {
     return new CounterSample((org.javasimon.CounterSample) s.sample());
   }
   return null;
 }
예제 #2
0
 /** {@inheritDoc} */
 public final StopwatchSample getStopwatchSampleAndReset(String name) {
   Simon s = manager.getSimon(name);
   if (s != null && s instanceof Stopwatch) {
     return new StopwatchSample((org.javasimon.StopwatchSample) s.sampleAndReset());
   }
   return null;
 }
 /**
  * Generates Google bar chart URL for last values of all collected Simons.
  *
  * @param collector data collector
  * @param title chart title
  * @param divisor value divisor. For example: if values are in ns and ms are required, divisor
  *     should be set to 1000000.
  * @param unit unit shown after values under every bar
  * @return URL generating the bar chart
  */
 public static String barChart(
     AbstractDataCollector collector, String title, double divisor, String unit) {
   final StringBuilder result = new StringBuilder(URL_START).append(TYPE_BAR);
   result.append("&chtt=").append(encode(title));
   final StringBuilder x0 = new StringBuilder("&chxl=0:");
   final StringBuilder x1 = new StringBuilder("|1:");
   final StringBuilder data = new StringBuilder("&chd=t:");
   double max = 0;
   boolean first = true;
   for (final Simon simon : collector.getSimons()) {
     if (first) {
       first = false;
     } else {
       data.append(',');
     }
     final List<Double> values = collector.valuesFor(simon);
     double lastValue = values.get(values.size() - 1) / divisor;
     x0.append('|').append(encode(simon.getName()));
     String formattedValue = NUMBER_FORMAT.format(lastValue);
     x1.append('|').append(formattedValue).append("+").append(unit);
     if (lastValue > max) {
       max = lastValue;
     }
     data.append(formattedValue);
   }
   double division = Math.pow(TEN_BASE, Math.floor(Math.log10(max)));
   StringBuilder x2 = new StringBuilder("|2:");
   double x = 0;
   for (; x < max + division; x += division) {
     x2.append('|').append(Double.valueOf(x).longValue());
   }
   result.append("&chxr=2,0,").append(Double.valueOf(x - division).longValue());
   result.append("&chds=0,").append(Double.valueOf(x - division).longValue());
   result.append(x0).append(x1).append(x2).append(data);
   result.append("&.png");
   return result.toString();
 }
예제 #4
0
 /**
  * Visit Simons recursively as a tree starting from the specified Simon.
  *
  * @param simon Parent simon
  * @param visitor Visitor
  * @throws IOException
  */
 public static void visitTree(Simon simon, SimonVisitor visitor) throws IOException {
   visitor.visit(simon);
   for (Simon childSimon : simon.getChildren()) {
     visitTree(childSimon, visitor);
   }
 }