Instead of keeping track of the fraction of time that we're
[gem5.git] / sim / sim_time.hh
1 /*
2 * Copyright (c) 2003 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __SIM_TIME_HH__
30 #define __SIM_TIME_HH__
31
32 #include <sys/time.h>
33
34 #include <iosfwd>
35
36 namespace Time {
37 struct _timeval;
38 class Start
39 {
40 private:
41 mutable _timeval *start;
42
43 public:
44 Start();
45 ~Start();
46
47 const timeval &get() const;
48 void reset();
49 double operator()() const;
50 };
51
52 class Now
53 {
54 private:
55 mutable _timeval *now;
56
57 public:
58 Now();
59 ~Now();
60
61 const timeval &get() const;
62 double operator()() const;
63 };
64
65 class Elapsed
66 {
67 private:
68 mutable _timeval *elapsed;
69 Start _start;
70 Now _now;
71
72 public:
73 Elapsed();
74 ~Elapsed();
75
76 const timeval &get() const;
77 void reset();
78 double operator()() const;
79 };
80
81 extern Start start;
82 extern Now now;
83 extern Elapsed elapsed;
84
85 std::ostream &operator<<(std::ostream &out, const Start &start);
86 std::ostream &operator<<(std::ostream &out, const Now &now);
87 std::ostream &operator<<(std::ostream &out, const Elapsed &elapsed);
88 }
89
90 #endif // __SIM_TIME_HH__