47#if defined(__INTEL_COMPILER) && defined(_WIN32)
49#define WIN32_LEAN_AND_MEAN
55bool seconds_initialized =
false;
56LARGE_INTEGER start_count, count_freq;
58inline void seconds_initialize() {
59 if( seconds_initialized )
return;
60 std::cout <<
"\nCalling Win32 version of Teuchos::seconds_initialize()!\n";
62 ::QueryPerformanceFrequency( &count_freq );
65 ::SetThreadPriority( ::GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
67 assert( QueryPerformanceCounter( &start_count ) );
68 seconds_initialized =
true;
75#ifdef HAVE_TEUCHOS_TIME_MASSIF_SNAPSHOTS
81#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE)
84extern void pushRegion (
const std::string&);
85extern void popRegion ();
92#ifdef HAVE_TEUCHOS_TIME_MASSIF_SNAPSHOTS
93 void removeIllegalChars(std::string& s){
94 std::string illegalChars =
"\\/:?\"<>|";
95 for (
auto it = s.begin() ; it < s.end() ; ++it){
96 bool found = illegalChars.find(*it) != std::string::npos;
105 : startTime_(0), totalTime_(0), isRunning_(false), enabled_ (true), name_(name_in), numCalls_(0)
107 if(start_in) this->
start();
108#ifdef HAVE_TEUCHOS_TIME_MASSIF_SNAPSHOTS
109 numCallsMassifSnapshots_ = 0;
118#ifdef HAVE_TEUCHOS_TIME_MASSIF_SNAPSHOTS
119 if (numCallsMassifSnapshots_ < 100) {
120 std::string
filename =
"massif.out." + std::to_string(::getpid()) +
"." +
name_ +
"." + std::to_string(numCallsMassifSnapshots_) +
".start.out";
123 std::string cmd =
"snapshot " +
filename;
124 VALGRIND_MONITOR_COMMAND(cmd.data());
128#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE)
129 ::Kokkos::Profiling::pushRegion (
name_);
141#ifdef HAVE_TEUCHOS_TIME_MASSIF_SNAPSHOTS
142 if (numCallsMassifSnapshots_ < 100) {
143 std::string
filename =
"massif.out." + std::to_string(::getpid()) +
"." +
name_ +
"." + std::to_string(numCallsMassifSnapshots_) +
".stop.out";
146 std::string cmd =
"snapshot " +
filename;
147 VALGRIND_MONITOR_COMMAND(cmd.data());
148 numCallsMassifSnapshots_++;
151#if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE)
152 ::Kokkos::Profiling::popRegion ();
194 MPI_Initialized(&mpiInitialized);
196 if( mpiInitialized ) {
206 return( (
double)(
start ) / CLOCKS_PER_SEC );
210#elif defined(__INTEL_COMPILER) && defined(_WIN32)
212 seconds_initialize();
214 QueryPerformanceCounter( &count );
217 sec = (double)( count.QuadPart - start_count.QuadPart ) / count_freq.QuadPart;
221#elif ICL || defined(_WIN32)
226 return( (
double)(
start ) / CLOCKS_PER_SEC );
232 static long start = 0, startu;
235 gettimeofday(&tp, NULL);
240 gettimeofday(&tp, NULL);
241 return( ((
double) (tp.tv_sec -
start)) + (tp.tv_usec-startu)/1000000.0 );
243 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.