Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 29th, 2006, 11:44 PM   #1
coder0xff
Unverified User
 
coder0xff's Avatar
 
Join Date: Mar 2006
Posts: 18
Rep Power: 0 coder0xff is on a distinguished road
Slow Performance Counter

I am writting a program using .Net. I am using the PerformanceCounter class and as previous experience with this class has also shown, the retrieval of values is prohibitively slow. (Atleast in the context which I am using it in) In this particular scenario I am getting the "Process">"IO Data Bytes/sec" for each process and using the RawValue, not the computed NextValue(). Is there another way I can retrieve this information (is it beneficial to use advapi.dll and bypass .net?). Less importantly (or perhaps more) why are the performance classes so slow anyway? I looked around on the net and found issues about slow constructors and over network parallel use problems, but not much on the slow performance of retrieving values otherwise. It looks like the underlying RegQueryValueEx function is rather time consuming. Funny that the word Performance is in the name of the class, isn't it?
coder0xff is offline   Reply With Quote
Old May 30th, 2006, 4:39 AM   #2
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by coder0xff
It looks like the underlying RegQueryValueEx function is rather time consuming.
I might be wrong, but I think you're the one making it slow rather than the function being slow.
Can you show a bit of the code?
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old May 31st, 2006, 10: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
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC