From 099a2cb586524cf49dd3a9a0107ce003fd2e27e5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 22 Nov 2013 00:23:17 +0100 Subject: Stats: print db statistics only if db is available Fixes crash on "stats" in certain configurations. --- src/Stats.cxx | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/Stats.cxx') 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); +} -- cgit v1.2.3