14#include "Teuchos_Behavior.hpp"
16#if defined(__INTEL_COMPILER) && defined(_WIN32)
18#define WIN32_LEAN_AND_MEAN
24bool seconds_initialized =
false;
25LARGE_INTEGER start_count, count_freq;
27inline void seconds_initialize() {
28 if( seconds_initialized )
return;
29 std::cout <<
"\nCalling Win32 version of Teuchos::seconds_initialize()!\n";
31 ::QueryPerformanceFrequency( &count_freq );
34 ::SetThreadPriority( ::GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
36 assert( QueryPerformanceCounter( &start_count ) );
37 seconds_initialized =
true;
44#ifdef HAVE_TEUCHOS_TIME_MASSIF_SNAPSHOTS
50#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
53extern void pushRegion (
const std::string&);
54extern void popRegion ();
59#ifdef HAVE_TEUCHOSCORE_KOKKOS
60#include "Kokkos_Core.hpp"
65#ifdef HAVE_TEUCHOS_TIME_MASSIF_SNAPSHOTS
66 void removeIllegalChars(std::string& s){
67 std::string illegalChars =
"\\/:?\"<>|";
68 for (
auto it = s.begin() ; it < s.end() ; ++it){
69 bool found = illegalChars.find(*it) != std::string::npos;
78 : startTime_(0), totalTime_(0), isRunning_(false), enabled_ (true), name_(name_in), numCalls_(0)
80 if(start_in) this->
start();
81#ifdef HAVE_TEUCHOS_TIME_MASSIF_SNAPSHOTS
82 numCallsMassifSnapshots_ = 0;
90 if (reset_in) totalTime_ = 0;
91#ifdef HAVE_TEUCHOS_TIME_MASSIF_SNAPSHOTS
92 if (numCallsMassifSnapshots_ < 100) {
93 std::string filename =
"massif.out." + std::to_string(::getpid()) +
"." + name_ +
"." + std::to_string(numCallsMassifSnapshots_) +
".start.out";
94 removeIllegalChars(filename);
95 std::replace(filename.begin(), filename.end(),
' ',
'_');
96 std::string cmd =
"snapshot " + filename;
97 VALGRIND_MONITOR_COMMAND(cmd.data());
101#ifdef HAVE_TEUCHOSCORE_KOKKOS
102 if (Behavior::fenceTimers()) {
103 Kokkos::fence(
"timer_fence_begin_"+name_);
106#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
107 ::Kokkos::Tools::pushRegion (name_);
116 totalTime_ += (
wallTime() - startTime_ );
119#ifdef HAVE_TEUCHOS_TIME_MASSIF_SNAPSHOTS
120 if (numCallsMassifSnapshots_ < 100) {
121 std::string filename =
"massif.out." + std::to_string(::getpid()) +
"." + name_ +
"." + std::to_string(numCallsMassifSnapshots_) +
".stop.out";
122 removeIllegalChars(filename);
123 std::replace(filename.begin(), filename.end(),
' ',
'_');
124 std::string cmd =
"snapshot " + filename;
125 VALGRIND_MONITOR_COMMAND(cmd.data());
126 numCallsMassifSnapshots_++;
129#ifdef HAVE_TEUCHOSCORE_KOKKOS
130 if (Behavior::fenceTimers()) {
131 Kokkos::fence(
"timer_fence_end_"+name_);
134#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOS)
135 ::Kokkos::Tools::popRegion ();
145 return wallTime() - startTime_ + totalTime_;
177 MPI_Initialized(&mpiInitialized);
179 if( mpiInitialized ) {
189 return( (
double)(
start ) / CLOCKS_PER_SEC );
193#elif defined(__INTEL_COMPILER) && defined(_WIN32)
195 seconds_initialize();
197 QueryPerformanceCounter( &count );
200 sec = (double)( count.QuadPart - start_count.QuadPart ) / count_freq.QuadPart;
204#elif ICL || defined(_WIN32)
209 return( (
double)(
start ) / CLOCKS_PER_SEC );
215 static long start = 0, startu;
218 gettimeofday(&tp, NULL);
223 gettimeofday(&tp, NULL);
224 return( ((
double) (tp.tv_sec -
start)) + (tp.tv_usec-startu)/1000000.0 );
226 return( (
double) clock() / CLOCKS_PER_SEC );
Basic wall-clock timer class.
void enable()
"Enable" this timer, so that it (again) respects calls to start() and stop().
void incrementNumCalls()
Increment the number of times this timer has been called, if the timer is enabled (see disable()).
double totalElapsedTime(bool readCurrentTime=false) const
The total time in seconds accumulated by this timer.
void reset()
Reset the cummulative time and call count.
void start(bool reset=false)
Start the timer, if the timer is enabled (see disable()).
double stop()
Stop the timer, if the timer is enabled (see disable()).
void disable()
"Disable" this timer, so that it ignores calls to start() and stop().
Time(const std::string &name, bool start=false)
Constructor.
static double wallTime()
Current wall-clock time in seconds.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...