static NetStatistics() { var statReader = new Utf8FileReader(NetDevPath, 512); try { statReader.SkipLine(); statReader.SkipFragment('|'); statReader.SkipWhiteSpaces(); var receiveColumnCount = 0; while (true) { var column = statReader.ReadWord(); if (column.IndexOf('|') >= 0) { if (column.Length != 0) { ++receiveColumnCount; } break; } ++receiveColumnCount; } ReceiveColumnCount = receiveColumnCount; } finally { statReader.Dispose(); } }
internal static IEnumerable <CpuStatistics> GetAll() { var statReader = new Utf8FileReader(StatPath, 4096); try { while (!statReader.EndOfStream) { var cpuStr = statReader.ReadWord(); if (!cpuStr.StartsWith(CpuNumberStart.Span)) { yield break; } var cpuNumberStr = cpuStr.Slice(CpuNumberStart.Length); short?cpuNumber; if (cpuNumberStr.Length == 0) { cpuNumber = null; } else { Utf8Parser.TryParse(cpuNumberStr, out short num, out _); cpuNumber = num; } var ticksPerSecond = (double)ProcFs.TicksPerSecond; var userTime = statReader.ReadInt64() / ticksPerSecond; var niceTime = statReader.ReadInt64() / ticksPerSecond; var kernelTime = statReader.ReadInt64() / ticksPerSecond; var idleTime = statReader.ReadInt64() / ticksPerSecond; statReader.SkipWord(); var irqTime = statReader.ReadInt64() / ticksPerSecond; var softIrqTime = statReader.ReadInt64() / ticksPerSecond; statReader.SkipLine(); yield return(new CpuStatistics { CpuNumber = cpuNumber, UserTime = userTime, NiceTime = niceTime, KernelTime = kernelTime, IdleTime = idleTime, IrqTime = irqTime, SoftIrqTime = softIrqTime }); } } finally { statReader.Dispose(); } }