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[]) ...@@ -554,7 +554,6 @@ int mpd_main(int argc, char *argv[])
archive_plugin_deinit_all(); archive_plugin_deinit_all();
#endif #endif
config_global_finish(); config_global_finish();
stats_global_finish();
io_thread_deinit(); io_thread_deinit();
SignalHandlersFinish(); SignalHandlersFinish();
delete instance; delete instance;
......
...@@ -30,9 +30,11 @@ ...@@ -30,9 +30,11 @@
#include "Log.hxx" #include "Log.hxx"
#ifndef WIN32 #ifndef WIN32
#include <glib.h> /**
* The monotonic time stamp when MPD was started. It is used to
static GTimer *uptime; * calculate the uptime.
*/
static unsigned start_time;
#endif #endif
static DatabaseStats stats; static DatabaseStats stats;
...@@ -40,14 +42,7 @@ static DatabaseStats stats; ...@@ -40,14 +42,7 @@ static DatabaseStats stats;
void stats_global_init(void) void stats_global_init(void)
{ {
#ifndef WIN32 #ifndef WIN32
uptime = g_timer_new(); start_time = MonotonicClockS();
#endif
}
void stats_global_finish(void)
{
#ifndef WIN32
g_timer_destroy(uptime);
#endif #endif
} }
...@@ -107,7 +102,7 @@ stats_print(Client &client) ...@@ -107,7 +102,7 @@ stats_print(Client &client)
#ifdef WIN32 #ifdef WIN32
GetProcessUptimeS(), GetProcessUptimeS(),
#else #else
(unsigned)g_timer_elapsed(uptime, NULL), MonotonicClockS() - start_time,
#endif #endif
(unsigned long)(client.player_control.GetTotalPlayTime() + 0.5)); (unsigned long)(client.player_control.GetTotalPlayTime() + 0.5));
......
...@@ -24,8 +24,6 @@ class Client; ...@@ -24,8 +24,6 @@ class Client;
void stats_global_init(void); void stats_global_init(void);
void stats_global_finish(void);
void stats_update(void); void stats_update(void);
void void
......
...@@ -31,6 +31,28 @@ ...@@ -31,6 +31,28 @@
#endif #endif
unsigned 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) MonotonicClockMS(void)
{ {
#ifdef WIN32 #ifdef WIN32
......
...@@ -25,6 +25,13 @@ ...@@ -25,6 +25,13 @@
#include <stdint.h> #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. * Returns the value of a monotonic clock in milliseconds.
*/ */
gcc_pure 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