home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume5 / fsanalyze4.1 / part01 / stats.c < prev    next >
C/C++ Source or Header  |  1989-02-03  |  6KB  |  138 lines

  1. static char sccsid[] = "@(#)$Id: stats.c, V4.1 88/11/16 17:31:26 $";
  2.  
  3. /*
  4.  * stats.c - file system statistics
  5.  * Version  : 4.1 - 88/11/16 17:31:26
  6.  *
  7.  * Author   : Michael J. Young
  8.  * USmail   : Software Development Technologies, Inc.
  9.  *            375 Dutton Rd
  10.  *            Sudbury MA 01776
  11.  * UUCP     : harvard!sdti!mjy
  12.  * Internet : mjy@sdti.SDTI.COM
  13.  *
  14.  * =========================================================================
  15.  * Note : This program has been placed in the public domain to permit
  16.  * unrestricted distribution and use.  I have placed no copyright on it, but
  17.  * I request that you keep me informed about any enhancements and bug fixes
  18.  * you make so I can keep an up-to-date copy for further distribution.
  19.  *
  20.  * This program is being provided "as is", with no warrantee as to safety or
  21.  * accuracy of results.  Use at your own risk.
  22.  * =========================================================================
  23.  */
  24.  
  25. /*
  26.  * Modification History:
  27.  *
  28.  * Thu Jul 28 16:02:51 EDT 1988 - M. Young (mjy@sdti.SDTI.COM),
  29.  *    Extracted from fsanalyze.c
  30.  *
  31.  * Mon Aug 08 11:27:39 EDT 1988 - M. Young (mjy@sdti.SDTI.COM),
  32.  *    Revised OS_TYPE and FS_TYPE macros to avoid name-space conflicts
  33.  *
  34.  * Wed Nov 16 11:31:32 EST 1988 - M. Young (mjy@sdti.SDTI.COM),
  35.  *    Placed under SCCS
  36.  */
  37.  
  38. #include "fsconfig.h"
  39. #include "fsanalyze.h"
  40.  
  41. /*
  42.  * calculated global statistics
  43.  */
  44. long blocks              = 0;           /* running block count */
  45. long free_inodes         = 0;           /* number of unused i-nodes */
  46. long potential_seeks     = 0;           /* potential number of disk seeks
  47.                                          * during sequential access of a 
  48.                                          * file */
  49. long seeks               = 0;           /* actual number of disk seeks
  50.                                          * required during sequential access
  51.                                          * of a file */
  52. long total_seek_distance = 0;           /* actual distance of disk seeks
  53.                                          * required during sequential access
  54.                                          * of a file */
  55. long rotates             = 0;           /* number of disk rotation delays */
  56. long indirects           = 0;           /* number of files w/ more than
  57.                                          * 10 data blocks */
  58. long double_indirects    = 0;           /* number of files w/ more than
  59.                                         /* one level of indirection */
  60. long triple_indirects    = 0;           /* number of files w/ more than
  61.                                          * two levels of indirection */
  62. long ind_blks            = 0;           /* number of blocks used for
  63.                                          * indirection */
  64. int big_directories      = 0;           /* number of directories with
  65.                                          * indirection */
  66. int num_directories      = 0;           /* number of directories */
  67. int num_specials         = 0;           /* number of special files */
  68. int linked_files         = 0;           /* number of multiply-linked files */
  69. int sparse_files         = 0;           /* number of sparse files */
  70. int size_errors          = 0;           /* number of file size discrepancies */
  71. long unuseable           = 0;           /* unuseable bytes due to external
  72.                                          * fragmentation */
  73.  
  74. struct file_data file_log[NUMOFFEND] = {0};    /* worst offenders */
  75.  
  76. /*
  77.  * init_stats : initializes per-file statistics structure
  78.  */
  79. void init_stats (data, inode, file_size)
  80. struct file_data *data;                           /* file stats to init */
  81. int inode;                                        /* i-node number */
  82. long file_size;                                   /* file size */
  83. {
  84.     data->inode = inode;
  85.     data->total_blocks = data->data_blocks = 0;
  86.     data->potential_seeks = data->seeks = data->rotates = 0;
  87.     data->fragm = 0.0;
  88.     data->sparse = 0;
  89.     data->cost = 0;
  90.     data->min_cost = minimum_seeks (file_size);
  91.     data->rel_cost = 0.0;
  92.     data->wasted = 0;
  93.     }
  94.  
  95. /*
  96.  * log_stats : updates global statistics based on the current file statistics.
  97.  * The current file is then checked to see if it qualifies as one of the
  98.  * worst offenders (i.e., most fragmented) encountered thus far.  The worst
  99.  * offenders are determined based on their absolute number of disk seeks
  100.  * required to read the entire file.  Such an absolute test (viz a viz a
  101.  * relative percentage test) ensures that very small, but fragmented, files
  102.  * will not clutter the output.
  103.  */
  104. void log_stats (data)
  105. struct file_data *data;                /* file statistics to be
  106.                                         * logged */
  107. {
  108.     int i, j;                          /* loop counters */
  109.  
  110.  
  111.     /*
  112.      * update global statistics
  113.      */
  114.     blocks += data->total_blocks;
  115.     ind_blks += data->total_blocks - data->data_blocks;
  116.     potential_seeks += data->potential_seeks;
  117.     seeks += data->seeks;
  118.     total_seek_distance += data->cost;
  119.     rotates += data->rotates;
  120.     data->fragm = data->potential_seeks ? (float)data->seeks/(float)data->potential_seeks : 0.0;
  121.     data->rel_cost = (data->seeks ? (float)data->cost/(float)data->seeks : 0.0);
  122.     unuseable += data->wasted;
  123.  
  124.     /*
  125.      * update worst offender array
  126.      */
  127.     for (i = 0; i < NUMOFFEND; i++){
  128.         if (data->seeks > file_log[i].seeks){
  129.             for (j = NUMOFFEND-1; j > i; j--){
  130.                 file_log[j] = file_log[j-1];
  131.                 }
  132.             file_log[i] = *data;
  133.             break;
  134.             }
  135.         }
  136.     }
  137.  
  138.