2016-05-18 02:52:22 +08:00
|
|
|
/*
|
2022-05-03 18:52:38 +08:00
|
|
|
* Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2018-12-06 20:44:07 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:52:22 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
2022-03-22 19:52:27 +08:00
|
|
|
#define OPENSSL_SUPPRESS_DEPRECATED
|
|
|
|
|
1998-12-21 18:52:47 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
1998-12-21 18:56:39 +08:00
|
|
|
/*
|
2015-10-28 03:11:48 +08:00
|
|
|
* If you wish to build this outside of OpenSSL, remove the following lines
|
1998-12-21 18:52:47 +08:00
|
|
|
* and things should work as expected
|
|
|
|
*/
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-27 23:06:22 +08:00
|
|
|
#include <openssl/bio.h>
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/lhash.h>
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "lhash_local.h"
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-15 04:57:28 +08:00
|
|
|
# ifndef OPENSSL_NO_STDIO
|
2023-10-02 21:38:12 +08:00
|
|
|
# ifndef OPENSSL_NO_DEPRECATED_3_1
|
2016-05-20 22:46:29 +08:00
|
|
|
void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
|
|
|
BIO *bp;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
1998-12-21 18:52:47 +08:00
|
|
|
bp = BIO_new(BIO_s_file());
|
|
|
|
if (bp == NULL)
|
2016-05-20 22:46:29 +08:00
|
|
|
return;
|
1998-12-21 18:52:47 +08:00
|
|
|
BIO_set_fp(bp, fp, BIO_NOCLOSE);
|
2016-05-20 22:46:29 +08:00
|
|
|
OPENSSL_LH_stats_bio(lh, bp);
|
1998-12-21 18:52:47 +08:00
|
|
|
BIO_free(bp);
|
|
|
|
}
|
|
|
|
|
2016-05-20 22:46:29 +08:00
|
|
|
void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
|
|
|
BIO *bp;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
1998-12-21 18:52:47 +08:00
|
|
|
bp = BIO_new(BIO_s_file());
|
|
|
|
if (bp == NULL)
|
2016-05-20 22:46:29 +08:00
|
|
|
return;
|
1998-12-21 18:52:47 +08:00
|
|
|
BIO_set_fp(bp, fp, BIO_NOCLOSE);
|
2016-05-20 22:46:29 +08:00
|
|
|
OPENSSL_LH_node_stats_bio(lh, bp);
|
1998-12-21 18:52:47 +08:00
|
|
|
BIO_free(bp);
|
|
|
|
}
|
|
|
|
|
2016-05-20 22:46:29 +08:00
|
|
|
void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
|
|
|
BIO *bp;
|
|
|
|
|
|
|
|
bp = BIO_new(BIO_s_file());
|
|
|
|
if (bp == NULL)
|
2016-05-20 22:46:29 +08:00
|
|
|
return;
|
1998-12-21 18:52:47 +08:00
|
|
|
BIO_set_fp(bp, fp, BIO_NOCLOSE);
|
2016-05-20 22:46:29 +08:00
|
|
|
OPENSSL_LH_node_usage_stats_bio(lh, bp);
|
1998-12-21 18:52:47 +08:00
|
|
|
BIO_free(bp);
|
|
|
|
}
|
2022-03-22 19:52:27 +08:00
|
|
|
# endif
|
1998-12-21 18:52:47 +08:00
|
|
|
# endif
|
|
|
|
|
2023-10-02 21:38:12 +08:00
|
|
|
# ifndef OPENSSL_NO_DEPRECATED_3_1
|
2022-03-22 19:52:27 +08:00
|
|
|
/*
|
|
|
|
* These functions are implemented as separate static functions as they are
|
|
|
|
* called from the stdio functions above and calling deprecated functions will
|
|
|
|
* generate a warning.
|
|
|
|
*/
|
2016-05-20 22:46:29 +08:00
|
|
|
void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
2002-11-13 23:43:43 +08:00
|
|
|
BIO_printf(out, "num_items = %lu\n", lh->num_items);
|
2017-09-28 08:09:18 +08:00
|
|
|
BIO_printf(out, "num_nodes = %u\n", lh->num_nodes);
|
|
|
|
BIO_printf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes);
|
2022-03-22 18:59:36 +08:00
|
|
|
BIO_printf(out, "num_expands = 0\n");
|
|
|
|
BIO_printf(out, "num_expand_reallocs = 0\n");
|
|
|
|
BIO_printf(out, "num_contracts = 0\n");
|
|
|
|
BIO_printf(out, "num_contract_reallocs = 0\n");
|
|
|
|
BIO_printf(out, "num_hash_calls = 0\n");
|
|
|
|
BIO_printf(out, "num_comp_calls = 0\n");
|
|
|
|
BIO_printf(out, "num_insert = 0\n");
|
|
|
|
BIO_printf(out, "num_replace = 0\n");
|
|
|
|
BIO_printf(out, "num_delete = 0\n");
|
|
|
|
BIO_printf(out, "num_no_delete = 0\n");
|
|
|
|
BIO_printf(out, "num_retrieve = 0\n");
|
|
|
|
BIO_printf(out, "num_retrieve_miss = 0\n");
|
|
|
|
BIO_printf(out, "num_hash_comps = 0\n");
|
1998-12-21 18:52:47 +08:00
|
|
|
}
|
|
|
|
|
2016-05-20 22:46:29 +08:00
|
|
|
void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
2016-05-20 22:46:29 +08:00
|
|
|
OPENSSL_LH_NODE *n;
|
1998-12-21 18:52:47 +08:00
|
|
|
unsigned int i, num;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
1998-12-21 18:52:47 +08:00
|
|
|
for (i = 0; i < lh->num_nodes; i++) {
|
|
|
|
for (n = lh->b[i], num = 0; n != NULL; n = n->next)
|
|
|
|
num++;
|
2002-11-13 23:43:43 +08:00
|
|
|
BIO_printf(out, "node %6u -> %3u\n", i, num);
|
1998-12-21 18:52:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 22:46:29 +08:00
|
|
|
void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
|
1998-12-21 18:52:47 +08:00
|
|
|
{
|
2016-05-20 22:46:29 +08:00
|
|
|
OPENSSL_LH_NODE *n;
|
1998-12-21 18:52:47 +08:00
|
|
|
unsigned long num;
|
|
|
|
unsigned int i;
|
|
|
|
unsigned long total = 0, n_used = 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
1998-12-21 18:52:47 +08:00
|
|
|
for (i = 0; i < lh->num_nodes; i++) {
|
|
|
|
for (n = lh->b[i], num = 0; n != NULL; n = n->next)
|
|
|
|
num++;
|
|
|
|
if (num != 0) {
|
|
|
|
n_used++;
|
|
|
|
total += num;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
}
|
2002-11-13 23:43:43 +08:00
|
|
|
BIO_printf(out, "%lu nodes used out of %u\n", n_used, lh->num_nodes);
|
|
|
|
BIO_printf(out, "%lu items\n", total);
|
1998-12-21 18:52:47 +08:00
|
|
|
if (n_used == 0)
|
|
|
|
return;
|
2002-11-13 23:43:43 +08:00
|
|
|
BIO_printf(out, "load %d.%02d actual load %d.%02d\n",
|
|
|
|
(int)(total / lh->num_nodes),
|
|
|
|
(int)((total % lh->num_nodes) * 100 / lh->num_nodes),
|
|
|
|
(int)(total / n_used), (int)((total % n_used) * 100 / n_used));
|
1998-12-21 18:52:47 +08:00
|
|
|
}
|
2022-03-22 19:52:27 +08:00
|
|
|
# endif
|