Commit 529b4bd1 authored by Max Kellermann's avatar Max Kellermann

Stats: use monotonic clock instead of GTimer

Reduce GLib usage.
parent 85b51e4e
......@@ -554,7 +554,6 @@ int mpd_main(int argc, char *argv[])
archive_plugin_deinit_all();
#endif
config_global_finish();
stats_global_finish();
io_thread_deinit();
SignalHandlersFinish();
delete instance;
......
......@@ -30,9 +30,11 @@
#include "Log.hxx"
#ifndef WIN32
#include <glib.h>
static GTimer *uptime;
/**
* The monotonic time stamp when MPD was started. It is used to
* calculate the uptime.
*/
static unsigned start_time;
#endif
static DatabaseStats stats;
......@@ -40,14 +42,7 @@ static DatabaseStats stats;
void stats_global_init(void)
{
#ifndef WIN32
uptime = g_timer_new();
#endif
}
void stats_global_finish(void)
{
#ifndef WIN32
g_timer_destroy(uptime);
start_time = MonotonicClockS();
#endif
}
......@@ -107,7 +102,7 @@ stats_print(Client &client)
#ifdef WIN32
GetProcessUptimeS(),
#else
(unsigned)g_timer_elapsed(uptime, NULL),
MonotonicClockS() - start_time,
#endif
(unsigned long)(client.player_control.GetTotalPlayTime() + 0.5));
......
......@@ -24,8 +24,6 @@ class Client;
void stats_global_init(void);
void stats_global_finish(void);
void stats_update(void);
void
......
......@@ -31,6 +31,28 @@
#endif
unsigned
MonotonicClockS(void)
{
#ifdef WIN32
return GetTickCount() / 1000;
#elif defined(__APPLE__) /* OS X does not define CLOCK_MONOTONIC */
static mach_timebase_info_data_t base;
if (base.denom == 0)
(void)mach_timebase_info(&base);
return (unsigned)((mach_absolute_time() * base.numer / 1000)
/ (1000000 * base.denom));
#elif defined(CLOCK_MONOTONIC)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec;
#else
/* we have no monotonic clock, fall back to time() */
return time(nullptr);
#endif
}
unsigned
MonotonicClockMS(void)
{
#ifdef WIN32
......
......@@ -25,6 +25,13 @@
#include <stdint.h>
/**
* Returns the value of a monotonic clock in seconds.
*/
gcc_pure
unsigned
MonotonicClockS();
/**
* Returns the value of a monotonic clock in milliseconds.
*/
gcc_pure
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment