2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2013-01-03 10:33:04 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2004-02-24 00:41:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-02-24 00:41:20 +01:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-10-02 12:14:07 +02:00
|
|
|
#include "Stats.hxx"
|
2013-01-04 22:31:53 +01:00
|
|
|
#include "PlayerControl.hxx"
|
2013-10-19 19:35:37 +02:00
|
|
|
#include "Client.hxx"
|
2012-08-07 23:06:41 +02:00
|
|
|
#include "DatabaseSelection.hxx"
|
2012-08-02 18:55:53 +02:00
|
|
|
#include "DatabaseGlue.hxx"
|
|
|
|
#include "DatabasePlugin.hxx"
|
2013-01-03 00:25:15 +01:00
|
|
|
#include "DatabaseSimple.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
#include "util/Error.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
#include "Log.hxx"
|
2012-08-02 18:55:53 +02:00
|
|
|
|
2013-10-02 12:16:52 +02:00
|
|
|
#include <glib.h>
|
|
|
|
|
2013-11-22 00:10:53 +01:00
|
|
|
static GTimer *uptime;
|
2013-11-22 00:12:12 +01:00
|
|
|
static DatabaseStats stats;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2009-01-18 15:22:26 +01:00
|
|
|
void stats_global_init(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2013-11-22 00:10:53 +01:00
|
|
|
uptime = g_timer_new();
|
2009-01-18 15:40:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void stats_global_finish(void)
|
|
|
|
{
|
2013-11-22 00:10:53 +01:00
|
|
|
g_timer_destroy(uptime);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2009-01-18 15:40:28 +01:00
|
|
|
void stats_update(void)
|
|
|
|
{
|
2013-11-22 00:23:17 +01:00
|
|
|
assert(GetDatabase() != nullptr);
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
2009-01-18 15:40:50 +01:00
|
|
|
|
2012-08-15 22:20:28 +02:00
|
|
|
DatabaseStats stats2;
|
2009-01-18 15:40:50 +01:00
|
|
|
|
2012-08-15 22:20:28 +02:00
|
|
|
const DatabaseSelection selection("", true);
|
2013-08-10 18:02:44 +02:00
|
|
|
if (GetDatabase()->GetStats(selection, stats2, error)) {
|
2013-11-22 00:12:12 +01:00
|
|
|
stats = stats2;
|
2012-08-15 22:20:28 +02:00
|
|
|
} else {
|
2013-09-27 22:31:24 +02:00
|
|
|
LogError(error);
|
2012-08-15 22:20:28 +02:00
|
|
|
|
2013-11-22 00:12:12 +01:00
|
|
|
stats.Clear();
|
2012-08-15 22:20:28 +02:00
|
|
|
}
|
2009-01-18 15:40:28 +01:00
|
|
|
}
|
|
|
|
|
2013-11-22 00:23:17 +01:00
|
|
|
static void
|
|
|
|
db_stats_print(Client &client)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2013-11-22 00:23:17 +01:00
|
|
|
assert(GetDatabase() != nullptr);
|
|
|
|
|
2013-11-21 23:30:49 +01:00
|
|
|
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();
|
|
|
|
|
2008-09-07 14:02:57 +02:00
|
|
|
client_printf(client,
|
2008-09-08 11:47:57 +02:00
|
|
|
"artists: %u\n"
|
|
|
|
"albums: %u\n"
|
2013-11-22 00:23:27 +01:00
|
|
|
"songs: %u\n"
|
|
|
|
"db_playtime: %lu\n",
|
2009-01-18 15:40:28 +01:00
|
|
|
stats.artist_count,
|
|
|
|
stats.album_count,
|
2009-01-18 15:22:26 +01:00
|
|
|
stats.song_count,
|
2013-11-22 00:12:12 +01:00
|
|
|
stats.total_duration);
|
2012-08-08 08:19:30 +02:00
|
|
|
|
|
|
|
if (db_is_simple())
|
|
|
|
client_printf(client,
|
2013-11-21 23:34:32 +01:00
|
|
|
"db_update: %lu\n",
|
|
|
|
(unsigned long)db_get_mtime());
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2013-11-22 00:23:17 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|