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