cryptostats.c revision 108833
1/* $FreeBSD: head/tools/tools/crypto/cryptostats.c 108833 2003-01-06 22:11:56Z sam $ */
2
3/*
4 * Little program to dump the crypto statistics block and, optionally,
5 * zero all the stats or just the timing stuff.
6 */
7#include <stdio.h>
8
9#include <sys/types.h>
10#include <sys/sysctl.h>
11#include <sys/time.h>
12#include <crypto/cryptodev.h>
13
14static void
15printt(const char* tag, struct cryptotstat *ts)
16{
17	uint64_t avg, min, max;
18
19	if (ts->count == 0)
20		return;
21	avg = (1000000000LL*ts->acc.tv_sec + ts->acc.tv_nsec) / ts->count;
22	min = 1000000000LL*ts->min.tv_sec + ts->min.tv_nsec;
23	max = 1000000000LL*ts->max.tv_sec + ts->max.tv_nsec;
24	printf("%16.16s: avg %6llu ns : min %6llu ns : max %7llu ns [%u samps]\n",
25		tag, avg, min, max, ts->count);
26}
27
28int
29main(int argc, char *argv[])
30{
31	struct cryptostats stats;
32	size_t slen;
33
34	slen = sizeof (stats);
35	if (sysctlbyname("kern.crypto_stats", &stats, &slen, NULL, NULL) < 0)
36		err(1, "kern.cryptostats");
37
38	if (argc > 1 && strcmp(argv[1], "-z") == 0) {
39		bzero(&stats.cs_invoke, sizeof (stats.cs_invoke));
40		bzero(&stats.cs_done, sizeof (stats.cs_done));
41		bzero(&stats.cs_cb, sizeof (stats.cs_cb));
42		bzero(&stats.cs_finis, sizeof (stats.cs_finis));
43		stats.cs_invoke.min.tv_sec = 10000;
44		stats.cs_done.min.tv_sec = 10000;
45		stats.cs_cb.min.tv_sec = 10000;
46		stats.cs_finis.min.tv_sec = 10000;
47		if (sysctlbyname("kern.crypto_stats", NULL, NULL, &stats, sizeof (stats)) < 0)
48			err(1, "kern.cryptostats");
49		exit(0);
50	}
51	if (argc > 1 && strcmp(argv[1], "-Z") == 0) {
52		bzero(&stats, sizeof (stats));
53		stats.cs_invoke.min.tv_sec = 10000;
54		stats.cs_done.min.tv_sec = 10000;
55		stats.cs_cb.min.tv_sec = 10000;
56		stats.cs_finis.min.tv_sec = 10000;
57		if (sysctlbyname("kern.crypto_stats", NULL, NULL, &stats, sizeof (stats)) < 0)
58			err(1, "kern.cryptostats");
59		exit(0);
60	}
61
62
63	printf("%u symmetric crypto ops (%u errors, %u times driver blocked)\n"
64		, stats.cs_ops, stats.cs_errs, stats.cs_blocks);
65	printf("%u key ops (%u errors, %u times driver blocked)\n"
66		, stats.cs_kops, stats.cs_kerrs, stats.cs_kblocks);
67	printf("%u crypto dispatch thread activations\n", stats.cs_intrs);
68	printf("%u crypto return thread activations\n", stats.cs_rets);
69	if (stats.cs_invoke.count) {
70		printf("\n");
71		printt("dispatch->invoke", &stats.cs_invoke);
72		printt("invoke->done", &stats.cs_done);
73		printt("done->cb", &stats.cs_cb);
74		printt("cb->finis", &stats.cs_finis);
75	}
76	return 0;
77}
78