155714Skris/* crypto/lhash/lh_stats.c */ 255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 355714Skris * All rights reserved. 455714Skris * 555714Skris * This package is an SSL implementation written 655714Skris * by Eric Young (eay@cryptsoft.com). 755714Skris * The implementation was written so as to conform with Netscapes SSL. 8296465Sdelphij * 955714Skris * This library is free for commercial and non-commercial use as long as 1055714Skris * the following conditions are aheared to. The following conditions 1155714Skris * apply to all code found in this distribution, be it the RC4, RSA, 1255714Skris * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1355714Skris * included with this distribution is covered by the same copyright terms 1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15296465Sdelphij * 1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in 1755714Skris * the code are not to be removed. 1855714Skris * If this package is used in a product, Eric Young should be given attribution 1955714Skris * as the author of the parts of the library used. 2055714Skris * This can be in the form of a textual message at program startup or 2155714Skris * in documentation (online or textual) provided with the package. 22296465Sdelphij * 2355714Skris * Redistribution and use in source and binary forms, with or without 2455714Skris * modification, are permitted provided that the following conditions 2555714Skris * are met: 2655714Skris * 1. Redistributions of source code must retain the copyright 2755714Skris * notice, this list of conditions and the following disclaimer. 2855714Skris * 2. Redistributions in binary form must reproduce the above copyright 2955714Skris * notice, this list of conditions and the following disclaimer in the 3055714Skris * documentation and/or other materials provided with the distribution. 3155714Skris * 3. All advertising materials mentioning features or use of this software 3255714Skris * must display the following acknowledgement: 3355714Skris * "This product includes cryptographic software written by 3455714Skris * Eric Young (eay@cryptsoft.com)" 3555714Skris * The word 'cryptographic' can be left out if the rouines from the library 3655714Skris * being used are not cryptographic related :-). 37296465Sdelphij * 4. If you include any Windows specific code (or a derivative thereof) from 3855714Skris * the apps directory (application code) you must include an acknowledgement: 3955714Skris * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40296465Sdelphij * 4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4455714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5155714Skris * SUCH DAMAGE. 52296465Sdelphij * 5355714Skris * The licence and distribution terms for any publically available version or 5455714Skris * derivative of this code cannot be changed. i.e. this code cannot simply be 5555714Skris * copied and put under another distribution licence 5655714Skris * [including the GNU Public Licence.] 5755714Skris */ 5855714Skris 5955714Skris#include <stdio.h> 6055714Skris#include <string.h> 6155714Skris#include <stdlib.h> 62296465Sdelphij/* 63296465Sdelphij * If you wish to build this outside of SSLeay, remove the following lines 64296465Sdelphij * and things should work as expected 65296465Sdelphij */ 6655714Skris#include "cryptlib.h" 6755714Skris 68109998Smarkm#ifndef OPENSSL_NO_BIO 69296465Sdelphij# include <openssl/bio.h> 7068651Skris#endif 7155714Skris#include <openssl/lhash.h> 7255714Skris 73109998Smarkm#ifdef OPENSSL_NO_BIO 7455714Skris 7555714Skrisvoid lh_stats(LHASH *lh, FILE *out) 76296465Sdelphij{ 77296465Sdelphij fprintf(out, "num_items = %lu\n", lh->num_items); 78296465Sdelphij fprintf(out, "num_nodes = %u\n", lh->num_nodes); 79296465Sdelphij fprintf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes); 80296465Sdelphij fprintf(out, "num_expands = %lu\n", lh->num_expands); 81296465Sdelphij fprintf(out, "num_expand_reallocs = %lu\n", lh->num_expand_reallocs); 82296465Sdelphij fprintf(out, "num_contracts = %lu\n", lh->num_contracts); 83296465Sdelphij fprintf(out, "num_contract_reallocs = %lu\n", lh->num_contract_reallocs); 84296465Sdelphij fprintf(out, "num_hash_calls = %lu\n", lh->num_hash_calls); 85296465Sdelphij fprintf(out, "num_comp_calls = %lu\n", lh->num_comp_calls); 86296465Sdelphij fprintf(out, "num_insert = %lu\n", lh->num_insert); 87296465Sdelphij fprintf(out, "num_replace = %lu\n", lh->num_replace); 88296465Sdelphij fprintf(out, "num_delete = %lu\n", lh->num_delete); 89296465Sdelphij fprintf(out, "num_no_delete = %lu\n", lh->num_no_delete); 90296465Sdelphij fprintf(out, "num_retrieve = %lu\n", lh->num_retrieve); 91296465Sdelphij fprintf(out, "num_retrieve_miss = %lu\n", lh->num_retrieve_miss); 92296465Sdelphij fprintf(out, "num_hash_comps = %lu\n", lh->num_hash_comps); 93296465Sdelphij# if 0 94296465Sdelphij fprintf(out, "p = %u\n", lh->p); 95296465Sdelphij fprintf(out, "pmax = %u\n", lh->pmax); 96296465Sdelphij fprintf(out, "up_load = %lu\n", lh->up_load); 97296465Sdelphij fprintf(out, "down_load = %lu\n", lh->down_load); 98296465Sdelphij# endif 99296465Sdelphij} 10055714Skris 10155714Skrisvoid lh_node_stats(LHASH *lh, FILE *out) 102296465Sdelphij{ 103296465Sdelphij LHASH_NODE *n; 104296465Sdelphij unsigned int i, num; 10555714Skris 106296465Sdelphij for (i = 0; i < lh->num_nodes; i++) { 107296465Sdelphij for (n = lh->b[i], num = 0; n != NULL; n = n->next) 108296465Sdelphij num++; 109296465Sdelphij fprintf(out, "node %6u -> %3u\n", i, num); 110296465Sdelphij } 111296465Sdelphij} 11255714Skris 11355714Skrisvoid lh_node_usage_stats(LHASH *lh, FILE *out) 114296465Sdelphij{ 115296465Sdelphij LHASH_NODE *n; 116296465Sdelphij unsigned long num; 117296465Sdelphij unsigned int i; 118296465Sdelphij unsigned long total = 0, n_used = 0; 11955714Skris 120296465Sdelphij for (i = 0; i < lh->num_nodes; i++) { 121296465Sdelphij for (n = lh->b[i], num = 0; n != NULL; n = n->next) 122296465Sdelphij num++; 123296465Sdelphij if (num != 0) { 124296465Sdelphij n_used++; 125296465Sdelphij total += num; 126296465Sdelphij } 127296465Sdelphij } 128296465Sdelphij fprintf(out, "%lu nodes used out of %u\n", n_used, lh->num_nodes); 129296465Sdelphij fprintf(out, "%lu items\n", total); 130296465Sdelphij if (n_used == 0) 131296465Sdelphij return; 132296465Sdelphij fprintf(out, "load %d.%02d actual load %d.%02d\n", 133296465Sdelphij (int)(total / lh->num_nodes), 134296465Sdelphij (int)((total % lh->num_nodes) * 100 / lh->num_nodes), 135296465Sdelphij (int)(total / n_used), (int)((total % n_used) * 100 / n_used)); 136296465Sdelphij} 13755714Skris 13855714Skris#else 13955714Skris 140296465Sdelphij# ifndef OPENSSL_NO_FP_API 141109998Smarkmvoid lh_stats(const LHASH *lh, FILE *fp) 142296465Sdelphij{ 143296465Sdelphij BIO *bp; 14455714Skris 145296465Sdelphij bp = BIO_new(BIO_s_file()); 146296465Sdelphij if (bp == NULL) 147296465Sdelphij goto end; 148296465Sdelphij BIO_set_fp(bp, fp, BIO_NOCLOSE); 149296465Sdelphij lh_stats_bio(lh, bp); 150296465Sdelphij BIO_free(bp); 151296465Sdelphij end:; 152296465Sdelphij} 15355714Skris 154109998Smarkmvoid lh_node_stats(const LHASH *lh, FILE *fp) 155296465Sdelphij{ 156296465Sdelphij BIO *bp; 15755714Skris 158296465Sdelphij bp = BIO_new(BIO_s_file()); 159296465Sdelphij if (bp == NULL) 160296465Sdelphij goto end; 161296465Sdelphij BIO_set_fp(bp, fp, BIO_NOCLOSE); 162296465Sdelphij lh_node_stats_bio(lh, bp); 163296465Sdelphij BIO_free(bp); 164296465Sdelphij end:; 165296465Sdelphij} 16655714Skris 167109998Smarkmvoid lh_node_usage_stats(const LHASH *lh, FILE *fp) 168296465Sdelphij{ 169296465Sdelphij BIO *bp; 17055714Skris 171296465Sdelphij bp = BIO_new(BIO_s_file()); 172296465Sdelphij if (bp == NULL) 173296465Sdelphij goto end; 174296465Sdelphij BIO_set_fp(bp, fp, BIO_NOCLOSE); 175296465Sdelphij lh_node_usage_stats_bio(lh, bp); 176296465Sdelphij BIO_free(bp); 177296465Sdelphij end:; 178296465Sdelphij} 17955714Skris 180296465Sdelphij# endif 18155714Skris 182109998Smarkmvoid lh_stats_bio(const LHASH *lh, BIO *out) 183296465Sdelphij{ 184296465Sdelphij BIO_printf(out, "num_items = %lu\n", lh->num_items); 185296465Sdelphij BIO_printf(out, "num_nodes = %u\n", lh->num_nodes); 186296465Sdelphij BIO_printf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes); 187296465Sdelphij BIO_printf(out, "num_expands = %lu\n", lh->num_expands); 188296465Sdelphij BIO_printf(out, "num_expand_reallocs = %lu\n", lh->num_expand_reallocs); 189296465Sdelphij BIO_printf(out, "num_contracts = %lu\n", lh->num_contracts); 190296465Sdelphij BIO_printf(out, "num_contract_reallocs = %lu\n", 191296465Sdelphij lh->num_contract_reallocs); 192296465Sdelphij BIO_printf(out, "num_hash_calls = %lu\n", lh->num_hash_calls); 193296465Sdelphij BIO_printf(out, "num_comp_calls = %lu\n", lh->num_comp_calls); 194296465Sdelphij BIO_printf(out, "num_insert = %lu\n", lh->num_insert); 195296465Sdelphij BIO_printf(out, "num_replace = %lu\n", lh->num_replace); 196296465Sdelphij BIO_printf(out, "num_delete = %lu\n", lh->num_delete); 197296465Sdelphij BIO_printf(out, "num_no_delete = %lu\n", lh->num_no_delete); 198296465Sdelphij BIO_printf(out, "num_retrieve = %lu\n", lh->num_retrieve); 199296465Sdelphij BIO_printf(out, "num_retrieve_miss = %lu\n", lh->num_retrieve_miss); 200296465Sdelphij BIO_printf(out, "num_hash_comps = %lu\n", lh->num_hash_comps); 201296465Sdelphij# if 0 202296465Sdelphij BIO_printf(out, "p = %u\n", lh->p); 203296465Sdelphij BIO_printf(out, "pmax = %u\n", lh->pmax); 204296465Sdelphij BIO_printf(out, "up_load = %lu\n", lh->up_load); 205296465Sdelphij BIO_printf(out, "down_load = %lu\n", lh->down_load); 206296465Sdelphij# endif 207296465Sdelphij} 20855714Skris 209109998Smarkmvoid lh_node_stats_bio(const LHASH *lh, BIO *out) 210296465Sdelphij{ 211296465Sdelphij LHASH_NODE *n; 212296465Sdelphij unsigned int i, num; 21355714Skris 214296465Sdelphij for (i = 0; i < lh->num_nodes; i++) { 215296465Sdelphij for (n = lh->b[i], num = 0; n != NULL; n = n->next) 216296465Sdelphij num++; 217296465Sdelphij BIO_printf(out, "node %6u -> %3u\n", i, num); 218296465Sdelphij } 219296465Sdelphij} 22055714Skris 221109998Smarkmvoid lh_node_usage_stats_bio(const LHASH *lh, BIO *out) 222296465Sdelphij{ 223296465Sdelphij LHASH_NODE *n; 224296465Sdelphij unsigned long num; 225296465Sdelphij unsigned int i; 226296465Sdelphij unsigned long total = 0, n_used = 0; 22755714Skris 228296465Sdelphij for (i = 0; i < lh->num_nodes; i++) { 229296465Sdelphij for (n = lh->b[i], num = 0; n != NULL; n = n->next) 230296465Sdelphij num++; 231296465Sdelphij if (num != 0) { 232296465Sdelphij n_used++; 233296465Sdelphij total += num; 234296465Sdelphij } 235296465Sdelphij } 236296465Sdelphij BIO_printf(out, "%lu nodes used out of %u\n", n_used, lh->num_nodes); 237296465Sdelphij BIO_printf(out, "%lu items\n", total); 238296465Sdelphij if (n_used == 0) 239296465Sdelphij return; 240296465Sdelphij BIO_printf(out, "load %d.%02d actual load %d.%02d\n", 241296465Sdelphij (int)(total / lh->num_nodes), 242296465Sdelphij (int)((total % lh->num_nodes) * 100 / lh->num_nodes), 243296465Sdelphij (int)(total / n_used), (int)((total % n_used) * 100 / n_used)); 244296465Sdelphij} 24555714Skris 24655714Skris#endif 247