aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Main.cxx1
-rw-r--r--src/Stats.cxx19
-rw-r--r--src/Stats.hxx2
-rw-r--r--src/system/Clock.cxx22
-rw-r--r--src/system/Clock.hxx7
5 files changed, 36 insertions, 15 deletions
diff --git a/src/Main.cxx b/src/Main.cxx
index b45e2c3ae..6023e8bed 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -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;
diff --git a/src/Stats.cxx b/src/Stats.cxx
index a188d88ba..e22f1a995 100644
--- a/src/Stats.cxx
+++ b/src/Stats.cxx
@@ -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));
diff --git a/src/Stats.hxx b/src/Stats.hxx
index dd131ce19..63b96c4d6 100644
--- a/src/Stats.hxx
+++ b/src/Stats.hxx
@@ -24,8 +24,6 @@ class Client;
void stats_global_init(void);
-void stats_global_finish(void);
-
void stats_update(void);
void
diff --git a/src/system/Clock.cxx b/src/system/Clock.cxx
index 17b221c15..8fbd76d22 100644
--- a/src/system/Clock.cxx
+++ b/src/system/Clock.cxx
@@ -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
diff --git a/src/system/Clock.hxx b/src/system/Clock.hxx
index 28df0c7e0..1c3651a99 100644
--- a/src/system/Clock.hxx
+++ b/src/system/Clock.hxx
@@ -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