diff options
author | Max Kellermann <max@duempel.org> | 2013-11-23 18:45:02 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-11-23 18:45:02 +0100 |
commit | 99527051b5751d2ef7c6b593f1beda84d1bcc33f (patch) | |
tree | 39b08616c597fc173022164050ed557650c177b5 /src/Stats.cxx | |
parent | bed98303a346dd98e2a239579c032d170440441d (diff) | |
parent | 57e0cc54424561499039967aa501c17d4b179019 (diff) | |
download | mpd-99527051b5751d2ef7c6b593f1beda84d1bcc33f.tar.gz mpd-99527051b5751d2ef7c6b593f1beda84d1bcc33f.tar.xz mpd-99527051b5751d2ef7c6b593f1beda84d1bcc33f.zip |
Merge branch 'v0.18.x'
Diffstat (limited to 'src/Stats.cxx')
-rw-r--r-- | src/Stats.cxx | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/src/Stats.cxx b/src/Stats.cxx index 88f76928f..f224bdf49 100644 --- a/src/Stats.cxx +++ b/src/Stats.cxx @@ -30,59 +30,75 @@ #include <glib.h> -struct stats stats; +static GTimer *uptime; +static DatabaseStats stats; void stats_global_init(void) { - stats.timer = g_timer_new(); + uptime = g_timer_new(); } void stats_global_finish(void) { - g_timer_destroy(stats.timer); + g_timer_destroy(uptime); } void stats_update(void) { + assert(GetDatabase() != nullptr); + Error error; DatabaseStats stats2; const DatabaseSelection selection("", true); if (GetDatabase()->GetStats(selection, stats2, error)) { - stats.song_count = stats2.song_count; - stats.song_duration = stats2.total_duration; - stats.artist_count = stats2.artist_count; - stats.album_count = stats2.album_count; + stats = stats2; } else { LogError(error); - stats.song_count = 0; - stats.song_duration = 0; - stats.artist_count = 0; - stats.album_count = 0; + stats.Clear(); } } -void -stats_print(Client &client) +static void +db_stats_print(Client &client) { + assert(GetDatabase() != nullptr); + + if (!db_is_simple()) + /* reload statistics if we're using the "proxy" + database plugin */ + /* TODO: move this into the "proxy" database plugin as + an "idle" handler */ + stats_update(); + client_printf(client, "artists: %u\n" "albums: %u\n" - "songs: %i\n" - "uptime: %li\n" - "playtime: %li\n" - "db_playtime: %li\n", + "songs: %u\n" + "db_playtime: %lu\n", stats.artist_count, stats.album_count, stats.song_count, - (long)g_timer_elapsed(stats.timer, NULL), - (long)(client.player_control.GetTotalPlayTime() + 0.5), - stats.song_duration); + stats.total_duration); - if (db_is_simple()) + const time_t update_stamp = GetDatabase()->GetUpdateStamp(); + if (update_stamp > 0) client_printf(client, - "db_update: %li\n", - (long)db_get_mtime()); + "db_update: %lu\n", + (unsigned long)update_stamp); +} + +void +stats_print(Client &client) +{ + client_printf(client, + "uptime: %lu\n" + "playtime: %lu\n", + (unsigned long)g_timer_elapsed(uptime, NULL), + (unsigned long)(client.player_control.GetTotalPlayTime() + 0.5)); + + if (GetDatabase() != nullptr) + db_stats_print(client); } |