summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile2
-rw-r--r--src/blob.c2
-rw-r--r--src/stats.c65
3 files changed, 67 insertions, 2 deletions
diff --git a/src/Makefile b/src/Makefile
index b0b9537..250d2f0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -24,7 +24,7 @@ endif
progs-y += apk
apk-objs := apk.o add.o del.o fix.o update.o info.o \
search.o upgrade.o cache.o ver.o index.o fetch.o \
- audit.o verify.o dot.o policy.o
+ audit.o verify.o dot.o policy.o stats.o
libapk.so-objs := common.o database.o package.o archive.o \
version.o io.o url.o gunzip.o blob.o hash.o print.o \
diff --git a/src/blob.c b/src/blob.c
index 46e5732..07ea6f3 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -651,7 +651,7 @@ static apk_blob_t atom_hash_get_key(apk_hash_item item)
return ((struct apk_blob_atom *) item)->blob;
}
-static struct apk_hash atom_hash;
+struct apk_hash atom_hash;
static struct apk_hash_ops atom_ops = {
.node_offset = offsetof(struct apk_blob_atom, hash_node),
.get_key = atom_hash_get_key,
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);
+
+