diff options
author | Max Kellermann <max@duempel.org> | 2013-11-22 00:23:17 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-11-22 00:27:37 +0100 |
commit | 099a2cb586524cf49dd3a9a0107ce003fd2e27e5 (patch) | |
tree | e4ea27f82304ca5f44d50b841b4165d77e100fd3 /src | |
parent | 042fe2a9d0e34d74e26aeedc1d1fd73f784c1afe (diff) | |
download | mpd-099a2cb586524cf49dd3a9a0107ce003fd2e27e5.tar.gz mpd-099a2cb586524cf49dd3a9a0107ce003fd2e27e5.tar.xz mpd-099a2cb586524cf49dd3a9a0107ce003fd2e27e5.zip |
Stats: print db statistics only if db is available
Fixes crash on "stats" in certain configurations.
Diffstat (limited to '')
-rw-r--r-- | src/Stats.cxx | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/Stats.cxx b/src/Stats.cxx index 8e39c8dfa..d2d18d6a9 100644 --- a/src/Stats.cxx +++ b/src/Stats.cxx @@ -45,6 +45,8 @@ void stats_global_finish(void) void stats_update(void) { + assert(GetDatabase() != nullptr); + Error error; DatabaseStats stats2; @@ -59,9 +61,11 @@ void stats_update(void) } } -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 */ @@ -73,14 +77,10 @@ stats_print(Client &client) "artists: %u\n" "albums: %u\n" "songs: %u\n" - "uptime: %lu\n" - "playtime: %lu\n" "db_playtime: %lu\n", stats.artist_count, stats.album_count, stats.song_count, - (unsigned long)g_timer_elapsed(uptime, NULL), - (unsigned long)(client.player_control.GetTotalPlayTime() + 0.5), stats.total_duration); if (db_is_simple()) @@ -88,3 +88,16 @@ stats_print(Client &client) "db_update: %lu\n", (unsigned long)db_get_mtime()); } + +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); +} |