Stats: use GetProcessTimes() on WIN32 to determine MPD uptime
Don't use GTimer if the operating system is able to tell us the uptime.
This commit is contained in:
parent
e53a25cbae
commit
85b51e4e77
@ -26,21 +26,29 @@
|
|||||||
#include "DatabasePlugin.hxx"
|
#include "DatabasePlugin.hxx"
|
||||||
#include "DatabaseSimple.hxx"
|
#include "DatabaseSimple.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
|
#include "system/Clock.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
static GTimer *uptime;
|
static GTimer *uptime;
|
||||||
|
#endif
|
||||||
|
|
||||||
static DatabaseStats stats;
|
static DatabaseStats stats;
|
||||||
|
|
||||||
void stats_global_init(void)
|
void stats_global_init(void)
|
||||||
{
|
{
|
||||||
|
#ifndef WIN32
|
||||||
uptime = g_timer_new();
|
uptime = g_timer_new();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void stats_global_finish(void)
|
void stats_global_finish(void)
|
||||||
{
|
{
|
||||||
|
#ifndef WIN32
|
||||||
g_timer_destroy(uptime);
|
g_timer_destroy(uptime);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void stats_update(void)
|
void stats_update(void)
|
||||||
@ -94,9 +102,13 @@ void
|
|||||||
stats_print(Client &client)
|
stats_print(Client &client)
|
||||||
{
|
{
|
||||||
client_printf(client,
|
client_printf(client,
|
||||||
"uptime: %lu\n"
|
"uptime: %u\n"
|
||||||
"playtime: %lu\n",
|
"playtime: %lu\n",
|
||||||
(unsigned long)g_timer_elapsed(uptime, NULL),
|
#ifdef WIN32
|
||||||
|
GetProcessUptimeS(),
|
||||||
|
#else
|
||||||
|
(unsigned)g_timer_elapsed(uptime, NULL),
|
||||||
|
#endif
|
||||||
(unsigned long)(client.player_control.GetTotalPlayTime() + 0.5));
|
(unsigned long)(client.player_control.GetTotalPlayTime() + 0.5));
|
||||||
|
|
||||||
if (GetDatabase() != nullptr)
|
if (GetDatabase() != nullptr)
|
||||||
|
@ -96,3 +96,29 @@ MonotonicClockUS(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
gcc_const
|
||||||
|
static unsigned
|
||||||
|
DeltaFileTimeS(FILETIME a, FILETIME b)
|
||||||
|
{
|
||||||
|
ULARGE_INTEGER a2, b2;
|
||||||
|
b2.LowPart = b.dwLowDateTime;
|
||||||
|
b2.HighPart = b.dwHighDateTime;
|
||||||
|
a2.LowPart = a.dwLowDateTime;
|
||||||
|
a2.HighPart = a.dwHighDateTime;
|
||||||
|
return (a2.QuadPart - b2.QuadPart) / 10000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned
|
||||||
|
GetProcessUptimeS()
|
||||||
|
{
|
||||||
|
FILETIME creation_time, now;
|
||||||
|
GetProcessTimes(GetCurrentProcess(), &creation_time,
|
||||||
|
nullptr, nullptr, nullptr);
|
||||||
|
GetSystemTimeAsFileTime(&now);
|
||||||
|
|
||||||
|
return DeltaFileTimeS(now, creation_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -38,4 +38,15 @@ gcc_pure
|
|||||||
uint64_t
|
uint64_t
|
||||||
MonotonicClockUS();
|
MonotonicClockUS();
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the uptime of the current process in seconds.
|
||||||
|
*/
|
||||||
|
gcc_pure
|
||||||
|
unsigned
|
||||||
|
GetProcessUptimeS();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user