aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet/src/Timers.cc
blob: 4460c0eaa97ecbaf9dd8fc4531b2e32e91111bd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <cassert>
#include <cstdio>
#include <cstring>
#include <list>

#include <cctk.h>
#include <cctk_Parameters.h>
#include <util_String.h>

#if HAVE_UNISTD_H
#  include <fcntl.h>
#  include <unistd.h>
#endif

#include <defs.hh>

#include <Timers.hh>
#include <TimerNode.hh>



namespace Carpet {
  
  using namespace std;

/*********************************************************************
 Timer
 *********************************************************************/

  /// Create a timer with a given name, but do not start it, and do
  /// not associate it with a point in the timer hierarchy.
  Timer::Timer(const string &name_p) : d_name(name_p)
  {
  }

  /// Destroy a timer
  Timer::~Timer ()
  {
  }

  /// Start the timer and insert it into the tree of timers as a child
  /// of the most recently started timer that has not been stopped.
  void Timer::start ()
  {
    TimerNode  *current_timer = TimerNode::getCurrentTimer();
    assert(current_timer);
    current_timer->getChildTimer(name())->start();
  }

  /// Stop the timer - it must be the most recently started timer
  void Timer::stop ()
  {
    TimerNode::getCurrentTimer()->stop();
  }

  /// Return the name of the timer
  string Timer::name () const
  {
    return d_name;
  }

  /// Return the current time of the timer as a double
  double Timer::getTime()
  {
    return TimerNode::getCurrentTimer()->getTime();
  }
} // namespace Carpet