<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
+ <ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>full</DebugType>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="Mono.Posix" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
using System;
using System.Text.RegularExpressions;
using System.IO;
+using Mono.Unix.Native;
+using System.Diagnostics;
namespace FreeCSharp
{
{
public static void Main(string[] args)
{
+ Console.WriteLine ();
+ Console.WriteLine ("USING free C#, just UNIX");
FreeCSharp free = new FreeCSharp();
free.GetValues();
long mainUsed = free.MemTotal - free.MemFree;
// What you would get from free command:
- Console.WriteLine("-/+ buffers/cache: {0} {1}", (mainUsed - buffersPlusCached), (free.MemFree + buffersPlusCached));
+ Console.WriteLine("-/+ buffers/cache: {0} {1}",
+ (mainUsed - buffersPlusCached), (free.MemFree + buffersPlusCached));
// What means:
Console.WriteLine("Used physical memory: {0} kB", mainUsed - buffersPlusCached);
Console.WriteLine("Available physical memory: {0} kB", free.MemFree + buffersPlusCached);
+
+ Console.WriteLine ();
+ Console.WriteLine ("USING SYSCALL, just UNIX");
+ OperatingSystem os = Environment.OSVersion;
+ PlatformID pid = os.Platform;
+ if (pid == PlatformID.Unix || pid == PlatformID.MacOSX) {
+ long pages = Syscall.sysconf (SysconfName._SC_AVPHYS_PAGES);
+ long page_size = Syscall.sysconf (SysconfName._SC_PAGESIZE);
+ Console.WriteLine("The number of currently available pages of physical memory: {0}, " +
+ "Size of a page in bytes: {1} bytes", pages, page_size);
+ Console.WriteLine("Mem: {0} bytes", pages * page_size);
+ }
+
+ if (pid == PlatformID.Unix || pid == PlatformID.MacOSX) {
+ long pages = Syscall.sysconf (SysconfName._SC_PHYS_PAGES);
+ long page_size = Syscall.sysconf (SysconfName._SC_PAGESIZE);
+ Console.WriteLine("The number of pages of physical memory: {0}, " +
+ "Size of a page in bytes: {1} bytes", pages, page_size);
+ Console.WriteLine("Mem: {0} bytes", pages * page_size);
+ }
+
+
+ Console.WriteLine ();
+ Console.WriteLine ("USING PerformanceCounter, platform independent");
+ string categoryName = "Mono Memory";
+ string counterName = "Total Physical Memory";
+
+ try {
+ var pc = new PerformanceCounter (categoryName, counterName);
+ Console.WriteLine ("Value of performance counter '{0}/{1}': {2}",
+ categoryName, counterName, pc.RawValue);
+ } catch (InvalidOperationException ex) {
+ Console.WriteLine ("Category name '{0}' does not exist. {1}",
+ categoryName, ex.Message);
+ }
}
}