2 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
10 #define OPENSSL_SUPPRESS_DEPRECATED
16 * If you wish to build this outside of OpenSSL, remove the following lines
17 * and things should work as expected
19 #include "internal/cryptlib.h"
21 #include <openssl/bio.h>
22 #include <openssl/lhash.h>
23 #include "lhash_local.h"
25 # ifndef OPENSSL_NO_STDIO
26 # ifndef OPENSSL_NO_DEPRECATED_3_2
27 void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp)
31 bp = BIO_new(BIO_s_file());
34 BIO_set_fp(bp, fp, BIO_NOCLOSE);
35 OPENSSL_LH_stats_bio(lh, bp);
39 void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp)
43 bp = BIO_new(BIO_s_file());
46 BIO_set_fp(bp, fp, BIO_NOCLOSE);
47 OPENSSL_LH_node_stats_bio(lh, bp);
51 void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp)
55 bp = BIO_new(BIO_s_file());
58 BIO_set_fp(bp, fp, BIO_NOCLOSE);
59 OPENSSL_LH_node_usage_stats_bio(lh, bp);
65 # ifndef OPENSSL_NO_DEPRECATED_3_2
67 * These functions are implemented as separate static functions as they are
68 * called from the stdio functions above and calling deprecated functions will
71 void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
73 BIO_printf(out, "num_items = %lu\n", lh->num_items);
74 BIO_printf(out, "num_nodes = %u\n", lh->num_nodes);
75 BIO_printf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes);
76 BIO_printf(out, "num_expands = 0\n");
77 BIO_printf(out, "num_expand_reallocs = 0\n");
78 BIO_printf(out, "num_contracts = 0\n");
79 BIO_printf(out, "num_contract_reallocs = 0\n");
80 BIO_printf(out, "num_hash_calls = 0\n");
81 BIO_printf(out, "num_comp_calls = 0\n");
82 BIO_printf(out, "num_insert = 0\n");
83 BIO_printf(out, "num_replace = 0\n");
84 BIO_printf(out, "num_delete = 0\n");
85 BIO_printf(out, "num_no_delete = 0\n");
86 BIO_printf(out, "num_retrieve = 0\n");
87 BIO_printf(out, "num_retrieve_miss = 0\n");
88 BIO_printf(out, "num_hash_comps = 0\n");
91 void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
96 for (i = 0; i < lh->num_nodes; i++) {
97 for (n = lh->b[i], num = 0; n != NULL; n = n->next)
99 BIO_printf(out, "node %6u -> %3u\n", i, num);
103 void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
108 unsigned long total = 0, n_used = 0;
110 for (i = 0; i < lh->num_nodes; i++) {
111 for (n = lh->b[i], num = 0; n != NULL; n = n->next)
118 BIO_printf(out, "%lu nodes used out of %u\n", n_used, lh->num_nodes);
119 BIO_printf(out, "%lu items\n", total);
122 BIO_printf(out, "load %d.%02d actual load %d.%02d\n",
123 (int)(total / lh->num_nodes),
124 (int)((total % lh->num_nodes) * 100 / lh->num_nodes),
125 (int)(total / n_used), (int)((total % n_used) * 100 / n_used));