1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ssl/libcrypto/src/crypto/lhash/lh_stats.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,248 @@
1.4 +/* crypto/lhash/lh_stats.c */
1.5 +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
1.6 + * All rights reserved.
1.7 + *
1.8 + * This package is an SSL implementation written
1.9 + * by Eric Young (eay@cryptsoft.com).
1.10 + * The implementation was written so as to conform with Netscapes SSL.
1.11 + *
1.12 + * This library is free for commercial and non-commercial use as long as
1.13 + * the following conditions are aheared to. The following conditions
1.14 + * apply to all code found in this distribution, be it the RC4, RSA,
1.15 + * lhash, DES, etc., code; not just the SSL code. The SSL documentation
1.16 + * included with this distribution is covered by the same copyright terms
1.17 + * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1.18 + *
1.19 + * Copyright remains Eric Young's, and as such any Copyright notices in
1.20 + * the code are not to be removed.
1.21 + * If this package is used in a product, Eric Young should be given attribution
1.22 + * as the author of the parts of the library used.
1.23 + * This can be in the form of a textual message at program startup or
1.24 + * in documentation (online or textual) provided with the package.
1.25 + *
1.26 + * Redistribution and use in source and binary forms, with or without
1.27 + * modification, are permitted provided that the following conditions
1.28 + * are met:
1.29 + * 1. Redistributions of source code must retain the copyright
1.30 + * notice, this list of conditions and the following disclaimer.
1.31 + * 2. Redistributions in binary form must reproduce the above copyright
1.32 + * notice, this list of conditions and the following disclaimer in the
1.33 + * documentation and/or other materials provided with the distribution.
1.34 + * 3. All advertising materials mentioning features or use of this software
1.35 + * must display the following acknowledgement:
1.36 + * "This product includes cryptographic software written by
1.37 + * Eric Young (eay@cryptsoft.com)"
1.38 + * The word 'cryptographic' can be left out if the rouines from the library
1.39 + * being used are not cryptographic related :-).
1.40 + * 4. If you include any Windows specific code (or a derivative thereof) from
1.41 + * the apps directory (application code) you must include an acknowledgement:
1.42 + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
1.43 + *
1.44 + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
1.45 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.46 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.47 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1.48 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.49 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.50 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.51 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.52 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.53 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.54 + * SUCH DAMAGE.
1.55 + *
1.56 + * The licence and distribution terms for any publically available version or
1.57 + * derivative of this code cannot be changed. i.e. this code cannot simply be
1.58 + * copied and put under another distribution licence
1.59 + * [including the GNU Public Licence.]
1.60 + */
1.61 +
1.62 +#include <stdio.h>
1.63 +#include <string.h>
1.64 +#include <stdlib.h>
1.65 +/* If you wish to build this outside of SSLeay, remove the following lines
1.66 + * and things should work as expected */
1.67 +#include "cryptlib.h"
1.68 +
1.69 +#ifndef OPENSSL_NO_BIO
1.70 +#include <openssl/bio.h>
1.71 +#endif
1.72 +#include <openssl/lhash.h>
1.73 +
1.74 +#ifdef OPENSSL_NO_BIO
1.75 +
1.76 +EXPORT_C void lh_stats(LHASH *lh, FILE *out)
1.77 + {
1.78 + fprintf(out,"num_items = %lu\n",lh->num_items);
1.79 + fprintf(out,"num_nodes = %u\n",lh->num_nodes);
1.80 + fprintf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
1.81 + fprintf(out,"num_expands = %lu\n",lh->num_expands);
1.82 + fprintf(out,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs);
1.83 + fprintf(out,"num_contracts = %lu\n",lh->num_contracts);
1.84 + fprintf(out,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs);
1.85 + fprintf(out,"num_hash_calls = %lu\n",lh->num_hash_calls);
1.86 + fprintf(out,"num_comp_calls = %lu\n",lh->num_comp_calls);
1.87 + fprintf(out,"num_insert = %lu\n",lh->num_insert);
1.88 + fprintf(out,"num_replace = %lu\n",lh->num_replace);
1.89 + fprintf(out,"num_delete = %lu\n",lh->num_delete);
1.90 + fprintf(out,"num_no_delete = %lu\n",lh->num_no_delete);
1.91 + fprintf(out,"num_retrieve = %lu\n",lh->num_retrieve);
1.92 + fprintf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
1.93 + fprintf(out,"num_hash_comps = %lu\n",lh->num_hash_comps);
1.94 +#if 0
1.95 + fprintf(out,"p = %u\n",lh->p);
1.96 + fprintf(out,"pmax = %u\n",lh->pmax);
1.97 + fprintf(out,"up_load = %lu\n",lh->up_load);
1.98 + fprintf(out,"down_load = %lu\n",lh->down_load);
1.99 +#endif
1.100 + }
1.101 +
1.102 +EXPORT_C void lh_node_stats(LHASH *lh, FILE *out)
1.103 + {
1.104 + LHASH_NODE *n;
1.105 + unsigned int i,num;
1.106 +
1.107 + for (i=0; i<lh->num_nodes; i++)
1.108 + {
1.109 + for (n=lh->b[i],num=0; n != NULL; n=n->next)
1.110 + num++;
1.111 + fprintf(out,"node %6u -> %3u\n",i,num);
1.112 + }
1.113 + }
1.114 +
1.115 +EXPORT_C void lh_node_usage_stats(LHASH *lh, FILE *out)
1.116 + {
1.117 + LHASH_NODE *n;
1.118 + unsigned long num;
1.119 + unsigned int i;
1.120 + unsigned long total=0,n_used=0;
1.121 +
1.122 + for (i=0; i<lh->num_nodes; i++)
1.123 + {
1.124 + for (n=lh->b[i],num=0; n != NULL; n=n->next)
1.125 + num++;
1.126 + if (num != 0)
1.127 + {
1.128 + n_used++;
1.129 + total+=num;
1.130 + }
1.131 + }
1.132 + fprintf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
1.133 + fprintf(out,"%lu items\n",total);
1.134 + if (n_used == 0) return;
1.135 + fprintf(out,"load %d.%02d actual load %d.%02d\n",
1.136 + (int)(total/lh->num_nodes),
1.137 + (int)((total%lh->num_nodes)*100/lh->num_nodes),
1.138 + (int)(total/n_used),
1.139 + (int)((total%n_used)*100/n_used));
1.140 + }
1.141 +
1.142 +#else
1.143 +
1.144 +#ifndef OPENSSL_NO_FP_API
1.145 +EXPORT_C void lh_stats(const LHASH *lh, FILE *fp)
1.146 + {
1.147 + BIO *bp;
1.148 +
1.149 + bp=BIO_new(BIO_s_file());
1.150 + if (bp == NULL) goto end;
1.151 + BIO_set_fp(bp,fp,BIO_NOCLOSE);
1.152 + lh_stats_bio(lh,bp);
1.153 + BIO_free(bp);
1.154 +end:;
1.155 + }
1.156 +
1.157 +EXPORT_C void lh_node_stats(const LHASH *lh, FILE *fp)
1.158 + {
1.159 + BIO *bp;
1.160 +
1.161 + bp=BIO_new(BIO_s_file());
1.162 + if (bp == NULL) goto end;
1.163 + BIO_set_fp(bp,fp,BIO_NOCLOSE);
1.164 + lh_node_stats_bio(lh,bp);
1.165 + BIO_free(bp);
1.166 +end:;
1.167 + }
1.168 +
1.169 +EXPORT_C void lh_node_usage_stats(const LHASH *lh, FILE *fp)
1.170 + {
1.171 + BIO *bp;
1.172 +
1.173 + bp=BIO_new(BIO_s_file());
1.174 + if (bp == NULL) goto end;
1.175 + BIO_set_fp(bp,fp,BIO_NOCLOSE);
1.176 + lh_node_usage_stats_bio(lh,bp);
1.177 + BIO_free(bp);
1.178 +end:;
1.179 + }
1.180 +
1.181 +#endif
1.182 +
1.183 +EXPORT_C void lh_stats_bio(const LHASH *lh, BIO *out)
1.184 + {
1.185 + BIO_printf(out,"num_items = %lu\n",lh->num_items);
1.186 + BIO_printf(out,"num_nodes = %u\n",lh->num_nodes);
1.187 + BIO_printf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
1.188 + BIO_printf(out,"num_expands = %lu\n",lh->num_expands);
1.189 + BIO_printf(out,"num_expand_reallocs = %lu\n",
1.190 + lh->num_expand_reallocs);
1.191 + BIO_printf(out,"num_contracts = %lu\n",lh->num_contracts);
1.192 + BIO_printf(out,"num_contract_reallocs = %lu\n",
1.193 + lh->num_contract_reallocs);
1.194 + BIO_printf(out,"num_hash_calls = %lu\n",lh->num_hash_calls);
1.195 + BIO_printf(out,"num_comp_calls = %lu\n",lh->num_comp_calls);
1.196 + BIO_printf(out,"num_insert = %lu\n",lh->num_insert);
1.197 + BIO_printf(out,"num_replace = %lu\n",lh->num_replace);
1.198 + BIO_printf(out,"num_delete = %lu\n",lh->num_delete);
1.199 + BIO_printf(out,"num_no_delete = %lu\n",lh->num_no_delete);
1.200 + BIO_printf(out,"num_retrieve = %lu\n",lh->num_retrieve);
1.201 + BIO_printf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
1.202 + BIO_printf(out,"num_hash_comps = %lu\n",lh->num_hash_comps);
1.203 +#if 0
1.204 + BIO_printf(out,"p = %u\n",lh->p);
1.205 + BIO_printf(out,"pmax = %u\n",lh->pmax);
1.206 + BIO_printf(out,"up_load = %lu\n",lh->up_load);
1.207 + BIO_printf(out,"down_load = %lu\n",lh->down_load);
1.208 +#endif
1.209 + }
1.210 +
1.211 +EXPORT_C void lh_node_stats_bio(const LHASH *lh, BIO *out)
1.212 + {
1.213 + LHASH_NODE *n;
1.214 + unsigned int i,num;
1.215 +
1.216 + for (i=0; i<lh->num_nodes; i++)
1.217 + {
1.218 + for (n=lh->b[i],num=0; n != NULL; n=n->next)
1.219 + num++;
1.220 + BIO_printf(out,"node %6u -> %3u\n",i,num);
1.221 + }
1.222 + }
1.223 +
1.224 +EXPORT_C void lh_node_usage_stats_bio(const LHASH *lh, BIO *out)
1.225 + {
1.226 + LHASH_NODE *n;
1.227 + unsigned long num;
1.228 + unsigned int i;
1.229 + unsigned long total=0,n_used=0;
1.230 +
1.231 + for (i=0; i<lh->num_nodes; i++)
1.232 + {
1.233 + for (n=lh->b[i],num=0; n != NULL; n=n->next)
1.234 + num++;
1.235 + if (num != 0)
1.236 + {
1.237 + n_used++;
1.238 + total+=num;
1.239 + }
1.240 + }
1.241 + BIO_printf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
1.242 + BIO_printf(out,"%lu items\n",total);
1.243 + if (n_used == 0) return;
1.244 + BIO_printf(out,"load %d.%02d actual load %d.%02d\n",
1.245 + (int)(total/lh->num_nodes),
1.246 + (int)((total%lh->num_nodes)*100/lh->num_nodes),
1.247 + (int)(total/n_used),
1.248 + (int)((total%n_used)*100/n_used));
1.249 + }
1.250 +
1.251 +#endif