コード例 #1
0
int64
CPUCombinedUsageDataSource::NextValue(SystemInfo& info)
{
	int32 running = 0;
	bigtime_t active = 0;

	for (int32 cpu = 0; cpu < info.Info().cpu_count; cpu++) {
		active += info.Info().cpu_infos[cpu].active_time;
		running++;
			// TODO: take disabled CPUs into account
	}

	int64 percent = int64(1000.0 * (active - fPreviousActive)
		/ (running * (info.Time() - fPreviousTime)));
	if (percent < 0)
		percent = 0;
	if (percent > 1000)
		percent = 1000;

	fPreviousActive = active;
	fPreviousTime = info.Time();

	return percent;
}
コード例 #2
0
int64
CPUUsageDataSource::NextValue(SystemInfo& info)
{
	bigtime_t active = info.Info().cpu_infos[fCPU].active_time;

	int64 percent = int64(1000.0 * (active - fPreviousActive)
		/ (info.Time() - fPreviousTime));
	if (percent < 0)
		percent = 0;
	if (percent > 1000)
		percent = 1000;

	fPreviousActive = active;
	fPreviousTime = info.Time();

	return percent;
}