# HG changeset patch # User Merten Sach # Date 1310400652 -7200 # Node ID 7a39408f9ea3868eb8ca3350a1d0d01aa571ff4a # Parent 060d63cb5d3497a8c8d006ee367f09378b28e0c3 Version 0 diff -r 060d63cb5d34 -r 7a39408f9ea3 Histogram.c --- a/Histogram.c Wed Jun 22 16:47:34 2011 +0200 +++ b/Histogram.c Mon Jul 11 18:10:52 2011 +0200 @@ -7,9 +7,16 @@ */ #include #include "Histogram.h" +#include "../VMS.h" #include "../vutilities.h" #include "../vmalloc.h" +//External variables for saving of the histogram +//These have to be defined by to plugins in order to enable VMS to print this +//information to the histogram file +extern char __ProgrammName[]; //Defined in main.c +extern char __Scheduler[]; //Defined in VPThread_PluginFns.c +extern char __DataSet[255]; /*This Histogram Abstract Data Type has a number of bins plus a range of * values that the bins span, both chosen at creation. @@ -133,7 +140,7 @@ /*Inline because use with RDTSC in innermost code so need ultra-fast */ void inline -addIntervalToHist( int32 startIntvl, int32 endIntvl, Histogram *hist ) +addIntervalToHist( uint32 startIntvl, uint32 endIntvl, Histogram *hist ) { int32 value; @@ -153,6 +160,130 @@ } void +saveHistToFile(Histogram *hist) +{ + FILE *output; + int32 binIdx, binStart, binEnd, centerValue, width; + int32 maxHeight, i,n; + float32 total, total2, binPercent, expectedValue1, expectedValue2; + + if(hist == NULL || hist->name == NULL) + return; + + //Calculate the average + //do all except the top bin + maxHeight = 0; total = 0.0; expectedValue1 = 0.0; + for( i = 0; i < hist->numBins -1; i++ ) + { + if( maxHeight < hist->bins[ i ] ) maxHeight = hist->bins[ i ]; + total += hist->bins[ i ]; + binStart = hist->startOfRange + hist->binWidth * i; + expectedValue1 += hist->bins[ i ] * (binStart + hist->binWidth/2.0); + } + //copy and calc expected value minus the top bin + expectedValue2 = expectedValue1; + expectedValue2 /= total; + total2 = total; + //now do last iteration, to add the top bin + if(maxHeight < hist->bins[ i ]) + maxHeight = hist->bins[ i ]; + total += hist->bins[ i ]; + binStart = hist->startOfRange + hist->binWidth * i; + expectedValue1 += hist->bins[ i ] * (binStart + hist->binWidth/2.0); + + expectedValue1 /= total; + + + + + //If a histogram directory does not exist, do not save to file. + //TODO change to argument + char filename[255]; + for(n=0;n<255;n++) + { + sprintf(filename, "./histograms/%s.%d.dat", hist->name,n); + output = fopen(filename,"r"); + if(output) + { + fclose(output); + }else{ + break; + } + } + printf("Saving Hist to File: %s ...\n", filename); + output = fopen(filename,"w+"); + if(output == NULL){ + printf("[!]No histogram was saved. To save histograms create folder 'histograms'.\n"); + return; + } + +/* + * Write the header of the measurement file. + */ +//-------------------------- +//Build Environment + fprintf(output, "# >> Build Environment <<\n"); + fprintf(output, "# Hardware Architecture: "); +#ifdef __x86_64 + fprintf(output, "x86_64"); +#endif __ +#ifdef __i386 + fprintf(output, "x86"); +#endif + fprintf(output, "\n"); + fprintf(output, "# GCC VERSION: %d.%d.%d\n",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__); + fprintf(output, "# Build Date: %s %s\n", __DATE__, __TIME__); + fprintf(output, "# Number of Cores: %d\n", NUM_CORES); +//-------------------------- + +//-------------------------- +//VMS Plugins + fprintf(output, "#\n# >> VMS Plugins <<\n"); + fprintf(output, "# Language : "); +#ifdef VPTHREAD + fprintf(output, "VPThread"); +#endif +#ifdef VCILK + fprintf(output, "VCilk"); +#endif +#ifdef SSR + fprintf(output, "SSR"); +#endif + fprintf(output, "\n"); + fprintf(output, "# Scheduler: %s\n", __Scheduler); + +//-------------------------- +//Application + fprintf(output, "#\n# >> Application <<\n"); + fprintf(output, "# Name: %s\n", __ProgrammName); + fprintf(output, "# Data Set:\n%s\n",__DataSet); + +//-------------------------- +//Histogram + fprintf(output, "#\n# Histogram Name: %s\n", hist->name); + fprintf(output, "# Expected Values\n"); + fprintf(output, "#\tnum samples: %d | expected value: %3.2f \n", + (int)total, expectedValue1 ); + fprintf(output, "#\tminus top bin, num samples: %d | expected value: %3.2f \n", + (int)total2, expectedValue2 ); + fprintf(output, "#\n# [Interval] [Center Value] [Count] [relative Count] [Width]\n"); + + for( binIdx = 0; binIdx < hist->numBins; binIdx++ ) + { + binStart = hist->startOfRange + hist->binWidth * binIdx; + binEnd = binStart + hist->binWidth - 1; + centerValue = (binStart+binEnd)/2; + width = (binEnd-binStart)+1; + fprintf(output, "%d-%d\t%d\t%d\t%.4f\t%d\n", binStart, binEnd, centerValue, + hist->bins[ binIdx ], + hist->bins[ binIdx ]/total, width); + } + + fclose(output); + fflush(stdout); +} + +void printHist( Histogram *hist ) { int32 binIdx, i, numBars, maxHeight, barValue, binStart, binEnd; @@ -181,8 +312,6 @@ expectedValue1 /= total; - barValue = maxHeight / 60; //60 spaces across page for tallest bin - printf( "histogram: " ); if( hist->name != NULL ) printf( "%s\n", hist->name ); else printf( "\n" ); @@ -191,6 +320,14 @@ printf( "minus top bin, num samples: %d | expected value: %3.2f \n", (int)total2, expectedValue2 ); + if(maxHeight < 60){ + barValue = 1; + printf("Single Bar Value: %i\n", barValue); + }else{ + barValue = maxHeight / 60; //60 spaces across page for tallest bin + printf("Single Bar Value: %0.3f\n", (float)maxHeight /60); + } + if( barValue == 0 ) { printf("error: bar val zero\n"); return; } for( binIdx = 0; binIdx < hist->numBins; binIdx++ ) { diff -r 060d63cb5d34 -r 7a39408f9ea3 Histogram.h --- a/Histogram.h Wed Jun 22 16:47:34 2011 +0200 +++ b/Histogram.h Mon Jul 11 18:10:52 2011 +0200 @@ -57,12 +57,15 @@ addToHist( int32 value, Histogram *hist ); void inline -addIntervalToHist( int32 startIntvl, int32 endIntvl, Histogram *hist ); +addIntervalToHist( uint32 startIntvl, uint32 endIntvl, Histogram *hist ); void inline subIntervalFromHist( int32 startIntvl, int32 endIntvl, Histogram *hist ); void +saveHistToFile(Histogram *hist); + +void printHist( Histogram *hist ); FloatHist * @@ -74,6 +77,9 @@ void printFloatHist( FloatHist *hist ); +void +freeHistExt( Histogram *hist ); + DblHist * makeDblHistogram( int numBins, float64 startOfRange, float64 binWidth );