int64
PageFaultsDataSource::NextValue(SystemInfo& info)
{
	uint64 faults = info.PageFaults();

	int64 faultsPerSecond = uint64(1024 * double(faults - fPreviousFaults)
		/ (info.Time() - fPreviousTime) * 1000000.0);

	fPreviousFaults = faults;
	fPreviousTime = info.Time();

	return faultsPerSecond;
}
int64
NetworkUsageDataSource::NextValue(SystemInfo& info)
{
	uint64 transferred = fIn ? info.NetworkReceived() : info.NetworkSent();

	int64 bytesPerSecond = uint64(double(transferred - fPreviousBytes)
		/ (info.Time() - fPreviousTime) * 1000000.0);

	fPreviousBytes = transferred;
	fPreviousTime = info.Time();

	return bytesPerSecond;
}
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;
}
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;
}