summaryrefslogtreecommitdiff
path: root/src/stats.c
blob: 5dc256101c1f752003398fe4dddd4be5253251c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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);