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 $ */ 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 #include <stdlib.h> 10 #include <string.h> 11 12 #include <sys/types.h> 13 #include <sys/sysctl.h> 14 #include <sys/time.h> 15 #include <crypto/cryptodev.h> 16 17 static void 18 printt(const char* tag, struct cryptotstat *ts) 19 { 20 uint64_t avg, min, max; 21 22 if (ts->count == 0) 23 return; 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); 29 } 30 31 int 32 main(int argc, char *argv[]) 33 { 34 struct cryptostats stats; 35 size_t slen; 36 37 slen = sizeof (stats); 38 if (sysctlbyname("kern.crypto_stats", &stats, &slen, NULL, NULL) < 0) 39 err(1, "kern.cryptostats"); 40 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"); 52 exit(0); 53 } 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"); 62 exit(0); 63 } 64 65 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) { 73 printf("\n"); 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); 78 } 79 return 0; 80 } 81