From 96f889276f95a7c9b9882f53423556e1bf17e6a2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 May 2019 15:42:47 +0200 Subject: [PATCH] system/Clock: GetProcessUptimeS() returns std::chrono::duration --- src/Stats.cxx | 12 +++++++----- src/system/Clock.cxx | 6 +++--- src/system/Clock.hxx | 6 ++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Stats.cxx b/src/Stats.cxx index 2bf4458fc..1e913e54f 100644 --- a/src/Stats.cxx +++ b/src/Stats.cxx @@ -114,13 +114,15 @@ db_stats_print(Response &r, const Database &db) void stats_print(Response &r, const Partition &partition) { +#ifdef _WIN32 + const auto uptime = GetProcessUptimeS(); +#else + const auto uptime = std::chrono::steady_clock::now() - start_time; +#endif + r.Format("uptime: %u\n" "playtime: %lu\n", -#ifdef _WIN32 - GetProcessUptimeS(), -#else - (unsigned)std::chrono::duration_cast(std::chrono::steady_clock::now() - start_time).count(), -#endif + (unsigned)std::chrono::duration_cast(uptime).count(), std::lround(partition.pc.GetTotalPlayTime().count())); #ifdef ENABLE_DATABASE diff --git a/src/system/Clock.cxx b/src/system/Clock.cxx index f0f1cd1c1..a4dc9ef89 100644 --- a/src/system/Clock.cxx +++ b/src/system/Clock.cxx @@ -23,7 +23,7 @@ #include gcc_const -static unsigned +static std::chrono::seconds DeltaFileTimeS(FILETIME a, FILETIME b) { ULARGE_INTEGER a2, b2; @@ -31,10 +31,10 @@ DeltaFileTimeS(FILETIME a, FILETIME b) b2.HighPart = b.dwHighDateTime; a2.LowPart = a.dwLowDateTime; a2.HighPart = a.dwHighDateTime; - return (a2.QuadPart - b2.QuadPart) / 10000000; + return std::chrono::seconds((a2.QuadPart - b2.QuadPart) / 10000000); } -unsigned +std::chrono::seconds GetProcessUptimeS() { FILETIME creation_time, exit_time, kernel_time, user_time, now; diff --git a/src/system/Clock.hxx b/src/system/Clock.hxx index 6a10bcbde..62a7f7aba 100644 --- a/src/system/Clock.hxx +++ b/src/system/Clock.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -22,13 +22,15 @@ #include "util/Compiler.h" +#include + #ifdef _WIN32 /** * Returns the uptime of the current process in seconds. */ gcc_pure -unsigned +std::chrono::seconds GetProcessUptimeS(); #endif