[Mono-devel-list] Mono.LinuxDiagnostics

Jonathan Pryor jonpryor at vt.edu
Tue Nov 23 08:39:53 EST 2004


On Tue, 2004-11-23 at 10:19 +0000, anthony whalley wrote:
> Hello Again.
>     The Mono.AppServer needs System.Diagnostics.PerformanceCounter and
> it is not yet implemented. 
> I have searched around and I think the best approach
> for now would be to create a name space Mono.LinuxDiagnostics which
> would read directly from 
> /proc like top or ps does. 
> 
> Is there a better way to approach PerformanceCounter
> implementations?

The *correct* approach is to implement the PerformanceCounter and
related classes so that it will work on both Windows and Linux.
Gratuitous incompatibilities should be avoided if at all possible.

This would likely be best done by using the Bridge design pattern:

	internal interface IPerformanceCounter {/* ... */}

	public class PerformanceCounter {
		private IPerformanceCounter impl;

		public PerformanceCounter ()
		{
			this.impl = 
			  PerfCounterFactory.CreatePerformanceCounter();
		}

		public long Decrement () {return impl.Decrement();}
		// ...
	}

	internal class LinuxPerformaceCounter : IPerformanceCounter 
	{/* ... */}

	internal class WindowsPerformaceCounter : IPerformanceCounter 
	{/* ... */}

	internal sealed class PerfCounterFactory {
		public IPerformancCounter CreatePerformaceCounter ()
		{
			// return appropriate IPerformaceCounter impl.
		}
	}

This will likely involve more work, but it will allow programs to be
portable between Windows & Linux, increasing compatibility, and reducing
any special-case portability considerations (such as using
PerformanceCounter on Windows but Mono.LinuxDiagnostics on Unix, which
is a consideration I'm sure most developers would rather avoid).

 - Jon





More information about the Mono-devel-list mailing list