public VmCpuStat getVmCpuStat() { string filename = "/proc/stat"; if (File.Exists(filename)) { string text = ""; using (StreamReader sr = File.OpenText(filename)) { text = sr.ReadLine(); string [] par1 = text.Split(" "); VmCpuStat vcs = new VmCpuStat(Int64.Parse(par1[2]), Int64.Parse(par1[3]), Int64.Parse(par1[4]), Int64.Parse(par1[5]), Int64.Parse(par1[6]), Int64.Parse(par1[7]), Int64.Parse(par1[8]), Int64.Parse(par1[9])); while ((text = sr.ReadLine()) != null && text.Length != 0) { // get boot time in ms since epoch if (text.Contains("btime")) { par1 = text.Split(" "); vcs.btime = Int64.Parse(par1[1]); } } return(vcs); } } else { return(new VmCpuStat()); } }
public VmCpuStat getVmCpuStatDiff(VmCpuStat v1, VmCpuStat v2) { return(new VmCpuStat(v2.cpuusr - v1.cpuusr, v2.cpunice - v1.cpunice, v2.cpukrn - v1.cpukrn, v2.cpuidle - v1.cpuidle, v2.cpuiowait - v1.cpuiowait, v2.cpuirq - v1.cpuirq, v2.cpusirq - v1.cpusirq, v2.cpusteal - v1.cpusteal)); }