summaryrefslogtreecommitdiff
path: root/Source/CTest/cmProcess.cxx
diff options
context:
space:
mode:
authorWouter Klouwen <wouter.klouwen@youview.com>2017-11-03 13:25:33 +0000
committerWouter Klouwen <wouter.klouwen@youview.com>2017-11-14 13:30:14 +0000
commite8a4036e9621d567fa47a118aa5583f85fae811a (patch)
tree904b467a4470c1d48d435334b8406902bac690b3 /Source/CTest/cmProcess.cxx
parentb77501d4c7341337174f29cae623d8e1905af29a (diff)
downloadcmake-e8a4036e9621d567fa47a118aa5583f85fae811a.tar.gz
CTest: use std::chrono::steady_clock for time keeping
It was reported in issue #17345 that CTest does not use monotonic time to report test duration. Monotonic clocks are not affected by large NTP adjustments or things like daylight savings time. As CMake 3.10 requires C++11, which introduced std::chrono, this commit moves the time keeping in CTest from cmSystemTools::GetTime() to std::chrono::steady_clock. Fixes: #17345
Diffstat (limited to 'Source/CTest/cmProcess.cxx')
-rw-r--r--Source/CTest/cmProcess.cxx14
1 files changed, 9 insertions, 5 deletions
diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx
index f3c191b8a0..78dd59899b 100644
--- a/Source/CTest/cmProcess.cxx
+++ b/Source/CTest/cmProcess.cxx
@@ -3,8 +3,8 @@
#include "cmProcess.h"
#include "cmProcessOutput.h"
-#include "cmSystemTools.h"
#include <iostream>
+#include <type_traits>
cmProcess::cmProcess()
{
@@ -13,7 +13,7 @@ cmProcess::cmProcess()
this->TotalTime = 0;
this->ExitValue = 0;
this->Id = 0;
- this->StartTime = 0;
+ this->StartTime = std::chrono::steady_clock::time_point();
}
cmProcess::~cmProcess()
@@ -35,7 +35,7 @@ bool cmProcess::StartProcess()
if (this->Command.empty()) {
return false;
}
- this->StartTime = cmSystemTools::GetTime();
+ this->StartTime = std::chrono::steady_clock::now();
this->ProcessArgs.clear();
// put the command as arg0
this->ProcessArgs.push_back(this->Command.c_str());
@@ -143,7 +143,11 @@ int cmProcess::GetNextOutputLine(std::string& line, double timeout)
// Record exit information.
this->ExitValue = cmsysProcess_GetExitValue(this->Process);
- this->TotalTime = cmSystemTools::GetTime() - this->StartTime;
+ this->TotalTime =
+ static_cast<double>(std::chrono::duration_cast<std::chrono::milliseconds>(
+ std::chrono::steady_clock::now() - this->StartTime)
+ .count()) /
+ 1000.0;
// Because of a processor clock scew the runtime may become slightly
// negative. If someone changed the system clock while the process was
// running this may be even more. Make sure not to report a negative
@@ -231,7 +235,7 @@ void cmProcess::ChangeTimeout(double t)
void cmProcess::ResetStartTime()
{
cmsysProcess_ResetStartTime(this->Process);
- this->StartTime = cmSystemTools::GetTime();
+ this->StartTime = std::chrono::steady_clock::now();
}
int cmProcess::GetExitException()