EMMA Coverage Report (generated Sat Aug 20 11:00:51 CDT 2011)
[all classes][tuffy.util]

COVERAGE SUMMARY FOR SOURCE FILE [Timer.java]

nameclass, %method, %block, %line, %
Timer.java100% (2/2)41%  (9/22)38%  (135/360)43%  (29.8/69)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Timer$RunStat100% (1/1)12%  (1/8)14%  (25/181)22%  (7/32)
addTurn (double): void 0%   (0/1)0%   (0/13)0%   (0/3)
getFlipRate (): double 0%   (0/1)0%   (0/6)0%   (0/1)
getGroundTime (): double 0%   (0/1)0%   (0/3)0%   (0/1)
markGroundingDone (): void 0%   (0/1)0%   (0/4)0%   (0/2)
markInferDone (): void 0%   (0/1)0%   (0/7)0%   (0/2)
report (): void 0%   (0/1)0%   (0/118)0%   (0/14)
setInferOps (long): void 0%   (0/1)0%   (0/5)0%   (0/2)
Timer$RunStat (): void 100% (1/1)100% (25/25)100% (7/7)
     
class Timer100% (1/1)57%  (8/14)61%  (110/179)62%  (22.8/37)
Timer (): void 0%   (0/1)0%   (0/3)0%   (0/1)
elapsedMilliSeconds (String): double 0%   (0/1)0%   (0/17)0%   (0/4)
elapsedSeconds (): double 0%   (0/1)0%   (0/9)0%   (0/2)
printElapsed (): void 0%   (0/1)0%   (0/14)0%   (0/2)
printElapsed (String): void 0%   (0/1)0%   (0/19)0%   (0/2)
resetClock (): void 0%   (0/1)0%   (0/3)0%   (0/2)
elapsed (String): String 100% (1/1)88%  (15/17)75%  (3/4)
elapsedSeconds (String): double 100% (1/1)89%  (17/19)75%  (3/4)
<static initializer> 100% (1/1)100% (17/17)100% (6/6)
elapsed (): String 100% (1/1)100% (5/5)100% (1/1)
getDateTime (): String 100% (1/1)100% (11/11)100% (2/2)
now (): long 100% (1/1)100% (2/2)100% (1/1)
readTime (long): String 100% (1/1)100% (36/36)100% (5/5)
start (String): void 100% (1/1)100% (7/7)100% (2/2)

1package tuffy.util;
2import java.text.DateFormat;
3import java.text.SimpleDateFormat;
4import java.util.ArrayList;
5import java.util.Date;
6import java.util.Hashtable;
7 
8/**
9 * Container of time related utilities.
10 */
11public class Timer {
12 
13        private static long birth = now();
14        private static Hashtable<String, Long> points = new Hashtable<String, Long>();
15        
16        private static long secondInMillis = 1000;
17        private static long minuteInMillis = secondInMillis * 60;
18        
19        /**
20         * Resets the global starting point of the Timer.
21         */
22        public static void resetClock() {
23                birth = now();
24        }
25        
26        public static String getDateTime(){
27                DateFormat df = new SimpleDateFormat("H:mm:ss M/d/yy");
28                return df.format(new Date());
29        }
30        
31        /**
32         * Kicks off a timer with the given name.
33         */
34        public static void start(String name) {
35                points.put(name, now());
36        }
37        
38        /**
39         * Returns the elapsed time of the timer with the given name.
40         * The format is [XX minutes, YYseconds].
41         */
42        public static String elapsed(String name) {
43                if(!points.containsKey(name)) {
44                        return "[UNKNOWN TIMER]";
45                }else {
46                        long diff = now() - points.get(name);
47                        return readTime(diff);
48                }
49        }
50 
51        /**
52         * Returns the number of elapsed seconds of a given timer;
53         * -1 if the timer is unknown.
54         * @param name the name of the timer
55         */
56        public static double elapsedSeconds(String name) {
57                if(!points.containsKey(name)) {
58                        return -1;
59                }else {
60                        long diff = now() - points.get(name);
61                        return (diff / 1000);
62                }
63        }
64 
65        public static double elapsedMilliSeconds(String name) {
66                if(!points.containsKey(name)) {
67                        return -1;
68                }else {
69                        long diff = now() - points.get(name);
70                        return diff;
71                }
72        }
73 
74        /**
75         * Returns the number of elapsed seconds since last clock reset.
76         */
77        public static double elapsedSeconds() {
78                        long diff = now() - birth;
79                        return (diff / 1000.0);
80        }
81 
82        /**
83         * Prints the elapsed time since last clock reset.
84         * The format is TIMER: [XX minutes, YYseconds].
85         */
86        public static void printElapsed() {
87                UIMan.println("TIMER: " + elapsed());
88        }
89 
90        /**
91         * Prints the elapsed time of the timer with the given name.
92         * The format is TIMER name: [XX minutes, YYseconds].
93         */
94        public static void printElapsed(String name) {
95                UIMan.println("TIMER " + name + ": " + elapsed(name));
96        }
97 
98        private static long now() {
99                return System.currentTimeMillis();
100        }
101 
102        /**
103         * Returns a string of elapsed time.
104         */
105        public static String elapsed() {
106                return readTime(now() - birth);
107        }
108 
109        private static String readTime(long timeIntervalInMS) {
110                long min = timeIntervalInMS / minuteInMillis;
111                long sec = timeIntervalInMS / secondInMillis % 60;
112                long mm = timeIntervalInMS % 1000;
113                String t = String.format("[%d min, %d.%03d sec]", min, sec, mm);
114                return t;
115        }
116        
117        public static RunStat runStat = new RunStat();
118        
119        public static class RunStat{
120                public double groundSec = 0;
121                public double inferSec = 0;
122                public double inferOps = 0;
123                public long effectiveSteps = 0;
124                
125                public ArrayList<Double> turns = new ArrayList<Double>();
126                public ArrayList<Double> costs = new ArrayList<Double>();
127                
128                public void addTurn(double cost){
129                        turns.add(Timer.elapsedSeconds());
130                        costs.add(cost);
131                }
132                
133                public double getGroundTime(){
134                        return groundSec;
135                }
136                
137                public double getFlipRate(){
138                        return inferOps / inferSec;
139                }
140                
141                public void markGroundingDone(){
142                        groundSec = Timer.elapsedSeconds();
143                }
144                
145                public void markInferDone(){
146                        inferSec = Timer.elapsedSeconds() - groundSec;
147                }
148                
149                public void setInferOps(long ops){
150                        inferOps = ops;
151                }
152                
153                public void report(){
154                        System.out.println("============================");
155                        boolean report_trace = false;
156                        if(report_trace){
157                                System.out.println("Trace:");
158                                for(int i=0; i<turns.size(); i++){
159                                        System.out.println(turns.get(i) + "\t" + costs.get(i));
160                                }
161                        }
162                        System.out.println("Total run-time = " + UIMan.comma(groundSec + inferSec) + " sec");
163                        System.out.println("Ground time = " + UIMan.comma(groundSec) + " sec");
164                        System.out.println("Inference time = " + UIMan.comma(inferSec) + " sec");
165                        //System.out.println("Flip rate = " + getFlipRate());
166                        System.out.println("Effective #flips in MAP inference = " + UIMan.comma(effectiveSteps));
167                        System.out.println("Base memory = " + UIMan.comma(DebugMan.getBaseMem()) + " bytes");
168                        System.out.println("Peak memory = " + UIMan.comma(DebugMan.getPeakMem()) + " bytes");
169                        System.out.println("============================");
170                }
171        }
172        
173}

[all classes][tuffy.util]
EMMA 2.0.5312 EclEmma Fix 2 (C) Vladimir Roubtsov