1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#ifndef _procinfometer_h
#define _procinfometer_h
#include <list>
#include "procinfo.h"
#include "deriver.h"
#ifdef __sun__
// we need the number of cpus for propper scaling of percent cpu-usage
#include <sinfo/cpuinfo.h>
#endif
class ProcinfoMeter
{
public:
struct ProcinfoInternal
{
Procinfo procinfo;
int uid;
bool ignoreListMatch;
#ifdef __linux__
DeriverWithTimer utimeDeriver;
DeriverWithTimer stimeDeriver;
#endif
bool updated; // set to true if updated or new, false if process terminated
};
private:
bool cmdlinemode;
std::list < std::string > ignoreList;
std::list < ProcinfoInternal > procinfoInternalList;
void unmarkProcinfoInternalList(); // set alle "updated" flags to false
std::list < ProcinfoInternal > ::iterator getProcinfoInternalList(int pid); // and set "updated"
#ifdef __linux__
char * cmdlineReadBuffer;
long cmdlineReadBufferSize;
bool readCmdline(std::string & cmdline, int pid);
bool readProcinfo(ProcinfoInternal & pii);
#endif
#ifdef __sun__
Cpuinfo cpuinfo;
bool readProcinfo(ProcinfoInternal & pii);
#endif
void updateProcinfoInternalList(); // different implementations for Linux, Solaris, FreeBSD available
void cleanupProcinfoInternalList(); // erase all entries that are not "updated"
public:
ProcinfoMeter(bool cmdlinemode, std::list < std::string > ignoreList);
~ProcinfoMeter();
bool getTopList(int nr, std::list < Procinfo > & returnProcinfoList); // Update and return the top nr entries of procinfoInternalList
}
;
bool operator<(const ProcinfoMeter::ProcinfoInternal& a, const ProcinfoMeter::ProcinfoInternal&b);
#endif // _procinfometer_h
|