Added function GetThreadCpuTimeSeconds in common/time.h (#1267)
This will be needed for measuring SLAM performance.master
parent
5abd413310
commit
dce713b442
|
@ -16,8 +16,13 @@
|
|||
|
||||
#include "cartographer/common/time.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "glog/logging.h"
|
||||
|
||||
namespace cartographer {
|
||||
namespace common {
|
||||
|
||||
|
@ -50,5 +55,12 @@ common::Duration FromMilliseconds(const int64 milliseconds) {
|
|||
std::chrono::milliseconds(milliseconds));
|
||||
}
|
||||
|
||||
double GetThreadCpuTimeSeconds() {
|
||||
struct timespec thread_cpu_time;
|
||||
CHECK(clock_gettime(CLOCK_THREAD_CPUTIME_ID, &thread_cpu_time) == 0)
|
||||
<< std::strerror(errno);
|
||||
return thread_cpu_time.tv_sec + 1e-9 * thread_cpu_time.tv_nsec;
|
||||
}
|
||||
|
||||
} // namespace common
|
||||
} // namespace cartographer
|
||||
|
|
|
@ -60,6 +60,9 @@ int64 ToUniversal(Time time);
|
|||
// For logging and unit tests, outputs the timestamp integer.
|
||||
std::ostream& operator<<(std::ostream& os, Time time);
|
||||
|
||||
// CPU time consumed by the thread so far, in seconds.
|
||||
double GetThreadCpuTimeSeconds();
|
||||
|
||||
} // namespace common
|
||||
} // namespace cartographer
|
||||
|
||||
|
|
Loading…
Reference in New Issue