コード例 #1
0
 /**
  * Creates an aggregate of the passed long values
  *
  * @param values the longs to aggregate
  * @return An array of longs containing <b><code>AVG, MIN, MAX</code></b>.
  */
 public static long[] aggregate(long... values) {
   if (values == null || values.length < 1) return new long[] {0, 0, 0};
   long[] aggr = new long[3];
   long max = Long.MIN_VALUE;
   long min = Long.MAX_VALUE;
   int cnt = 0;
   BigDecimal total = new BigDecimal(0);
   for (long value : values) {
     if (value == -1) continue;
     total = total.add(BigDecimal.valueOf(value));
     if (value > max) max = value;
     if (value < min) min = value;
     cnt++;
   }
   try {
     aggr[0] = (cnt != 0 && total.longValue() > 0) ? (SimpleMath.avg(cnt, total.longValue())) : 0;
   } catch (Exception e) {
     System.err.println(
         "Failed to compute average for a total of ["
             + total
             + "] and count ["
             + cnt
             + "]. Stack trace follows:");
     e.printStackTrace(System.err);
   }
   aggr[1] = min == Long.MAX_VALUE ? -1 : min;
   aggr[2] = max == Long.MIN_VALUE ? -1 : max;
   return aggr;
 }
コード例 #2
0
 /**
  * Returns an aggregate of the passed ThreadBenchmarkResult
  *
  * @param results the ThreadBenchmarkResult to aggregate
  * @return the aggregate
  */
 public static AggregatedThreadBenchmarkResult aggregate(ThreadBenchmarkResult... results) {
   long[] args = new long[LONG_VALUE_CNT];
   AggregatedElapsedTime aggregatedElapsedTime =
       AggregatedElapsedTime.aggregate(getElapsedTimes(results));
   int index = 0;
   long[] values = getAggregate("AvgPerOpMs", results);
   args[index++] = values[0];
   args[index++] = values[1];
   args[index++] = values[2];
   values = getAggregate("AvgPerOpNs", results);
   args[index++] = values[0];
   args[index++] = values[1];
   args[index++] = values[2];
   values = getAggregate("BlockCount", results);
   args[index++] = values[0];
   args[index++] = values[1];
   args[index++] = values[2];
   values = getAggregate("BlockTime", results);
   args[index++] = values[0];
   args[index++] = values[1];
   args[index++] = values[2];
   values = getAggregate("WaitCount", results);
   args[index++] = values[0];
   args[index++] = values[1];
   args[index++] = values[2];
   values = getAggregate("WaitTime", results);
   args[index++] = values[0];
   args[index++] = values[1];
   args[index++] = values[2];
   values = getAggregate("ElapsedSysCpu", results);
   args[index++] = values[0];
   args[index++] = values[1];
   args[index++] = values[2];
   final int opCount = results[0].opCount;
   args[index++] = SimpleMath.avg(opCount, values[0]);
   args[index++] = SimpleMath.avg(opCount, values[1]);
   args[index++] = SimpleMath.avg(opCount, values[2]);
   return new AggregatedThreadBenchmarkResult(aggregatedElapsedTime, args);
 }