1 /* $FreeBSD: src/tools/tools/crypto/cryptostats.c,v 1.1.2.1 2003/02/24 22:52:36 sam Exp $ */
2 /* $DragonFly: src/tools/tools/crypto/cryptostats.c,v 1.3 2008/04/26 09:19:10 swildner Exp $ */
5 * Little program to dump the crypto statistics block and, optionally,
6 * zero all the stats or just the timing stuff.
12 #include <sys/types.h>
13 #include <sys/sysctl.h>
15 #include <crypto/cryptodev.h>
18 printt(const char* tag
, struct cryptotstat
*ts
)
20 uint64_t avg
, min
, max
;
24 avg
= (1000000000LL*ts
->acc
.tv_sec
+ ts
->acc
.tv_nsec
) / ts
->count
;
25 min
= 1000000000LL*ts
->min
.tv_sec
+ ts
->min
.tv_nsec
;
26 max
= 1000000000LL*ts
->max
.tv_sec
+ ts
->max
.tv_nsec
;
27 printf("%16.16s: avg %6llu ns : min %6llu ns : max %7llu ns [%u samps]\n",
28 tag
, avg
, min
, max
, ts
->count
);
32 main(int argc
, char *argv
[])
34 struct cryptostats stats
;
37 slen
= sizeof (stats
);
38 if (sysctlbyname("kern.crypto_stats", &stats
, &slen
, NULL
, NULL
) < 0)
39 err(1, "kern.cryptostats");
41 if (argc
> 1 && strcmp(argv
[1], "-z") == 0) {
42 bzero(&stats
.cs_invoke
, sizeof (stats
.cs_invoke
));
43 bzero(&stats
.cs_done
, sizeof (stats
.cs_done
));
44 bzero(&stats
.cs_cb
, sizeof (stats
.cs_cb
));
45 bzero(&stats
.cs_finis
, sizeof (stats
.cs_finis
));
46 stats
.cs_invoke
.min
.tv_sec
= 10000;
47 stats
.cs_done
.min
.tv_sec
= 10000;
48 stats
.cs_cb
.min
.tv_sec
= 10000;
49 stats
.cs_finis
.min
.tv_sec
= 10000;
50 if (sysctlbyname("kern.crypto_stats", NULL
, NULL
, &stats
, sizeof (stats
)) < 0)
51 err(1, "kern.cryptostats");
54 if (argc
> 1 && strcmp(argv
[1], "-Z") == 0) {
55 bzero(&stats
, sizeof (stats
));
56 stats
.cs_invoke
.min
.tv_sec
= 10000;
57 stats
.cs_done
.min
.tv_sec
= 10000;
58 stats
.cs_cb
.min
.tv_sec
= 10000;
59 stats
.cs_finis
.min
.tv_sec
= 10000;
60 if (sysctlbyname("kern.crypto_stats", NULL
, NULL
, &stats
, sizeof (stats
)) < 0)
61 err(1, "kern.cryptostats");
66 printf("%u symmetric crypto ops (%u errors, %u times driver blocked)\n"
67 , stats
.cs_ops
, stats
.cs_errs
, stats
.cs_blocks
);
68 printf("%u key ops (%u errors, %u times driver blocked)\n"
69 , stats
.cs_kops
, stats
.cs_kerrs
, stats
.cs_kblocks
);
70 printf("%u crypto dispatch thread activations\n", stats
.cs_intrs
);
71 printf("%u crypto return thread activations\n", stats
.cs_rets
);
72 if (stats
.cs_invoke
.count
) {
74 printt("dispatch->invoke", &stats
.cs_invoke
);
75 printt("invoke->done", &stats
.cs_done
);
76 printt("done->cb", &stats
.cs_cb
);
77 printt("cb->finis", &stats
.cs_finis
);