[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:35:20 EDT 2010

On Sat, 17 Apr 2010 18:14:49 -0800 (PST)
jmalcolm <malcolm.justin at gmail.com> 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?
Using this particular category, yes - it is described in the article as Mono-specific and the
constructor is supposed to throw the exception
(see http://msdn.microsoft.com/en-us/library/z0wssx8x.aspx)
> 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.
There's nothing to be put in a separate assembly. The code throws an exception not because we
extended something, but because the performance counter _category_ doesn't exist
(http://www.mono-project.com/Mono_Performance_Counters#Category:_Mono_Memory) on .NET. Replace "Mono
Memory" with any other non-Mono specific category in the list and it will work. You are always
expected to handle the exceptions that are thrown by the class code - the sample is just a
simple snippet of code to show a technique. Performance counters are implemented in the
Mono runtime, not in managed code, so they don't belong in any assembly.

> Would something like the following be portable?
Both your code and the sample are perfectly portable.

> 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.
I've updated the article with an extended sample and a note about the exception. I've noticed that
Mono doesn't throw the InvalidOperationException for missing categories. Will look into that later


More information about the Mono-devel-list mailing list