![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Unverified User
Join Date: Mar 2006
Posts: 18
Rep Power: 0
![]() |
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?
|
|
|
|
|
|
#2 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
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 |
|
|
|
|
|
|
#3 |
|
Unverified User
Join Date: Mar 2006
Posts: 18
Rep Power: 0
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|