2 * Copyright 2001 Sun Microsystems, Inc.
4 * See the file "license.terms" for information on usage and
5 * redistribution of this file, and for a DISCLAIMER OF ALL
8 package com.sun.speech.freetts.util;
11 import java.util.LinkedHashMap;
12 import java.util.Collection;
13 import java.util.Iterator;
16 * Provides a suite of timers that are used to collect and generate
17 * performance metrics for FreeTTS.
19 public class BulkTimer {
21 * A BulkTimer that can be used by classes that need to
22 * time their loading phase.
24 public final static BulkTimer LOAD = new BulkTimer();
26 private final static String SELF = "OverallTime";
27 private boolean verbose;
32 * Creates a bulk timer.
36 timers = new LinkedHashMap();
40 * Starts the timer with the given name. A BulkTimer can manage
41 * any number of timers. The timers are referenced by name. A
42 * timer is created the first time it is referenced.
44 * @param name the name of the timer to start
46 public void start(String name) {
47 getTimer(name).start();
51 * Stops the timer with the given name.
53 * @param name the name of the timer
55 public void stop(String name) {
56 getTimer(name).stop(verbose);
60 * Starts the bulk timer. The BulkTimer maintains a timer for
61 * itself (called SELF). This is used to measure the overall time
62 * for a bulk timer. When timing data is displayed, the percentage
63 * of total time is displayed. The total time is the time between
64 * <code> start </code> and <code> end </code> calls on the
65 * <code> BulkTimer </code> .
68 getTimer(SELF).start();
73 * Stops the bulk timer.
76 getTimer(SELF).stop(verbose);
82 * @param verbose the verbose mode
84 public void setVerbose(boolean verbose) {
85 this.verbose = verbose;
89 * Checks to see if we are in verbose mode.
91 * @return <code>true</code> if verbose mode; otherwise
94 public boolean isVerbose() {
99 * Gets the timer with the given name.
101 * @param name the timer name
103 * @return the timer with that name
105 public Timer getTimer(String name) {
106 if (!timers.containsKey(name)) {
107 timers.put(name, new Timer(name));
109 return (Timer) timers.get(name);
113 * Shows all of the collected times.
115 * @param title the title for the display
117 public void show(String title) {
118 long overall = getTimer(SELF).getCurrentTime();
119 Collection values = timers.values();
120 Timer.showTimesShortTitle(title);
121 for (Iterator i = values.iterator(); i.hasNext(); ) {
122 Timer t = (Timer) i.next();
123 t.showTimes(overall);