Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Histogram
changeset 10:7a39408f9ea3
Version 0
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Mon, 11 Jul 2011 18:10:52 +0200 |
| parents | 060d63cb5d34 |
| children | 31a248920429 |
| files | Histogram.c Histogram.h |
| diffstat | 2 files changed, 147 insertions(+), 4 deletions(-) [+] |
line diff
1.1 --- a/Histogram.c Wed Jun 22 16:47:34 2011 +0200 1.2 +++ b/Histogram.c Mon Jul 11 18:10:52 2011 +0200 1.3 @@ -7,9 +7,16 @@ 1.4 */ 1.5 #include <stdio.h> 1.6 #include "Histogram.h" 1.7 +#include "../VMS.h" 1.8 #include "../vutilities.h" 1.9 #include "../vmalloc.h" 1.10 1.11 +//External variables for saving of the histogram 1.12 +//These have to be defined by to plugins in order to enable VMS to print this 1.13 +//information to the histogram file 1.14 +extern char __ProgrammName[]; //Defined in main.c 1.15 +extern char __Scheduler[]; //Defined in VPThread_PluginFns.c 1.16 +extern char __DataSet[255]; 1.17 1.18 /*This Histogram Abstract Data Type has a number of bins plus a range of 1.19 * values that the bins span, both chosen at creation. 1.20 @@ -133,7 +140,7 @@ 1.21 /*Inline because use with RDTSC in innermost code so need ultra-fast 1.22 */ 1.23 void inline 1.24 -addIntervalToHist( int32 startIntvl, int32 endIntvl, Histogram *hist ) 1.25 +addIntervalToHist( uint32 startIntvl, uint32 endIntvl, Histogram *hist ) 1.26 { 1.27 int32 value; 1.28 1.29 @@ -153,6 +160,130 @@ 1.30 } 1.31 1.32 void 1.33 +saveHistToFile(Histogram *hist) 1.34 +{ 1.35 + FILE *output; 1.36 + int32 binIdx, binStart, binEnd, centerValue, width; 1.37 + int32 maxHeight, i,n; 1.38 + float32 total, total2, binPercent, expectedValue1, expectedValue2; 1.39 + 1.40 + if(hist == NULL || hist->name == NULL) 1.41 + return; 1.42 + 1.43 + //Calculate the average 1.44 + //do all except the top bin 1.45 + maxHeight = 0; total = 0.0; expectedValue1 = 0.0; 1.46 + for( i = 0; i < hist->numBins -1; i++ ) 1.47 + { 1.48 + if( maxHeight < hist->bins[ i ] ) maxHeight = hist->bins[ i ]; 1.49 + total += hist->bins[ i ]; 1.50 + binStart = hist->startOfRange + hist->binWidth * i; 1.51 + expectedValue1 += hist->bins[ i ] * (binStart + hist->binWidth/2.0); 1.52 + } 1.53 + //copy and calc expected value minus the top bin 1.54 + expectedValue2 = expectedValue1; 1.55 + expectedValue2 /= total; 1.56 + total2 = total; 1.57 + //now do last iteration, to add the top bin 1.58 + if(maxHeight < hist->bins[ i ]) 1.59 + maxHeight = hist->bins[ i ]; 1.60 + total += hist->bins[ i ]; 1.61 + binStart = hist->startOfRange + hist->binWidth * i; 1.62 + expectedValue1 += hist->bins[ i ] * (binStart + hist->binWidth/2.0); 1.63 + 1.64 + expectedValue1 /= total; 1.65 + 1.66 + 1.67 + 1.68 + 1.69 + //If a histogram directory does not exist, do not save to file. 1.70 + //TODO change to argument 1.71 + char filename[255]; 1.72 + for(n=0;n<255;n++) 1.73 + { 1.74 + sprintf(filename, "./histograms/%s.%d.dat", hist->name,n); 1.75 + output = fopen(filename,"r"); 1.76 + if(output) 1.77 + { 1.78 + fclose(output); 1.79 + }else{ 1.80 + break; 1.81 + } 1.82 + } 1.83 + printf("Saving Hist to File: %s ...\n", filename); 1.84 + output = fopen(filename,"w+"); 1.85 + if(output == NULL){ 1.86 + printf("[!]No histogram was saved. To save histograms create folder 'histograms'.\n"); 1.87 + return; 1.88 + } 1.89 + 1.90 +/* 1.91 + * Write the header of the measurement file. 1.92 + */ 1.93 +//-------------------------- 1.94 +//Build Environment 1.95 + fprintf(output, "# >> Build Environment <<\n"); 1.96 + fprintf(output, "# Hardware Architecture: "); 1.97 +#ifdef __x86_64 1.98 + fprintf(output, "x86_64"); 1.99 +#endif __ 1.100 +#ifdef __i386 1.101 + fprintf(output, "x86"); 1.102 +#endif 1.103 + fprintf(output, "\n"); 1.104 + fprintf(output, "# GCC VERSION: %d.%d.%d\n",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__); 1.105 + fprintf(output, "# Build Date: %s %s\n", __DATE__, __TIME__); 1.106 + fprintf(output, "# Number of Cores: %d\n", NUM_CORES); 1.107 +//-------------------------- 1.108 + 1.109 +//-------------------------- 1.110 +//VMS Plugins 1.111 + fprintf(output, "#\n# >> VMS Plugins <<\n"); 1.112 + fprintf(output, "# Language : "); 1.113 +#ifdef VPTHREAD 1.114 + fprintf(output, "VPThread"); 1.115 +#endif 1.116 +#ifdef VCILK 1.117 + fprintf(output, "VCilk"); 1.118 +#endif 1.119 +#ifdef SSR 1.120 + fprintf(output, "SSR"); 1.121 +#endif 1.122 + fprintf(output, "\n"); 1.123 + fprintf(output, "# Scheduler: %s\n", __Scheduler); 1.124 + 1.125 +//-------------------------- 1.126 +//Application 1.127 + fprintf(output, "#\n# >> Application <<\n"); 1.128 + fprintf(output, "# Name: %s\n", __ProgrammName); 1.129 + fprintf(output, "# Data Set:\n%s\n",__DataSet); 1.130 + 1.131 +//-------------------------- 1.132 +//Histogram 1.133 + fprintf(output, "#\n# Histogram Name: %s\n", hist->name); 1.134 + fprintf(output, "# Expected Values\n"); 1.135 + fprintf(output, "#\tnum samples: %d | expected value: %3.2f \n", 1.136 + (int)total, expectedValue1 ); 1.137 + fprintf(output, "#\tminus top bin, num samples: %d | expected value: %3.2f \n", 1.138 + (int)total2, expectedValue2 ); 1.139 + fprintf(output, "#\n# [Interval] [Center Value] [Count] [relative Count] [Width]\n"); 1.140 + 1.141 + for( binIdx = 0; binIdx < hist->numBins; binIdx++ ) 1.142 + { 1.143 + binStart = hist->startOfRange + hist->binWidth * binIdx; 1.144 + binEnd = binStart + hist->binWidth - 1; 1.145 + centerValue = (binStart+binEnd)/2; 1.146 + width = (binEnd-binStart)+1; 1.147 + fprintf(output, "%d-%d\t%d\t%d\t%.4f\t%d\n", binStart, binEnd, centerValue, 1.148 + hist->bins[ binIdx ], 1.149 + hist->bins[ binIdx ]/total, width); 1.150 + } 1.151 + 1.152 + fclose(output); 1.153 + fflush(stdout); 1.154 +} 1.155 + 1.156 +void 1.157 printHist( Histogram *hist ) 1.158 { 1.159 int32 binIdx, i, numBars, maxHeight, barValue, binStart, binEnd; 1.160 @@ -181,8 +312,6 @@ 1.161 1.162 expectedValue1 /= total; 1.163 1.164 - barValue = maxHeight / 60; //60 spaces across page for tallest bin 1.165 - 1.166 printf( "histogram: " ); 1.167 if( hist->name != NULL ) printf( "%s\n", hist->name ); 1.168 else printf( "\n" ); 1.169 @@ -191,6 +320,14 @@ 1.170 printf( "minus top bin, num samples: %d | expected value: %3.2f \n", 1.171 (int)total2, expectedValue2 ); 1.172 1.173 + if(maxHeight < 60){ 1.174 + barValue = 1; 1.175 + printf("Single Bar Value: %i\n", barValue); 1.176 + }else{ 1.177 + barValue = maxHeight / 60; //60 spaces across page for tallest bin 1.178 + printf("Single Bar Value: %0.3f\n", (float)maxHeight /60); 1.179 + } 1.180 + 1.181 if( barValue == 0 ) { printf("error: bar val zero\n"); return; } 1.182 for( binIdx = 0; binIdx < hist->numBins; binIdx++ ) 1.183 {
2.1 --- a/Histogram.h Wed Jun 22 16:47:34 2011 +0200 2.2 +++ b/Histogram.h Mon Jul 11 18:10:52 2011 +0200 2.3 @@ -57,12 +57,15 @@ 2.4 addToHist( int32 value, Histogram *hist ); 2.5 2.6 void inline 2.7 -addIntervalToHist( int32 startIntvl, int32 endIntvl, Histogram *hist ); 2.8 +addIntervalToHist( uint32 startIntvl, uint32 endIntvl, Histogram *hist ); 2.9 2.10 void inline 2.11 subIntervalFromHist( int32 startIntvl, int32 endIntvl, Histogram *hist ); 2.12 2.13 void 2.14 +saveHistToFile(Histogram *hist); 2.15 + 2.16 +void 2.17 printHist( Histogram *hist ); 2.18 2.19 FloatHist * 2.20 @@ -74,6 +77,9 @@ 2.21 void 2.22 printFloatHist( FloatHist *hist ); 2.23 2.24 +void 2.25 +freeHistExt( Histogram *hist ); 2.26 + 2.27 2.28 DblHist * 2.29 makeDblHistogram( int numBins, float64 startOfRange, float64 binWidth );
