1 /* $FreeBSD: src/tools/tools/crypto/cryptostats.c,v 1.1.2.1 2003/02/24 22:52:36 sam Exp $ */
4 * Little program to dump the crypto statistics block and, optionally,
5 * zero all the stats or just the timing stuff.
10 #include <sys/sysctl.h>
12 #include <crypto/cryptodev.h>
15 printt(const char* tag, struct cryptotstat *ts)
17 uint64_t avg, min, max;
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);
29 main(int argc, char *argv[])
31 struct cryptostats stats;
34 slen = sizeof (stats);
35 if (sysctlbyname("kern.crypto_stats", &stats, &slen, NULL, NULL) < 0)
36 err(1, "kern.cryptostats");
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");
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");
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) {
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);