diff options
author | Max Kellermann <max@duempel.org> | 2009-01-18 15:40:53 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-18 15:40:53 +0100 |
commit | 004dfddca383394426f6d191a43c9a0131cdee34 (patch) | |
tree | 6f23a82122f02c63e7830dfa812e017f6c80d837 | |
parent | 14ca99b22469808642034813156281a203cfee5e (diff) | |
download | mpd-004dfddca383394426f6d191a43c9a0131cdee34.tar.gz mpd-004dfddca383394426f6d191a43c9a0131cdee34.tar.xz mpd-004dfddca383394426f6d191a43c9a0131cdee34.zip |
stats: use GTimer instead of time(NULL)
time(NULL) shows the wrong results when the machine's clock is
changed.
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/stats.c | 9 | ||||
-rw-r--r-- | src/stats.h | 6 |
3 files changed, 13 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c index d5bb98dc0..ee6efd194 100644 --- a/src/main.c +++ b/src/main.c @@ -350,6 +350,7 @@ int main(int argc, char *argv[]) songvec_deinit(); dirvec_deinit(); idle_deinit(); + stats_global_finish(); close_log_files(); return EXIT_SUCCESS; diff --git a/src/stats.c b/src/stats.c index c85c705d7..937ca3e3f 100644 --- a/src/stats.c +++ b/src/stats.c @@ -29,7 +29,12 @@ struct stats stats; void stats_global_init(void) { - stats.start_time = time(NULL); + stats.timer = g_timer_new(); +} + +void stats_global_finish(void) +{ + g_timer_destroy(stats.timer); } struct visit_data { @@ -107,7 +112,7 @@ int stats_print(struct client *client) stats.artist_count, stats.album_count, stats.song_count, - time(NULL) - stats.start_time, + (long)g_timer_elapsed(stats.timer, NULL), (long)(getPlayerTotalPlayTime() + 0.5), stats.song_duration, db_get_mtime()); diff --git a/src/stats.h b/src/stats.h index 0c82cb16c..c783eb052 100644 --- a/src/stats.h +++ b/src/stats.h @@ -19,10 +19,12 @@ #ifndef MPD_STATS_H #define MPD_STATS_H +#include <glib.h> + struct client; struct stats { - unsigned long start_time; + GTimer *timer; /** number of song files in the music directory */ unsigned song_count; @@ -42,6 +44,8 @@ extern struct stats stats; void stats_global_init(void); +void stats_global_finish(void); + void stats_update(void); int stats_print(struct client *client); |