View Single Post
Old May 31st, 2006, 9:29 PM   #3
coder0xff
Unverified User
 
coder0xff's Avatar
 
Join Date: Mar 2006
Posts: 18
Rep Power: 0 coder0xff is on a distinguished road
This is the code:

	__int64 RunningProcess::GetIOBytes()
	{
		IORetriever->InstanceName=PerformanceCounterName;
		return IORetriever->RawValue;
	}

As a demonstration to the poor performance I have written a small VB.net console application. The output:

Amount of time to print 1000 Integers:0.134375
Amount of time to read and print 1000 Performance Counter Values:51.20313
Approximate time (in ms) to call PerformanceCounter->RawValue:51.06875

This isn't practical for a program that wants to update the IO Data Bytes of each process once a second (or faster). On my laptop I average atleast 55 processes. I am running an AMD Athlon 64 3400+M Portable (2200 Mhz), and 1536 MB of RAM. Hardly a slow computer. This is the VB app code:

Module Module1

    Sub Main()
        Dim counter As System.Diagnostics.PerformanceCounter
        counter = New System.Diagnostics.PerformanceCounter("Process", "IO Data Bytes/sec", "explorer")
        Dim step1 As Integer
        Dim t As Single
        t = Timer
        For step1 = 0 To 10000
            System.Console.WriteLine(step1)
        Next
        Dim step1time As Single
        step1time = (Timer - t) / 10 //used 10000 ints - to be measurable
        Dim step2 As Integer
        For step2 = 0 To 1000
            System.Console.WriteLine(counter.RawValue)
        Next
        Dim step2time As Single
        step2time = Timer - t
        System.Console.Write("Amount of time to print 1000 Integers:")
        System.Console.WriteLine(step1time)
        System.Console.Write("Amount of time to read and print 1000 Performance Counter Values:")
        System.Console.WriteLine(step2time)
        System.Console.Write("Approximate time (in ms) to call PerformanceCounter->RawValue:")
        System.Console.WriteLine((step2time - step1time))
        System.Console.Read()
    End Sub

End Module
coder0xff is offline   Reply With Quote