Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages

CpuUsage Class Reference

#include <CpuUsage.hpp>

Collaboration diagram for CpuUsage:

Collaboration graph
[legend]
List of all members.

Public Member Functions

float utilization ()

Static Public Member Functions

CpuUsagegetInstance ()

Private Member Functions

void cpuLoop ()
 CpuUsage ()

Static Private Member Functions

void * cpuLoopWrapper (void *ptr)

Private Attributes

unsigned long us
unsigned long usLow
unsigned long sy
unsigned long id
unsigned long currTotal
unsigned long currUsed
unsigned long prevTotal
unsigned long prevUsed
double util
double utilInInterval
int numLoops
pthread_t thread
pthread_mutex_t mutex

Static Private Attributes

const int CPU_MEASURE_INTERVAL = 10
CpuUsagesingleInstance = 0

Detailed Description

CpuUsage - Utility class to measure Cpu Usage.

This class was designed to constantly measure CPU utilization on Linux systems. Basically, it starts a thread that periodically gathers information from the OS (via /proc), and reports the last average CPU utilization when queried.

CpuUsage is a singleton, since ther is no reason to have more than one CPU measurer in our system.

Author:
Andrei Goldchleger


Constructor & Destructor Documentation

CpuUsage::CpuUsage  )  [private]
 

Constructor.


Member Function Documentation

void CpuUsage::cpuLoop  )  [private]
 

CPU Measurement function (an infinite loop).

void * CpuUsage::cpuLoopWrapper void *  ptr  )  [static, private]
 

cpuLoop wrapper. Needed because pthreads require a function pointer

CpuUsage & CpuUsage::getInstance  )  [static]
 

Returns a reference to CpuUsage's singleton.

float CpuUsage::utilization  ) 
 

Returns average CPU utilization.

Returns a float in the range [0..100] representing the average CPU utilization since last call.


Member Data Documentation

const int CpuUsage::CPU_MEASURE_INTERVAL = 10 [static, private]
 

time between CPU usage measurements

unsigned long CpuUsage::currTotal [private]
 

unsigned long CpuUsage::currUsed [private]
 

unsigned long CpuUsage::id [private]
 

pthread_mutex_t CpuUsage::mutex [private]
 

protects CPU utilization from race conditions

int CpuUsage::numLoops [private]
 

unsigned long CpuUsage::prevTotal [private]
 

unsigned long CpuUsage::prevUsed [private]
 

CpuUsage * CpuUsage::singleInstance = 0 [static, private]
 

CpuUsage singleton

unsigned long CpuUsage::sy [private]
 

pthread_t CpuUsage::thread [private]
 

thread that keeps collecting CPU availability

unsigned long CpuUsage::us [private]
 

unsigned long CpuUsage::usLow [private]
 

double CpuUsage::util [private]
 

CPU utilization in current interval

double CpuUsage::utilInInterval [private]
 

diference bettween current and last measurement


The documentation for this class was generated from the following files:
Generated on Mon Sep 6 16:13:10 2004 by doxygen 1.3.3