Files
TheRock/rocm-systems/projects/rocprofiler-systems/external/dyninst/dataflowAPI/rose/util/Stopwatch.C
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

110 lines
2.6 KiB
C++

// WARNING: Changes to this file must be contributed back to Sawyer or else they will
// be clobbered by the next update from Sawyer. The Sawyer repository is at
// https://github.com/matzke1/sawyer.
#include "Sawyer.h"
#include "Stopwatch.h"
#include <iostream>
#if defined(SAWYER_HAVE_BOOST_CHRONO)
#include <chrono>
#elif defined(_WIN32)
# include <time.h>
# include <windows.h>
# undef ERROR // not sure where this pollution comes from
# undef max // more pollution
#else // POSIX
# include <sys/time.h> // gettimeofday() and struct timeval
#endif
namespace Sawyer {
static Stopwatch::TimePoint getCurrentTime() {
#if defined(SAWYER_HAVE_BOOST_CHRONO)
return std::chrono::high_resolution_clock::now();
#elif defined(_WIN32)
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
unsigned __int64 t = ft.dwHighDateTime;
t <<= 32;
t |= ft.dwLowDateTime;
t /= 10; // convert into microseconds
//t -= 11644473600000000Ui64; // convert file time to microseconds since Unix epoch
return t / 1e6;
#else // POSIX
struct timeval t;
if (-1==gettimeofday(&t, NULL))
return 0.0;
return t.tv_sec + 1e-6 * t.tv_usec;
#endif
}
SAWYER_EXPORT double
Stopwatch::report(bool clear) const {
if (running_) {
TimePoint now = getCurrentTime();
elapsed_ += now - begin_;
begin_ = now;
}
#ifdef SAWYER_HAVE_BOOST_CHRONO
double retval = elapsed_.count();
#else
double retval = elapsed_;
#endif
if (clear)
elapsed_ = Duration();
return retval;
}
SAWYER_EXPORT double
Stopwatch::start() {
double retval = report(false);
if (!running_) {
begin_ = getCurrentTime();
running_ = true;
}
return retval;
}
SAWYER_EXPORT double
Stopwatch::start(double value) {
double retval = report(false);
elapsed_ = Duration(value);
if (!running_) {
begin_ = getCurrentTime();
running_ = true;
}
return retval;
}
SAWYER_EXPORT double
Stopwatch::restart() {
return start(0.0);
}
SAWYER_EXPORT double
Stopwatch::stop(bool clear) {
double retval = report(clear);
running_ = false;
return retval;
}
SAWYER_EXPORT double
Stopwatch::clear(double value) {
double retval = stop();
elapsed_ = Duration(value);
return retval;
}
SAWYER_EXPORT std::ostream&
operator<<(std::ostream &out, const Stopwatch &x) {
out <<x.report();
return out;
}
} // namespace