timer: support for walltime
* spot/misc/timer.hh: here.
This commit is contained in:
parent
765bb8a7c4
commit
9a9a237272
1 changed files with 18 additions and 1 deletions
|
|
@ -33,7 +33,7 @@
|
||||||
# include <sys/times.h>
|
# include <sys/times.h>
|
||||||
#endif
|
#endif
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace spot
|
namespace spot
|
||||||
{
|
{
|
||||||
|
|
@ -96,6 +96,7 @@ namespace spot
|
||||||
{
|
{
|
||||||
SPOT_ASSERT(!running);
|
SPOT_ASSERT(!running);
|
||||||
running = true;
|
running = true;
|
||||||
|
wall_start_ = std::chrono::high_resolution_clock::now();
|
||||||
#ifdef SPOT_HAVE_TIMES
|
#ifdef SPOT_HAVE_TIMES
|
||||||
struct tms tmp;
|
struct tms tmp;
|
||||||
times(&tmp);
|
times(&tmp);
|
||||||
|
|
@ -112,6 +113,9 @@ namespace spot
|
||||||
void
|
void
|
||||||
stop()
|
stop()
|
||||||
{
|
{
|
||||||
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
wall_cumul_ = std::chrono::duration_cast
|
||||||
|
<std::chrono::milliseconds>(end - wall_start_).count();
|
||||||
#ifdef SPOT_HAVE_TIMES
|
#ifdef SPOT_HAVE_TIMES
|
||||||
struct tms tmp;
|
struct tms tmp;
|
||||||
times(&tmp);
|
times(&tmp);
|
||||||
|
|
@ -194,10 +198,23 @@ namespace spot
|
||||||
return running;
|
return running;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Return cumulative wall time
|
||||||
|
///
|
||||||
|
/// When using multithreading the cpu time is not
|
||||||
|
/// relevant and we have to deal with wall time to have an
|
||||||
|
/// effective timer
|
||||||
|
std::chrono::milliseconds::rep
|
||||||
|
walltime() const
|
||||||
|
{
|
||||||
|
return wall_cumul_;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
time_info start_;
|
time_info start_;
|
||||||
time_info total_;
|
time_info total_;
|
||||||
bool running;
|
bool running;
|
||||||
|
std::chrono::high_resolution_clock::time_point wall_start_;
|
||||||
|
std::chrono::milliseconds::rep wall_cumul_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This function declared here must be implemented in each file
|
// This function declared here must be implemented in each file
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue