Stats: print db statistics only if db is available

Fixes crash on "stats" in certain configurations.
This commit is contained in:
Max Kellermann 2013-11-22 00:23:17 +01:00
parent 042fe2a9d0
commit 099a2cb586
2 changed files with 20 additions and 6 deletions

1
NEWS
View File

@ -1,6 +1,7 @@
ver 0.18.5 (20??/??/??) ver 0.18.5 (20??/??/??)
* configuration * configuration
- fix crash when db_file is configured without music_directory - fix crash when db_file is configured without music_directory
- fix crash on "stats" without db_file/music_directory
* database * database
- proxy: auto-reload statistics - proxy: auto-reload statistics
* decoder * decoder

View File

@ -45,6 +45,8 @@ void stats_global_finish(void)
void stats_update(void) void stats_update(void)
{ {
assert(GetDatabase() != nullptr);
Error error; Error error;
DatabaseStats stats2; DatabaseStats stats2;
@ -59,9 +61,11 @@ void stats_update(void)
} }
} }
void static void
stats_print(Client &client) db_stats_print(Client &client)
{ {
assert(GetDatabase() != nullptr);
if (!db_is_simple()) if (!db_is_simple())
/* reload statistics if we're using the "proxy" /* reload statistics if we're using the "proxy"
database plugin */ database plugin */
@ -73,14 +77,10 @@ stats_print(Client &client)
"artists: %u\n" "artists: %u\n"
"albums: %u\n" "albums: %u\n"
"songs: %u\n" "songs: %u\n"
"uptime: %lu\n"
"playtime: %lu\n"
"db_playtime: %lu\n", "db_playtime: %lu\n",
stats.artist_count, stats.artist_count,
stats.album_count, stats.album_count,
stats.song_count, stats.song_count,
(unsigned long)g_timer_elapsed(uptime, NULL),
(unsigned long)(client.player_control.GetTotalPlayTime() + 0.5),
stats.total_duration); stats.total_duration);
if (db_is_simple()) if (db_is_simple())
@ -88,3 +88,16 @@ stats_print(Client &client)
"db_update: %lu\n", "db_update: %lu\n",
(unsigned long)db_get_mtime()); (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);
}