[Mono-dev] New performance counter in Mono to report physical memory size in the machine

Marek Habersack grendel at twistedcode.net
Mon Apr 19 02:36:50 EDT 2010


On Sun, 18 Apr 2010 08:00:04 -0400
"Jay R. Wren" <jrwren at xmtp.net> wrote:

Hello,

> Confirmed, the constructor throws InvalidOperationException with a
> message of "Category does not exist." on .NET 4.
> 
> The code you pasted falls through to "Cannot detect Physical RAM".
> 
> It is not a big deal, but it is something of which people should be aware.
The behavior is exactly as documented in MSDN documentation for the PerformanceCounter class -
there are no surprises there.

marek

> --
> Jay
> 
> On 4/17/2010 10:14 PM, jmalcolm wrote:
> > Thanks Marek,
> >
> > Does this live in System.Diagnostics?
> >
> > Does this mean that the code you posted would fail on Microsoft.NET with an
> > InvalidOperationException?
> >
> > System.Diagnostics seems like the place Microsoft should have put it.  I am
> > just surprised to see a Mono extension that does not have it's own assembly
> > or namespace.  There are probably more that I have managed to miss or simply
> > forgotten about.
> >
> > Would something like the following be portable?
> >
> > --- CUT ---
> > using System;
> > using System.Diagnostics;
> >
> > class app
> > {
> >    static void Main ()
> >    {
> >        if (PerformanceCounterCategory.Exists("Mono Memory"))
> >        {
> >             var pc = new PerformanceCounter ("Mono Memory", "Total Physical
> > Memory");
> >             Console.WriteLine ("Physical RAM (bytes): {0}", pc.RawValue);
> >        }
> >        else
> >        {
> >             Console.WriteLine("Cannot detect physical RAM");
> >        }
> >    }
> > }
> > --- CUT ---
> >
> > Sorry if this is a basic question but I am currently on a Windows machine. 
> > Building Mono from trunk on Windows is not an area of strength for me and I
> > have not really played around with this part of the framework before.
> >   
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list



More information about the Mono-devel-list mailing list