#include <errno.h> #include <time.h> #ifndef NONAMESPACE #include <iostream> using namespace std; #else #include <iostream.h> #endif #include <string> #include "pidfunc.h" #include "pidhash.h" #include "timestamp.h" #define HASHPID( pid ) ( ( pid ) % PIDHASH ) PidHash::PidHash() { int i; for( i = 0; i < PIDHASH; i++ ) buckets[i] = 0; nhashed = 0; maxhashed = 0; } int PidHash::Insert( PidFunc *ppidfunc ) { int ibucket; ibucket = HASHPID( ppidfunc->GetPid() ); ppidfunc->SetNextPidFunc( buckets[ibucket] ); buckets[ibucket] = ppidfunc; nhashed++; if( nhashed > maxhashed ) { if( nhashed > MAXCONCURRENTS ) { cout << "nhashed > MAXCONCURRENTS\n"; return ENOMEM; } Save(); maxhashed = nhashed; maxhashedts = ppidfunc->GetStartTS(); } return 0; } PidFunc *PidHash::Find( int pid, bool remove ) { int ibucket; PidFunc *firstpidfunc; PidFunc *pidfunc; PidFunc *prevpidfunc; PidFunc *nextpidfunc; ibucket = HASHPID( pid ); firstpidfunc = buckets[ibucket]; pidfunc = firstpidfunc; while( pidfunc ) { if( pid == pidfunc->GetPid() ) break; prevpidfunc = pidfunc; pidfunc = pidfunc->GetNextPidFunc(); } if( remove && pidfunc ) { nextpidfunc = pidfunc->GetNextPidFunc(); if( pidfunc == firstpidfunc ) buckets[ibucket] = nextpidfunc; else prevpidfunc->SetNextPidFunc( nextpidfunc ); pidfunc->SetNextPidFunc( 0 ); nhashed--; } return pidfunc; } void PidHash::Save() { int iconcurrent; PidFunc *pconcurrent; int ibucket; for( iconcurrent = 0; iconcurrent < maxhashed; iconcurrent++ ) { pconcurrent = pconcurrents[iconcurrent]; if( !pconcurrent->DecrementRefCount() ) delete pconcurrent; } iconcurrent = 0; for( ibucket = 0; ibucket < PIDHASH; ibucket++ ) { pconcurrent = buckets[ibucket]; while( pconcurrent ) { pconcurrent->IncrementRefCount(); pconcurrents[iconcurrent] = pconcurrent; iconcurrent++; pconcurrent = pconcurrent->GetNextPidFunc(); } } } void PidHash::Flush() { int ibucket; PidFunc *ppidfunc; PidFunc *pnextpidfunc; for( ibucket = 0; ibucket < PIDHASH; ibucket++ ) { pnextpidfunc = buckets[ibucket]; while( pnextpidfunc ) { ppidfunc = pnextpidfunc; pnextpidfunc = ppidfunc->GetNextPidFunc(); if( !ppidfunc->DecrementRefCount() ) delete ppidfunc; } buckets[ibucket] = 0; } nhashed = 0; } void PidHash::PrintMaxConcurrent( FuncNames *pfuncnames ) { string tsstr; int iconcurrent; cout << "Maximum number of concurrent processes: " << maxhashed << "\n"; time2str( maxhashedts, &tsstr ); cout << " at: " << tsstr << "\n"; qsort( pconcurrents, maxhashed, sizeof( pconcurrents[0] ), tscmp ); for( iconcurrent = 0; iconcurrent < maxhashed; iconcurrent++ ) { cout << "Concurrents[" << iconcurrent << "]:\n"; pconcurrents[iconcurrent]->PrintPretty( " ", pfuncnames ); } }
# | 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. |