diff options
author | Timo Teräs <timo.teras@iki.fi> | 2015-06-12 11:20:01 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2015-06-12 11:20:01 +0300 |
commit | 5ecc97e7246b3802170fbbfc45eb924a78960196 (patch) | |
tree | d0194d2a4ed77c80b10ab176172b65b7d9f84228 /src/stats.c | |
parent | 3e8e2b562226fa10adb98b1c5faba4b547c4d139 (diff) | |
download | apk-tools-5ecc97e7246b3802170fbbfc45eb924a78960196.tar.gz apk-tools-5ecc97e7246b3802170fbbfc45eb924a78960196.tar.bz2 apk-tools-5ecc97e7246b3802170fbbfc45eb924a78960196.tar.xz apk-tools-5ecc97e7246b3802170fbbfc45eb924a78960196.zip |
add simple stats applet
Diffstat (limited to 'src/stats.c')
-rw-r--r-- | src/stats.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/stats.c b/src/stats.c new file mode 100644 index 0000000..5dc2561 --- /dev/null +++ b/src/stats.c @@ -0,0 +1,65 @@ +/* stats.c - Alpine Package Keeper (APK) + * + * Copyright (C) 2013 Timo Teräs <timo.teras@iki.fi> + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. See http://www.gnu.org/ for details. + */ + +#include <stdio.h> +#include "apk_defines.h" +#include "apk_applet.h" +#include "apk_database.h" + +static int list_count(struct list_head *h) +{ + struct list_head *n; + int c = 0; + + list_for_each(n, h) + c++; + + return c; +} + +static int stats_main(void *ctx, struct apk_database *db, struct apk_string_array *args) +{ + extern struct apk_hash atom_hash; + + printf( + "installed:\n" + " packages: %d\n" + " dirs: %d\n" + " files: %d\n" + " bytes: %zu\n" + " triggers: %d\n" + "available:\n" + " names: %d\n" + " packages: %d\n" + "atoms:\n" + " num: %d\n" + , + db->installed.stats.packages, + db->installed.stats.dirs, + db->installed.stats.files, + db->installed.stats.bytes, + list_count(&db->installed.triggers), + db->available.names.num_items, + db->available.packages.num_items, + atom_hash.num_items + ); + return 0; +} + +static struct apk_applet stats_applet = { + .name = "stats", + .help = "Show statistics about repositories and installations", + .open_flags = APK_OPENF_READ, + .main = stats_main, +}; + +APK_DEFINE_APPLET(stats_applet); + + |