Introduce common::ToSeconds for std::chrono::steady_clock::duration. (#1244)

Introduce a new overload of ToSeconds for std::chrono::steady_clock and use it for the work queue delay metric.
master
Arno Fleck 2018-07-09 20:13:17 +02:00 committed by Wally B. Feed
parent eff103f663
commit 9e54a981c6
4 changed files with 8 additions and 6 deletions

View File

@ -31,6 +31,11 @@ double ToSeconds(const Duration duration) {
.count();
}
double ToSeconds(const std::chrono::steady_clock::duration duration) {
return std::chrono::duration_cast<std::chrono::duration<double>>(duration)
.count();
}
Time FromUniversal(const int64 ticks) { return Time(Duration(ticks)); }
int64 ToUniversal(const Time time) { return time.time_since_epoch().count(); }

View File

@ -49,6 +49,7 @@ Duration FromMilliseconds(int64 milliseconds);
// Returns the given duration in seconds.
double ToSeconds(Duration duration);
double ToSeconds(std::chrono::steady_clock::duration duration);
// Creates a time from a Universal Time Scale.
Time FromUniversal(int64 ticks);

View File

@ -151,9 +151,7 @@ void PoseGraph2D::AddWorkItem(const std::function<void()>& work_item) {
const auto now = std::chrono::steady_clock::now();
work_queue_->push_back({now, work_item});
kWorkQueueDelayMetric->Set(
std::chrono::duration_cast<std::chrono::duration<double>>(
now - work_queue_->front().time)
.count());
common::ToSeconds(now - work_queue_->front().time));
}
}

View File

@ -149,9 +149,7 @@ void PoseGraph3D::AddWorkItem(const std::function<void()>& work_item) {
const auto now = std::chrono::steady_clock::now();
work_queue_->push_back({now, work_item});
kWorkQueueDelayMetric->Set(
std::chrono::duration_cast<std::chrono::duration<double>>(
now - work_queue_->front().time)
.count());
common::ToSeconds(now - work_queue_->front().time));
}
}