]>
Commit | Line | Data |
---|---|---|
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 | ||
10 | #include <stdio.h> | |
11 | #include <string.h> | |
12 | #include <stdlib.h> | |
0f113f3e | 13 | /* |
b0700d2c | 14 | * If you wish to build this outside of OpenSSL, remove the following lines |
0f113f3e MC |
15 | * and things should work as expected |
16 | */ | |
b39fc560 | 17 | #include "internal/cryptlib.h" |
d02b48c6 | 18 | |
a00ae6c4 | 19 | #include <openssl/bio.h> |
ec577822 | 20 | #include <openssl/lhash.h> |
706457b7 | 21 | #include "lhash_local.h" |
d02b48c6 | 22 | |
0f113f3e | 23 | # ifndef OPENSSL_NO_STDIO |
739a1eb1 | 24 | void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp) |
0f113f3e MC |
25 | { |
26 | BIO *bp; | |
27 | ||
28 | bp = BIO_new(BIO_s_file()); | |
29 | if (bp == NULL) | |
739a1eb1 | 30 | return; |
0f113f3e | 31 | BIO_set_fp(bp, fp, BIO_NOCLOSE); |
739a1eb1 | 32 | OPENSSL_LH_stats_bio(lh, bp); |
0f113f3e | 33 | BIO_free(bp); |
0f113f3e | 34 | } |
d02b48c6 | 35 | |
739a1eb1 | 36 | void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp) |
0f113f3e MC |
37 | { |
38 | BIO *bp; | |
39 | ||
40 | bp = BIO_new(BIO_s_file()); | |
41 | if (bp == NULL) | |
739a1eb1 | 42 | return; |
0f113f3e | 43 | BIO_set_fp(bp, fp, BIO_NOCLOSE); |
739a1eb1 | 44 | OPENSSL_LH_node_stats_bio(lh, bp); |
0f113f3e | 45 | BIO_free(bp); |
0f113f3e | 46 | } |
d02b48c6 | 47 | |
739a1eb1 | 48 | void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp) |
0f113f3e MC |
49 | { |
50 | BIO *bp; | |
d02b48c6 | 51 | |
0f113f3e MC |
52 | bp = BIO_new(BIO_s_file()); |
53 | if (bp == NULL) | |
739a1eb1 | 54 | return; |
0f113f3e | 55 | BIO_set_fp(bp, fp, BIO_NOCLOSE); |
739a1eb1 | 56 | OPENSSL_LH_node_usage_stats_bio(lh, bp); |
0f113f3e | 57 | BIO_free(bp); |
0f113f3e | 58 | } |
d02b48c6 | 59 | |
0f113f3e | 60 | # endif |
d02b48c6 | 61 | |
739a1eb1 | 62 | void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out) |
0f113f3e MC |
63 | { |
64 | BIO_printf(out, "num_items = %lu\n", lh->num_items); | |
2e8b5d75 P |
65 | BIO_printf(out, "num_nodes = %u\n", lh->num_nodes); |
66 | BIO_printf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes); | |
77d7b6ee HL |
67 | BIO_printf(out, "num_expands = 0\n"); |
68 | BIO_printf(out, "num_expand_reallocs = 0\n"); | |
69 | BIO_printf(out, "num_contracts = 0\n"); | |
70 | BIO_printf(out, "num_contract_reallocs = 0\n"); | |
71 | BIO_printf(out, "num_hash_calls = 0\n"); | |
72 | BIO_printf(out, "num_comp_calls = 0\n"); | |
73 | BIO_printf(out, "num_insert = 0\n"); | |
74 | BIO_printf(out, "num_replace = 0\n"); | |
75 | BIO_printf(out, "num_delete = 0\n"); | |
76 | BIO_printf(out, "num_no_delete = 0\n"); | |
77 | BIO_printf(out, "num_retrieve = 0\n"); | |
78 | BIO_printf(out, "num_retrieve_miss = 0\n"); | |
79 | BIO_printf(out, "num_hash_comps = 0\n"); | |
0f113f3e | 80 | } |
d02b48c6 | 81 | |
739a1eb1 | 82 | void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out) |
0f113f3e | 83 | { |
739a1eb1 | 84 | OPENSSL_LH_NODE *n; |
0f113f3e MC |
85 | unsigned int i, num; |
86 | ||
87 | for (i = 0; i < lh->num_nodes; i++) { | |
88 | for (n = lh->b[i], num = 0; n != NULL; n = n->next) | |
89 | num++; | |
90 | BIO_printf(out, "node %6u -> %3u\n", i, num); | |
91 | } | |
92 | } | |
d02b48c6 | 93 | |
739a1eb1 | 94 | void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out) |
0f113f3e | 95 | { |
739a1eb1 | 96 | OPENSSL_LH_NODE *n; |
0f113f3e MC |
97 | unsigned long num; |
98 | unsigned int i; | |
99 | unsigned long total = 0, n_used = 0; | |
100 | ||
101 | for (i = 0; i < lh->num_nodes; i++) { | |
102 | for (n = lh->b[i], num = 0; n != NULL; n = n->next) | |
103 | num++; | |
104 | if (num != 0) { | |
105 | n_used++; | |
106 | total += num; | |
107 | } | |
108 | } | |
109 | BIO_printf(out, "%lu nodes used out of %u\n", n_used, lh->num_nodes); | |
110 | BIO_printf(out, "%lu items\n", total); | |
111 | if (n_used == 0) | |
112 | return; | |
113 | BIO_printf(out, "load %d.%02d actual load %d.%02d\n", | |
114 | (int)(total / lh->num_nodes), | |
115 | (int)((total % lh->num_nodes) * 100 / lh->num_nodes), | |
116 | (int)(total / n_used), (int)((total % n_used) * 100 / n_used)); | |
117 | } |