]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/lhash/lh_stats.c
Add deprecation macro for 3.1 and deprecate OPENSSL_LH_stats
[thirdparty/openssl.git] / crypto / lhash / lh_stats.c
CommitLineData
b1322259 1/*
fecb3aae 2 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
0f113f3e 3 *
8573be06 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
b1322259
RS
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
d02b48c6
RE
8 */
9
5317b6ee
HL
10#define OPENSSL_SUPPRESS_DEPRECATED
11
d02b48c6
RE
12#include <stdio.h>
13#include <string.h>
14#include <stdlib.h>
0f113f3e 15/*
b0700d2c 16 * If you wish to build this outside of OpenSSL, remove the following lines
0f113f3e
MC
17 * and things should work as expected
18 */
b39fc560 19#include "internal/cryptlib.h"
d02b48c6 20
a00ae6c4 21#include <openssl/bio.h>
ec577822 22#include <openssl/lhash.h>
706457b7 23#include "lhash_local.h"
d02b48c6 24
0f113f3e 25# ifndef OPENSSL_NO_STDIO
5317b6ee 26# ifndef OPENSSL_NO_DEPRECATED_3_1
739a1eb1 27void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp)
0f113f3e
MC
28{
29 BIO *bp;
30
31 bp = BIO_new(BIO_s_file());
32 if (bp == NULL)
739a1eb1 33 return;
0f113f3e 34 BIO_set_fp(bp, fp, BIO_NOCLOSE);
739a1eb1 35 OPENSSL_LH_stats_bio(lh, bp);
0f113f3e 36 BIO_free(bp);
0f113f3e 37}
d02b48c6 38
739a1eb1 39void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp)
0f113f3e
MC
40{
41 BIO *bp;
42
43 bp = BIO_new(BIO_s_file());
44 if (bp == NULL)
739a1eb1 45 return;
0f113f3e 46 BIO_set_fp(bp, fp, BIO_NOCLOSE);
739a1eb1 47 OPENSSL_LH_node_stats_bio(lh, bp);
0f113f3e 48 BIO_free(bp);
0f113f3e 49}
d02b48c6 50
739a1eb1 51void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp)
0f113f3e
MC
52{
53 BIO *bp;
d02b48c6 54
0f113f3e
MC
55 bp = BIO_new(BIO_s_file());
56 if (bp == NULL)
739a1eb1 57 return;
0f113f3e 58 BIO_set_fp(bp, fp, BIO_NOCLOSE);
739a1eb1 59 OPENSSL_LH_node_usage_stats_bio(lh, bp);
0f113f3e 60 BIO_free(bp);
0f113f3e 61}
5317b6ee 62# endif
0f113f3e 63# endif
d02b48c6 64
5317b6ee
HL
65# ifndef OPENSSL_NO_DEPRECATED_3_1
66/*
67 * These functions are implemented as separate static functions as they are
68 * called from the stdio functions above and calling deprecated functions will
69 * generate a warning.
70 */
739a1eb1 71void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
0f113f3e
MC
72{
73 BIO_printf(out, "num_items = %lu\n", lh->num_items);
2e8b5d75
P
74 BIO_printf(out, "num_nodes = %u\n", lh->num_nodes);
75 BIO_printf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes);
77d7b6ee
HL
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");
0f113f3e 89}
d02b48c6 90
739a1eb1 91void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
0f113f3e 92{
739a1eb1 93 OPENSSL_LH_NODE *n;
0f113f3e
MC
94 unsigned int i, num;
95
96 for (i = 0; i < lh->num_nodes; i++) {
97 for (n = lh->b[i], num = 0; n != NULL; n = n->next)
98 num++;
99 BIO_printf(out, "node %6u -> %3u\n", i, num);
100 }
101}
d02b48c6 102
739a1eb1 103void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
0f113f3e 104{
739a1eb1 105 OPENSSL_LH_NODE *n;
0f113f3e
MC
106 unsigned long num;
107 unsigned int i;
108 unsigned long total = 0, n_used = 0;
109
110 for (i = 0; i < lh->num_nodes; i++) {
111 for (n = lh->b[i], num = 0; n != NULL; n = n->next)
112 num++;
113 if (num != 0) {
114 n_used++;
115 total += num;
116 }
117 }
118 BIO_printf(out, "%lu nodes used out of %u\n", n_used, lh->num_nodes);
119 BIO_printf(out, "%lu items\n", total);
120 if (n_used == 0)
121 return;
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));
126}
5317b6ee 127# endif