Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_Time.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 // Kris
11 // 07.08.03 -- Move into Teuchos package/namespace
12 
13 #ifndef _TEUCHOS_TIME_HPP_
14 #define _TEUCHOS_TIME_HPP_
15 
20 #include "Teuchos_ConfigDefs.hpp"
21 
22 #include <ctime>
23 #ifdef HAVE_MPI
24 #include <mpi.h>
25 #else
26 #if ICL || defined(_WIN32)
27 #include <time.h>
28 #else
29 #include <sys/time.h>
30 #ifndef MINGW
31 #include <sys/resource.h>
32 #endif
33 #endif
34 #endif
35 
36 
37 namespace Teuchos {
38 
39 
53 class TEUCHOSCORE_LIB_DLL_EXPORT Time {
54 public:
60  Time (const std::string& name, bool start = false);
61 
67  static double wallTime ();
68 
75  void start (bool reset = false);
76 
78  double stop ();
79 
81  void disable ();
82 
84  void enable ();
85 
87  bool isEnabled () const {
88  return enabled_;
89  }
90 
102  double totalElapsedTime (bool readCurrentTime = false) const;
103 
105  void reset ();
106 
112  bool isRunning() const {
113  return isRunning_;
114  }
115 
117  const std::string& name() const {
118  return name_;
119  }
120 
123  void incrementNumCalls();
124 
126  int numCalls() const {return numCalls_;}
127 
128 private:
129  double startTime_;
130  double totalTime_;
131  bool isRunning_;
132  bool enabled_;
133  std::string name_;
134  int numCalls_;
135 #ifdef HAVE_TEUCHOS_TIME_MASSIF_SNAPSHOTS
136  // We don't want to rely on incrementNumCalls being called,
137  // because this does not seem to always happen in the same order.
138  // Sometimes after start() is called, sometimes after stop().
139  int numCallsMassifSnapshots_;
140 #endif
141 };
142 
143 
144 } // namespace Teuchos
145 
146 
147 #endif // TEUCHOS_TIME_HPP_
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
bool isEnabled() const
Whether the timer is enabled (see disable()).
Wall-clock timer.
bool isRunning() const
Whether the timer is currently running.
int numCalls() const
The number of times this timer has been called while enabled.
const std::string & name() const
The name of this timer.