private static void ReadUsage() { try { var topActivity = TinyIoC.TinyIoCContainer.Current.Resolve <IMvxAndroidCurrentTopActivity> (); RandomAccessFile reader = new RandomAccessFile("/proc/stat", "r"); string load = reader.ReadLine(); string[] toks = load.Split(' '); long idle1 = long.Parse(toks [5]); long cpu1 = long.Parse(toks [2]) + long.Parse(toks [3]) + long.Parse(toks [4]) + long.Parse(toks [6]) + long.Parse(toks [7]) + long.Parse(toks [8]); try { Thread.Sleep(360); } catch (Exception) { } reader.Seek(0); load = reader.ReadLine(); reader.Close(); toks = load.Split(' '); float idle2 = float.Parse(toks [5]); float cpu2 = float.Parse(toks [2]) + float.Parse(toks [3]) + float.Parse(toks [4]) + float.Parse(toks [6]) + float.Parse(toks [7]) + float.Parse(toks [8]); float cpuValue = ((cpu2 - cpu1) * 100f / ((cpu2 + idle2) - (cpu1 + idle1))); CpuStack [_cpuStackPointer++] = cpuValue; if (_cpuStackPointer == 10) { _cpuStackPointer = 0; } var averageTxt = ((int)CpuStack.Take(10).Average()).ToString().PadLeft(2, '0'); TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1)); // Get VM Heap Size by calling: var heapSize = (Java.Lang.Runtime.GetRuntime().TotalMemory() / 1000).ToString().PadLeft(6, '0'); // Get Allocated VM Memory by calling: var allocated = ((Java.Lang.Runtime.GetRuntime().TotalMemory() - Java.Lang.Runtime.GetRuntime().FreeMemory()) / 1000).ToString().PadLeft(6, '0'); // Get Free Memory var free = (Java.Lang.Runtime.GetRuntime().FreeMemory() / 1000).ToString().PadLeft(6, '0'); // Get VM Heap Size Limit by calling: var heapSizeLimit = (Java.Lang.Runtime.GetRuntime().MaxMemory() / 1000).ToString().PadLeft(6, '0'); var mem = heapSize + " " + allocated + " " + free + " " + heapSizeLimit; System.Console.WriteLine("-|-cpu " + (((long)t.TotalSeconds * 1000L) + (long)DateTime.Now.Millisecond).ToString() + " " + averageTxt + " " + mem + " " + topActivity.Activity.Title); } catch (System.IO.IOException) { } }
public double GetCpuTemp() { if (cpuTempFile == null) { throw new NotSupportedException("CPU Temp not available"); } cpuTempFile.Seek(0); var s = cpuTempFile?.ReadLine(); if (string.IsNullOrWhiteSpace(s)) { throw new NotSupportedException("CPU Temp not available"); } double val; if (!double.TryParse(s, out val)) { throw new NotSupportedException("CPU Temp not available"); } if (val < -30 || val > 300) { val = val / 1000; } return(val); }
// https://stackoverflow.com/questions/16963292/read-current-cpu-frequency/19858957#19858957 float GetFrequency(string path) { using (var reader = new RandomAccessFile(path, "r")) { float.TryParse(reader.ReadLine(), out var result); return(result / 1000); } }
private static long GetTotalMemory() { using (var reader = new RandomAccessFile("/proc/meminfo", "r")) { var line = reader.ReadLine(); // first line --> MemTotal: xxxxxx kB var split = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return(Convert.ToInt64(split[1]) * 1024); } }
private static long GetTotalMemory() { using (var reader = new RandomAccessFile("/proc/meminfo", "r")) { var line = reader.ReadLine(); // first line --> MemTotal: xxxxxx kB var split = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return Convert.ToInt64(split[1]) * 1024; } }