PerformanceCounter.NextValue is integer not single?

PerformanceCounter.NextValue appears to return integer values instead

Page 1 of 1

1 Replies - 3149 Views - Last Post: 31 August 2009 - 11:31 AM Rate Topic: -----

#1 erickh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-June 09

PerformanceCounter.NextValue is integer not single?

Posted 18 August 2009 - 06:26 PM

PerformanceCounter.NextValue appears to return integer values instead of single values.


The code below has a button, Button1 and a textbox, TextBox1. Click on the button and the textbox is filled with the CPU usage of each process at a given time. I would assume that these values should match with the values in task manager.



	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		TextBox1.Text = Now.ToString & vbCrLf & vbCrLf
		TextBox1.Text &= GetInfo()
		Application.DoEvents()

	End Sub


	Private Function GetInfo() As String

		Dim c As New System.Diagnostics.PerformanceCounter()
		c.CategoryName = "Process"
		c.CounterName = "% Processor Time"
		c.ReadOnly = True

		Dim pArray() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses
		Dim p As System.Diagnostics.Process

		Dim s As String = ""
		Dim d As Double = 0

		For Each p In pArray

			c.InstanceName = p.ProcessName  '  set the counter instance to the current process

			s &= p.ProcessName & vbTab

			Try 
				d = c.NextValue  ' read that the first instance of .NextValue is always 0
			Catch ex As Exception
				'do nothing
			End Try

			Try
				s &= c.NextValue & vbCrLf
			Catch ex As Exception
				s &= "UNKNOWN" & vbTab & ex.Message & vbCrLf
			End Try

		Next

		Return s

	End Function





Here is a sample output, which doesn't match the results when using task manager. Note that the first example adds to 100% while the second output sample does not.

Quote

8/18/2009 9:11:14 PM

services 0
ccApp 0
wmiprvse 0
Iap 0
GoogleToolbarNotifier 0
inetinfo 0
PGPserv 0
snmp 0
svchost 0
vbexpress 0
ccEvtMgr 0
svchost 0
explorer 0
nvsvc32 0
spoolsv 0
firefox 0
mqsvc 0
TimeKeeper.vshost 100
hpcmpmgr 0
sqlmangr 0
msmdsrv 0
svchost 0
ReportingServicesService 0
svchost 0
sqlservr 0
smss 0
shservice 0
quickset 0
svchost 0
wuauclt 0
DefWatch 0
winlogon 0
WLTRYSVC 0
RIMAutoUpdate 0
mdm 0
MsDtsSrvr 0
SetPoint 0
tcpsvcs 0
SavRoam 0
sqlbrowser 0
Rtvscan 0
wmiprvse 0
VPTray 0
DSentry 0
ccSetMgr 0
svchost 0
qttask 0
KHALMNPR 0
jusched 0
csrss 0
msdtc 0
BCMWLTRY 0
lsass 0
ctfmon 0
BAsfIpM 0
System 0
svchost 0
sqlservr 0
Idle 0


Quote

8/18/2009 9:12:10 PM

services 0
ccApp 0
wmiprvse 0
Iap 0
GoogleToolbarNotifier 0
inetinfo 0
PGPserv 0
snmp 0
svchost 0
vbexpress 0
ccEvtMgr 0
svchost 0
explorer 0
nvsvc32 0
spoolsv 0
firefox 0
mqsvc 0
TimeKeeper.vshost 0
hpcmpmgr 0
sqlmangr 0
msmdsrv 0
svchost 0
ReportingServicesService 0
svchost 0
sqlservr 0
smss 0
shservice 0
quickset 0
svchost 0
wuauclt 0
DefWatch 0
winlogon 0
WLTRYSVC 0
RIMAutoUpdate 0
mdm 0
MsDtsSrvr 0
SetPoint 0
tcpsvcs 0
SavRoam 0
sqlbrowser 0
Rtvscan 0
wmiprvse 0
VPTray 0
DSentry 0
ccSetMgr 0
svchost 0
qttask 0
KHALMNPR 0
jusched 0
csrss 0
msdtc 0
BCMWLTRY 0
lsass 0
ctfmon 0
BAsfIpM 0
System 0
svchost 0
sqlservr 0
Idle 0



My guess is that these processes are taking up SOME amount of CPU and are just being rounded down to 0. In the first example I would guess that the CPU amount is rounded up to 100 %.

Any thoughts on how to show the actual values would be appreciated.


Thanks!

Erick

Is This A Good Question/Topic? 0
  • +

Replies To: PerformanceCounter.NextValue is integer not single?

#2 erickh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-June 09

Re: PerformanceCounter.NextValue is integer not single?

Posted 31 August 2009 - 11:31 AM

Nobody has any suggestions?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1