Ejemplo n.º 1
0
/**
The acquisition of the current CPU information.
Distance of around one second is necessary for a second summons.
@params infos Write back by CPU information.
              There being more numbers of element of the sequence than the number of CPU cores.
@return infos
*/
CpuCoreInfo* cpumon_getInfos(CpuCoreInfo* infos) {
	int n;
	long used[coreNum];

	if (infos == NULL) {
		infos = calloc(coreNum, sizeof(CpuCoreInfo)); 
		if (infos == NULL) error(__LINE__);
	}

	calcCpuTimes(used);
	for (n=0; n<coreNum; n++) {
		infos[n].freq = (int)getSysctl(mibFreq[n]);
		infos[n].temp = (int)getSysctl(mibTemp[n]) - 2732; // K->C
		infos[n].used = used[n];
	}
	return infos;
}
Ejemplo n.º 2
0
/**
The initialization of this library.
@return number of cpu core.
*/
int cpumon_init() {
	int n;
	mibCoreNum  = getSysctlMib(NAME_CORE_NUM,0);
	mibCpuTimes = getSysctlMib(NAME_CPU_TIMES,0);
	coreNum = (int)getSysctl(mibCoreNum);
	for (n=0; n<coreNum; n++) {
		mibTemp[n] = getSysctlMib(NAME_TEMP,n);
		mibFreq[n] = getSysctlMib(NAME_FREQ,n);
	}

	long used[coreNum];
	calcCpuTimes(used);
	return coreNum;
}
Ejemplo n.º 3
0
int UtilObject::cores() { static const int count = getSysctl(HW_NCPU, 1); return count; }
Ejemplo n.º 4
0
double UtilObject::totalMemory(MemoryUnit unit) {
	static const quint64 total = getSysctl(HW_MEMSIZE, (quint64)0);
	return total/(double)unit;
}