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>
21 #include "lhash_lcl.h"
23 # ifndef OPENSSL_NO_STDIO
24 void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp)
28 bp = BIO_new(BIO_s_file());
31 BIO_set_fp(bp, fp, BIO_NOCLOSE);
32 OPENSSL_LH_stats_bio(lh, bp);
36 void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp)
40 bp = BIO_new(BIO_s_file());
43 BIO_set_fp(bp, fp, BIO_NOCLOSE);
44 OPENSSL_LH_node_stats_bio(lh, bp);
48 void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp)
52 bp = BIO_new(BIO_s_file());
55 BIO_set_fp(bp, fp, BIO_NOCLOSE);
56 OPENSSL_LH_node_usage_stats_bio(lh, bp);
62 void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
64 OPENSSL_LHASH *lh_mut = (OPENSSL_LHASH *) lh;
67 BIO_printf(out, "num_items = %lu\n", lh->num_items);
68 BIO_printf(out, "num_nodes = %u\n", lh->num_nodes);
69 BIO_printf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes);
70 BIO_printf(out, "num_expands = %lu\n", lh->num_expands);
71 BIO_printf(out, "num_expand_reallocs = %lu\n", lh->num_expand_reallocs);
72 BIO_printf(out, "num_contracts = %lu\n", lh->num_contracts);
73 BIO_printf(out, "num_contract_reallocs = %lu\n",
74 lh->num_contract_reallocs);
75 CRYPTO_atomic_add(&lh_mut->num_hash_calls, 0, &ret,
76 lh->retrieve_stats_lock);
77 BIO_printf(out, "num_hash_calls = %d\n", ret);
78 CRYPTO_atomic_add(&lh_mut->num_comp_calls, 0, &ret,
79 lh->retrieve_stats_lock);
80 BIO_printf(out, "num_comp_calls = %d\n", ret);
81 BIO_printf(out, "num_insert = %lu\n", lh->num_insert);
82 BIO_printf(out, "num_replace = %lu\n", lh->num_replace);
83 BIO_printf(out, "num_delete = %lu\n", lh->num_delete);
84 BIO_printf(out, "num_no_delete = %lu\n", lh->num_no_delete);
85 CRYPTO_atomic_add(&lh_mut->num_retrieve, 0, &ret, lh->retrieve_stats_lock);
86 BIO_printf(out, "num_retrieve = %d\n", ret);
87 CRYPTO_atomic_add(&lh_mut->num_retrieve_miss, 0, &ret,
88 lh->retrieve_stats_lock);
89 BIO_printf(out, "num_retrieve_miss = %d\n", ret);
90 CRYPTO_atomic_add(&lh_mut->num_hash_comps, 0, &ret,
91 lh->retrieve_stats_lock);
92 BIO_printf(out, "num_hash_comps = %d\n", ret);
95 void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
100 for (i = 0; i < lh->num_nodes; i++) {
101 for (n = lh->b[i], num = 0; n != NULL; n = n->next)
103 BIO_printf(out, "node %6u -> %3u\n", i, num);
107 void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
112 unsigned long total = 0, n_used = 0;
114 for (i = 0; i < lh->num_nodes; i++) {
115 for (n = lh->b[i], num = 0; n != NULL; n = n->next)
122 BIO_printf(out, "%lu nodes used out of %u\n", n_used, lh->num_nodes);
123 BIO_printf(out, "%lu items\n", total);
126 BIO_printf(out, "load %d.%02d actual load %d.%02d\n",
127 (int)(total / lh->num_nodes),
128 (int)((total % lh->num_nodes) * 100 / lh->num_nodes),
129 (int)(total / n_used), (int)((total % n_used) * 100 / n_used));