public static UInt64 GetProperty(MemPropOSX prop, string output) { var propName = Regex.Escape(prop.GetAttributeProperty <SysctlPropertyNameAttribute, string>(attribute => attribute.Name)); var match = new Regex(propName + @"\s*?[=:]\s*?(?<" + propName + @">\d+)", RegexOptions.Multiline).Match(output); return(match.Success ? match.Groups[propName].Value.ParseUInt64Invariant() : 0); }
/// <seealso href="http://stackoverflow.com/a/8782351/467582"/> private static ulong GetMemoryOSX2(MemPropOSX prop) { var output = GetProcessOutput("/usr/bin/vm_stat"); // var pageSize = Regex.Match(output, @"page size of (\d+) bytes"); return(0); }
private static ulong GetMemoryOSX(MemPropOSX prop) { using (var process = new Process()) { process.StartInfo = new ProcessStartInfo("sysctl", "-a") { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, }; process.Start(); var propName = prop.GetAttributeProperty <DescriptionAttribute, string>(attribute => attribute.Description); var output = process.StandardOutput.ReadToEnd(); var match = new Regex(@"hw\." + propName + @"\s+?=\s+?(?<" + propName + @">\d+)", RegexOptions.Multiline).Match(output); return(match.Success ? UInt64.Parse(match.Groups[propName].Value) : 0); } }
private static ulong GetMemoryOSX3(MemPropOSX prop) { var output = GetProcessOutput("sysctl", "-a"); return(SysctlPropertyNameAttribute.GetProperty(prop, output)); }
private static ulong GetMemoryOSX(MemPropOSX prop) { using (var process = new Process()) { process.StartInfo = new ProcessStartInfo("sysctl", "-a") { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, }; process.Start(); var propName = prop.GetAttributeProperty<DescriptionAttribute, string>(attribute => attribute.Description); var output = process.StandardOutput.ReadToEnd(); var match = new Regex(@"hw\." + propName + @"\s+?=\s+?(?<" + propName + @">\d+)", RegexOptions.Multiline).Match(output); return match.Success ? UInt64.Parse(match.Groups[propName].Value) : 0; } }