source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDshowTimer.java @ 235

Last change on this file since 235 was 235, checked in by sherbold, 13 years ago
  • added commands startTimer, showTimer for measuring time of experiments
  • Property svn:mime-type set to text/plain
File size: 1.4 KB
Line 
1package de.ugoe.cs.eventbench.commands;
2
3import java.security.InvalidParameterException;
4import java.util.List;
5
6import de.ugoe.cs.eventbench.data.GlobalDataContainer;
7import de.ugoe.cs.util.console.Command;
8import de.ugoe.cs.util.console.Console;
9
10/**
11 * <p>
12 * Command to show the time elapsed since a timer has been started.
13 * </p>
14 *
15 * @author Steffen Herbold
16 * @version 1.0
17 */
18public class CMDshowTimer implements Command {
19
20        /*
21         * (non-Javadoc)
22         *
23         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
24         */
25        @Override
26        public void run(List<Object> parameters) {
27                String timerName;
28                try {
29                        timerName = (String) parameters.get(0);
30                } catch (Exception e) {
31                        throw new InvalidParameterException();
32                }
33
34                Object dataObject = (Long) GlobalDataContainer.getInstance().getData(
35                                timerName);
36                if (dataObject == null) {
37                        Console.printerrln("No object with name " + timerName + " found");
38                        return;
39                }
40                if (!(dataObject instanceof Long)) {
41                        Console.printerrln("Object " + timerName + " not of type Long!");
42                        return;
43                }
44
45                long startTime = (Long) dataObject;
46                long currentTime = System.currentTimeMillis();
47                Console.println("" + (currentTime - startTime) + " miliseconds");
48        }
49
50        /*
51         * (non-Javadoc)
52         *
53         * @see de.ugoe.cs.util.console.Command#help()
54         */
55        @Override
56        public void help() {
57                Console.println("Usage: showTimer <timerName>");
58        }
59
60}
Note: See TracBrowser for help on using the repository browser.