Stats: use monotonic clock instead of GTimer
Reduce GLib usage.
This commit is contained in:
parent
85b51e4e77
commit
529b4bd185
@ -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 @@
|
|||||||
#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;
|
|||||||
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)
|
|||||||
#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;
|
|||||||
|
|
||||||
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
|
||||||
|
@ -30,6 +30,28 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#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
|
unsigned
|
||||||
MonotonicClockMS(void)
|
MonotonicClockMS(void)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +24,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.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user