package org.bench4q.monitor.service.windows;

import org.bench4q.monitor.model.ProcessorModel;
import org.bench4q.monitor.model.ProcessorModelChild;
import org.bench4q.monitor.performance.windows.ProcessorMonitor;
import org.springframework.beans.factory.annotation.Autowired;

public class ProcessorServiceWindows {
	public ProcessorServiceWindows() {
		this.processorMonitor = new ProcessorMonitor();
	}

	private ProcessorMonitor processorMonitor;

	public ProcessorMonitor getProcessorMonitor() {
		return processorMonitor;
	}

	@Autowired
	public void setProcessorMonitor(ProcessorMonitor processorMonitor) {
		this.processorMonitor = processorMonitor;
	}

	public ProcessorModel getProcessorInfo(int idleTime) {
		String instances[] = this.getProcessorMonitor().getInstances();
		ProcessorModel processorModel = new ProcessorModel();

		for (String elem : instances) {
			ProcessorModelChild processorModelChild = new ProcessorModelChild();
			processorModelChild.setInstance(elem);
			processorModelChild.setPrivilegedTimePercent(this
					.getProcessorMonitor().getPrivilegedTimePercent(elem,
							idleTime));
			processorModelChild.setProcessorTimePercent(this
					.getProcessorMonitor().getProcessorTimePercent(elem,
							idleTime));
			processorModelChild.setUserTimePercent(this.getProcessorMonitor()
					.getUserTimePercent(elem, idleTime));
			processorModel.getProcessorModelList().add(processorModelChild);
		}
		return processorModel;
	}

}
