The Wayback Machine - http://web.archive.org/web/20201011123855/https://github.com/dotnet/BenchmarkDotNet/pull/847
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Memory Information - Free and Total memory for different platforms #847

Open
wants to merge 8 commits into
base: master
from

Conversation

@ChiragRupani
Copy link

@ChiragRupani ChiragRupani commented Aug 8, 2018

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

{
if (RuntimeInformation.IsMacOSX())
{
string sysctlContent = ProcessHelper.RunAndReadOutput("sysctl", "-a");

This comment has been minimized.

@AndreyAkinshin

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.

This comment has been minimized.

@ChiragRupani

ChiragRupani Aug 9, 2018
Author

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");

This comment has been minimized.

@AndreyAkinshin

AndreyAkinshin Aug 9, 2018
Member

Please, reuse the wmic call from WmicCpuInfoProvider

This comment has been minimized.

@ChiragRupani

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

This comment has been minimized.

@@ -155,6 +156,22 @@ internal static CpuInfo GetCpuInfo()
return null;
}

public static bool IsVistaAndAbove() => Version.Parse(RuntimeEnvironment.OperatingSystemVersion).Major >= 6;

This comment has been minimized.

@AndreyAkinshin

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.

This comment has been minimized.

@ChiragRupani

ChiragRupani Aug 9, 2018
Author

Removed the code

if (IsWindows() && IsVistaAndAbove())
return MoSMemoryInfoProvider.MosMemoryInfo.Value;
if (IsWindows())
return WmicMemoryInfoProvider.WmicMemoryInfo.Value;

This comment has been minimized.

@AndreyAkinshin

AndreyAkinshin Aug 9, 2018
Member

Do we really need two different ways to get this information on Windows?

This comment has been minimized.

@AndreyAkinshin

AndreyAkinshin Aug 9, 2018
Member

I guess, it's better to use only Wmic because we already have a wmic call.

This comment has been minimized.

<ItemGroup>
<None Remove="Portability\Memory\TestFiles\SysctlMemory.txt" />
<None Remove="Portability\Memory\TestFiles\VmStatMemory.txt" />
</ItemGroup>

This comment has been minimized.

@AndreyAkinshin

AndreyAkinshin Aug 9, 2018
Member

Why do we need these lines?

This comment has been minimized.

@ChiragRupani

ChiragRupani Aug 9, 2018
Author

Removed - not required.

<ItemGroup>
<EmbeddedResource Include="Portability\Memory\TestFiles\SysctlMemory.txt" />
<EmbeddedResource Include="Portability\Memory\TestFiles\VmStatMemory.txt" />
</ItemGroup>

This comment has been minimized.

@AndreyAkinshin

AndreyAkinshin Aug 9, 2018
Member

Please, embed the whole folder (<EmbeddedResource Include="Portability\Memory\TestFiles\*.txt" />)

This comment has been minimized.

Copy link
Member

@AndreyAkinshin AndreyAkinshin left a comment

LGTM in general. Some minor changes are requested.

@ChiragRupani
Copy link
Author

@ChiragRupani ChiragRupani commented Aug 9, 2018

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?

@AndreyAkinshin
Copy link
Member

@AndreyAkinshin AndreyAkinshin commented Aug 9, 2018

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 MockHostEnvironmentInfo by fake hardcoded values.

internal static class SysctlInfoProvider
{
internal static readonly Lazy<string> SysctlInfo = new Lazy<string>(Load);
private static string _sysctlInfo = null;

This comment has been minimized.

@AndreyAkinshin

AndreyAkinshin Aug 9, 2018
Member

We don't use _ as a field prefix.

This comment has been minimized.

@AndreyAkinshin
Copy link
Member

@AndreyAkinshin AndreyAkinshin commented Aug 10, 2018

I have another concern about Linux. I don't think that it makes sense to print "Free" memory from /proc/meminfo. Currently, I have the following line in the BenchmarkDotNet output:

Total Memory=31.38 GB, Free Memory=0.37 GB

The whole stats (some numbers have a small drift because I had different activities between measurements):

$ cat /proc/meminfo 
MemTotal:       32904420 kB
MemFree:          415612 kB
MemAvailable:    6204328 kB
Buffers:         1270516 kB
Cached:          3843920 kB
SwapCached:         1136 kB
Active:         27942284 kB
Inactive:        3192896 kB
Active(anon):   23296324 kB
Inactive(anon):  2192128 kB
Active(file):    4645960 kB
Inactive(file):  1000768 kB
Unevictable:         232 kB
Mlocked:             232 kB
SwapTotal:       7999484 kB
SwapFree:        7974908 kB
Dirty:              1232 kB
Writeback:             0 kB
AnonPages:      26020568 kB
Mapped:          2779036 kB
Shmem:            969228 kB
Slab:             841104 kB
SReclaimable:     611448 kB
SUnreclaim:       229656 kB
KernelStack:       28480 kB
PageTables:       153144 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    24451692 kB
Committed_AS:   40689380 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:     3029980 kB
DirectMap2M:    29440000 kB
DirectMap1G:     1048576 kB
$ vmstat -s
     32904420 K total memory
     26693376 K used memory
     27852808 K active memory
      3167168 K inactive memory
       545832 K free memory
      1270684 K buffer memory
      4394528 K swap cache
      7999484 K total swap
        24576 K used swap
      7974908 K free swap
     12136084 non-nice user cpu ticks
       287263 nice user cpu ticks
      2815775 system cpu ticks
    192840749 idle cpu ticks
       308475 IO-wait cpu ticks
            0 IRQ cpu ticks
       143378 softirq cpu ticks
            0 stolen cpu ticks
     35812936 pages paged in
    501444032 pages paged out
          475 pages swapped in
         5888 pages swapped out
   1997545531 interrupts
   2354026314 CPU context switches
   1533637428 boot time
      2355729 forks

htop:
screenshot_20180810_141206
top:
screenshot_20180810_141348

I suggest using the htop format and print Mem/used/buffers/cache. What do you think?

@AndreyAkinshin
Copy link
Member

@AndreyAkinshin AndreyAkinshin commented Aug 10, 2018

The same experiment on macOS.
BenchmarkDotNet:

Total Memory=16 GB, Free Memory=0.98 GB
$ vm_stat
Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                               90662.
Pages active:                           1685717.
Pages inactive:                         1553942.
Pages speculative:                        38418.
Pages throttled:                              0.
Pages wired down:                        682750.
Pages purgeable:                          20762.
"Translation faults":                1314731806.
Pages copy-on-write:                   25196855.
Pages zero filled:                    733593693.
Pages reactivated:                    124220354.
Pages purged:                          13424421.
File-backed pages:                       859068.
Anonymous pages:                        2419009.
Pages stored in compressor:             4872948.
Pages occupied by compressor:            142518.
Decompressions:                       128182734.
Compressions:                         173530019.
Pageins:                               72689687.
Pageouts:                                712547.
Swapins:                               80355093.
Swapouts:                              84599798.

htop:
image
top:
image

@ChiragRupani
Copy link
Author

@ChiragRupani ChiragRupani commented Aug 11, 2018

Linux:
Makes sense and this explains why free memory is always showed as lower value. However, as Used Memory already includes buffer+cache, Can we show: Total/Free/Buffers/Cache?

MacOS:
What about MacOS, which fields need to be considered?

@AndreyAkinshin
Copy link
Member

@AndreyAkinshin AndreyAkinshin commented Aug 16, 2018

@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.

@ChiragRupani
Copy link
Author

@ChiragRupani ChiragRupani commented Sep 3, 2018

Its better to keep available memory as it is since available memory can be calculated as below:
Linux: MemAvailable
MacOS: Free + Inactive

ChiragRupani added 2 commits Sep 3, 2018
Linux: MemAvailable
MacOS: Free + Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.