001 /*
002 Galois, a framework to exploit amorphous data-parallelism in irregular
003 programs.
004
005 Copyright (C) 2010, The University of Texas at Austin. All rights reserved.
006 UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS SOFTWARE
007 AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR ANY
008 PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF PERFORMANCE, AND ANY
009 WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF DEALING OR USAGE OF TRADE.
010 NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH RESPECT TO THE USE OF THE
011 SOFTWARE OR DOCUMENTATION. Under no circumstances shall University be liable
012 for incidental, special, indirect, direct or consequential damages or loss of
013 profits, interruption of business, or related expenses which may arise from use
014 of Software or Documentation, including but not limited to those resulting from
015 defects in Software and/or Documentation, or loss or inaccuracy of data of any
016 kind.
017
018 File: RuntimeStatistics.java
019
020 */
021
022 package util;
023
024 import java.io.PrintStream;
025 import java.util.ArrayList;
026 import java.util.List;
027
028 /**
029 * Runtime statistics (wall-clock time) with and without garbage collection
030 * time. This class is intended to repeatedly measure the same piece of code
031 * and return a summary of the measured runtimes.
032 *
033 *
034 */
035 public class RuntimeStatistics extends Statistics {
036 private final List<Long> times;
037 private final List<Long> timesWithGc;
038
039 public RuntimeStatistics() {
040 this.times = new ArrayList<Long>();
041 this.timesWithGc = new ArrayList<Long>();
042 }
043
044 /**
045 * Adds the measured times to the accumulated statistics.
046 *
047 * @param time wall-clock time in milliseconds <i>excluding</i> garbage collection time
048 * @param timeWithGc wall-clock time in milliseconds <i>including</i> garbage collection time
049 */
050 public void putStats(long time, long timeWithGc) {
051 times.add(time);
052 timesWithGc.add(timeWithGc);
053 }
054
055 @Override
056 public void dumpFull(PrintStream out) {
057 printFullHeader(out, "Runtimes");
058 out.printf("Without GC (ms): %s\n", times);
059 summarizeLongs(out, times, 0, "\t");
060 out.printf("With GC (ms): %s\n", timesWithGc);
061 summarizeLongs(out, timesWithGc, 0, "\t");
062 }
063
064 @Override
065 public void dumpSummary(PrintStream out) {
066 printSummaryHeader(out, "Runtimes (ms)");
067 float[] wgc = summarizeLongs(timesWithGc, 1);
068 float[] wogc = summarizeLongs(times, 1);
069 boolean output = wgc != null;
070 summarizeLongs(out, timesWithGc, 1, "", output);
071 if (output) {
072 float rel = 0;
073 if (wgc[0] != 0)
074 rel = (wgc[0] - wogc[0]) / wgc[0];
075 out.printf(" Rel. GC time: %.4f\n", rel);
076 }
077 }
078
079 @Override
080 public void merge(Object obj) {
081 RuntimeStatistics other = (RuntimeStatistics) obj;
082 times.addAll(other.times);
083 timesWithGc.addAll(other.timesWithGc);
084 }
085 }