2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
14 * If you wish to build this outside of OpenSSL, remove the following lines
15 * and things should work as expected
17 #include "internal/cryptlib.h"
19 #include <openssl/bio.h>
20 #include <openssl/lhash.h>
22 # ifndef OPENSSL_NO_STDIO
23 void lh_stats(const _LHASH *lh, FILE *fp)
27 bp = BIO_new(BIO_s_file());
30 BIO_set_fp(bp, fp, BIO_NOCLOSE);
36 void lh_node_stats(const _LHASH *lh, FILE *fp)
40 bp = BIO_new(BIO_s_file());
43 BIO_set_fp(bp, fp, BIO_NOCLOSE);
44 lh_node_stats_bio(lh, bp);
49 void lh_node_usage_stats(const _LHASH *lh, FILE *fp)
53 bp = BIO_new(BIO_s_file());
56 BIO_set_fp(bp, fp, BIO_NOCLOSE);
57 lh_node_usage_stats_bio(lh, bp);
64 void lh_stats_bio(const _LHASH *lh, BIO *out)
66 BIO_printf(out, "num_items = %lu\n", lh->num_items);
67 BIO_printf(out, "num_nodes = %u\n", lh->num_nodes);
68 BIO_printf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes);
69 BIO_printf(out, "num_expands = %lu\n", lh->num_expands);
70 BIO_printf(out, "num_expand_reallocs = %lu\n", lh->num_expand_reallocs);
71 BIO_printf(out, "num_contracts = %lu\n", lh->num_contracts);
72 BIO_printf(out, "num_contract_reallocs = %lu\n",
73 lh->num_contract_reallocs);
74 BIO_printf(out, "num_hash_calls = %lu\n", lh->num_hash_calls);
75 BIO_printf(out, "num_comp_calls = %lu\n", lh->num_comp_calls);
76 BIO_printf(out, "num_insert = %lu\n", lh->num_insert);
77 BIO_printf(out, "num_replace = %lu\n", lh->num_replace);
78 BIO_printf(out, "num_delete = %lu\n", lh->num_delete);
79 BIO_printf(out, "num_no_delete = %lu\n", lh->num_no_delete);
80 BIO_printf(out, "num_retrieve = %lu\n", lh->num_retrieve);
81 BIO_printf(out, "num_retrieve_miss = %lu\n", lh->num_retrieve_miss);
82 BIO_printf(out, "num_hash_comps = %lu\n", lh->num_hash_comps);
85 void lh_node_stats_bio(const _LHASH *lh, BIO *out)
90 for (i = 0; i < lh->num_nodes; i++) {
91 for (n = lh->b[i], num = 0; n != NULL; n = n->next)
93 BIO_printf(out, "node %6u -> %3u\n", i, num);
97 void lh_node_usage_stats_bio(const _LHASH *lh, BIO *out)
102 unsigned long total = 0, n_used = 0;
104 for (i = 0; i < lh->num_nodes; i++) {
105 for (n = lh->b[i], num = 0; n != NULL; n = n->next)
112 BIO_printf(out, "%lu nodes used out of %u\n", n_used, lh->num_nodes);
113 BIO_printf(out, "%lu items\n", total);
116 BIO_printf(out, "load %d.%02d actual load %d.%02d\n",
117 (int)(total / lh->num_nodes),
118 (int)((total % lh->num_nodes) * 100 / lh->num_nodes),
119 (int)(total / n_used), (int)((total % n_used) * 100 / n_used));