Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded Memory Information - Free and Total memory for different platforms #847
Conversation
| { | ||
| if (RuntimeInformation.IsMacOSX()) | ||
| { | ||
| string sysctlContent = ProcessHelper.RunAndReadOutput("sysctl", "-a"); |
AndreyAkinshin
Aug 9, 2018
Member
We already call sysctl in SysctlCpuInfoProvider. Such calls are pretty expensive. Please, reuse existed data from SysctlCpuInfoProvider instead of an additional call.
We already call sysctl in SysctlCpuInfoProvider. Such calls are pretty expensive. Please, reuse existed data from SysctlCpuInfoProvider instead of an additional call.
ChiragRupani
Aug 9, 2018
Author
Right, added code to reuse call output for CPU and memory
Right, added code to reuse call output for CPU and memory
| { | ||
| if (RuntimeInformation.IsWindows()) | ||
| { | ||
| string content = ProcessHelper.RunAndReadOutput("wmic", "OS get TotalVisibleMemorySize, FreePhysicalMemory /Format:List"); |
AndreyAkinshin
Aug 9, 2018
Member
Please, reuse the wmic call from WmicCpuInfoProvider
Please, reuse the wmic call from WmicCpuInfoProvider
ChiragRupani
Aug 9, 2018
Author
wmic cpu is used for CPU and wmic OS is used for memory, the call output can not be reused
wmic cpu is used for CPU and wmic OS is used for memory, the call output can not be reused
AndreyAkinshin
Aug 9, 2018
Member
Ok.
Ok.
| @@ -155,6 +156,22 @@ internal static CpuInfo GetCpuInfo() | |||
| return null; | |||
| } | |||
|
|
|||
| public static bool IsVistaAndAbove() => Version.Parse(RuntimeEnvironment.OperatingSystemVersion).Major >= 6; | |||
AndreyAkinshin
Aug 9, 2018
Member
BenchmarkDotNet v0.11.0+ requires .NET Framework 4.6+. Windows XP doesn't support .NET Framework 4.6+ and .NET Core. So, we can assume that the Windows version is always vista or above.
BenchmarkDotNet v0.11.0+ requires .NET Framework 4.6+. Windows XP doesn't support .NET Framework 4.6+ and .NET Core. So, we can assume that the Windows version is always vista or above.
ChiragRupani
Aug 9, 2018
Author
Removed the code
Removed the code
| if (IsWindows() && IsVistaAndAbove()) | ||
| return MoSMemoryInfoProvider.MosMemoryInfo.Value; | ||
| if (IsWindows()) | ||
| return WmicMemoryInfoProvider.WmicMemoryInfo.Value; |
AndreyAkinshin
Aug 9, 2018
Member
Do we really need two different ways to get this information on Windows?
Do we really need two different ways to get this information on Windows?
AndreyAkinshin
Aug 9, 2018
Member
I guess, it's better to use only Wmic because we already have a wmic call.
I guess, it's better to use only Wmic because we already have a wmic call.
ChiragRupani
Aug 9, 2018
Author
Done
Done
| <ItemGroup> | ||
| <None Remove="Portability\Memory\TestFiles\SysctlMemory.txt" /> | ||
| <None Remove="Portability\Memory\TestFiles\VmStatMemory.txt" /> | ||
| </ItemGroup> |
AndreyAkinshin
Aug 9, 2018
Member
Why do we need these lines?
Why do we need these lines?
ChiragRupani
Aug 9, 2018
Author
Removed - not required.
Removed - not required.
| <ItemGroup> | ||
| <EmbeddedResource Include="Portability\Memory\TestFiles\SysctlMemory.txt" /> | ||
| <EmbeddedResource Include="Portability\Memory\TestFiles\VmStatMemory.txt" /> | ||
| </ItemGroup> |
AndreyAkinshin
Aug 9, 2018
Member
Please, embed the whole folder (<EmbeddedResource Include="Portability\Memory\TestFiles\*.txt" />)
Please, embed the whole folder (<EmbeddedResource Include="Portability\Memory\TestFiles\*.txt" />)
ChiragRupani
Aug 9, 2018
Author
Done
Done
|
LGTM in general. Some minor changes are requested. |
|
Resolved code review comments, for failing approval tests - total memory need to be of CI machine and free memory is dynamic. How it can be handled? |
You should replace it in |
| internal static class SysctlInfoProvider | ||
| { | ||
| internal static readonly Lazy<string> SysctlInfo = new Lazy<string>(Load); | ||
| private static string _sysctlInfo = null; |
AndreyAkinshin
Aug 9, 2018
Member
We don't use _ as a field prefix.
We don't use _ as a field prefix.
ChiragRupani
Aug 9, 2018
Author
Done
Done
|
I have another concern about Linux. I don't think that it makes sense to print "Free" memory from
The whole stats (some numbers have a small drift because I had different activities between measurements):
I suggest using the htop format and print |
|
The same experiment on macOS.
|
|
Linux: MacOS: |
|
@ChiragRupani, I guess we can print "Total/Used" on all operating systems because "Used memory" provides useful information not only on Windows but also on Linux and macOS. |
|
Its better to keep available memory as it is since available memory can be calculated as below: |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.





Added Memory Information - Free and Total memory for different platforms, for #846 Add RAM to summary