#include <time.h> #ifndef NONAMESPACE #include <iostream> using namespace std; #else #include <iostream.h> #endif #include <string> #include "p4loga.h" #include "extremes.h" #include "pidfunc.h" #define MAXTHRESHOLD 1.00e+100 void Extremes::Init( int aorder, int andesired ) { order = aorder; ndesired = andesired; nextremes = 0; threshold = MAXTHRESHOLD * order; } bool Extremes::Find( double odiffts, double difftss[], PidFunc *ppidfuncs[], int *ippidfunc ) { int ilower; int iupper; bool found; int imiddle; double osdiffts; ilower = 0; iupper = nextremes - 1; found = false; if( ilower <= iupper ) { do { imiddle = ilower + ( ( iupper - ilower ) / 2 ); osdiffts = difftss[imiddle] * order; if( odiffts > osdiffts ) iupper = imiddle - 1; else if( odiffts < osdiffts ) ilower = imiddle + 1; else found = true; } while( ilower <= iupper && !found ); if( !found && odiffts < osdiffts ) imiddle++; } else imiddle = 0; *ippidfunc = imiddle; return found; } void Extremes::Insert( PidFunc *ppidfunc, double diffts, double difftss[], PidFunc *ppidfuncs[] ) { double odiffts; bool insert; PidFunc *pbumped; int ippidfunc; int jppidfunc; int nelements; odiffts = diffts * order; if( nextremes == ndesired ) { if( insert = odiffts > ( threshold * order ) ) { nextremes--; pbumped = ppidfuncs[nextremes]; if( !pbumped->DecrementRefCount() ) delete pbumped; } } else { insert = true; } if( insert ) { Find( odiffts, difftss, ppidfuncs, &ippidfunc ); jppidfunc = ippidfunc + 1; nelements = nextremes - ippidfunc; memmove( &difftss[jppidfunc], &difftss[ippidfunc], nelements * sizeof( difftss[0] ) ); memmove( &ppidfuncs[jppidfunc], &ppidfuncs[ippidfunc], nelements * sizeof( ppidfuncs[0] ) ); ppidfunc->IncrementRefCount(); difftss[ippidfunc] = diffts; ppidfuncs[ippidfunc] = ppidfunc; threshold = difftss[nextremes]; nextremes++; } } void Extremes::Remove( PidFunc *ppidfunc, double diffts, double difftss[], PidFunc *ppidfuncs[] ) { int ippidfunc; int jppidfunc; int nelements; if( ( diffts * order ) >= ( threshold * order ) ) { for( ippidfunc = 0; ippidfunc < nextremes; ippidfunc++ ) if( ppidfunc == ppidfuncs[ippidfunc] ) break; if( ippidfunc != nextremes ) { if( !ppidfunc->DecrementRefCount() ) delete ppidfunc; jppidfunc = ippidfunc + 1; nelements = nextremes - jppidfunc; memmove( &difftss[ippidfunc], &difftss[jppidfunc], nelements * sizeof( difftss[0] ) ); memmove( &ppidfuncs[ippidfunc], &ppidfuncs[jppidfunc], nelements * sizeof( ppidfuncs[0] ) ); nextremes--; if( nextremes ) threshold = difftss[nextremes - 1]; else threshold = MAXTHRESHOLD * order; } } } void Extremes::Print( string name, FuncNames *pfuncnames, PidFunc *ppidfuncs[] ) { int ibegin; int iend; int iextreme; if( order == MAXIMUMS ) { ibegin = 0; iend = nextremes; } else { ibegin = nextremes - 1; iend = 1; } for( iextreme = ibegin; iextreme * order < iend; iextreme += order ) { cout << name << "[" << iextreme << "]:\n"; ppidfuncs[iextreme]->PrintPretty( " ", pfuncnames ); } if( nextremes ) cout << "\n"; } void AllExtremes::Insert( PidFunc *ppidfunc, double diffts ) { Extremes::Insert( ppidfunc, diffts, difftss, ppidfuncs ); } void AllExtremes::Remove( PidFunc *ppidfunc, double diffts ) { Extremes::Remove( ppidfunc, diffts, difftss, ppidfuncs ); } void AllExtremes::Print( string name, FuncNames *pfuncnames ) { Extremes::Print( name, pfuncnames, ppidfuncs ); } void FuncExtremes::Insert( PidFunc *ppidfunc, double diffts ) { Extremes::Insert( ppidfunc, diffts, difftss, ppidfuncs ); } void FuncExtremes::Remove( PidFunc *ppidfunc, double diffts ) { Extremes::Remove( ppidfunc, diffts, difftss, ppidfuncs ); } void FuncExtremes::Print( string name ) { Extremes::Print( name, 0, ppidfuncs ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 1722 | Michael Shields |
p4loga builds for freebsd4 (play), hpux11 (hell), linux24x86 (duey), and solaris26 (shucks). A bit of porting was required for the hpux11 build (aCC as configured on hell isn't quite up to speed with respect to namespaces). |
||
#1 | 1610 | Michael Shields |
Adding p4d log analyzer concocted by myself. Compiles and executes on Red Hat 6.0, 7.0, and probably a few other operating systems with perhaps a little help. Still needs comments. |