1 // 2 // Initial port performed by Stefan Eilemann (eilemann@gmail.com) 3 // 4 #ifndef _CPUMETER_H_ 5 #define _CPUMETER_H_ 6 7 #include "fieldmetergraph.h" 8 9 #include <sys/types.h> 10 #include <sys/sysmp.h> 11 #include <sys/sysinfo.h> 12 13 #define USED_CPU_STATES (CPU_STATES-1) // SXBRK + IDLE merged 14 15 class CPUMeter : public FieldMeterGraph { 16 public: 17 CPUMeter(XOSView *parent, const int cpuid = 0); 18 ~CPUMeter(void); 19 20 const char *name(void) const { return "CPUMeter"; } 21 void checkevent(void); 22 23 void checkResources(void); 24 25 static int nCPUs(); 26 static const char *cpuStr(int num); 27 28 protected: 29 time_t cputime_[2][USED_CPU_STATES]; 30 int cpuindex_; 31 32 void getcputime(void); 33 const char *toUpper(const char *str); 34 35 private: 36 struct sysinfo tsp; 37 int sinfosz; 38 int cpuid_; 39 }; 40 41 #endif