How can i display cpu effort..?

BlitzMax Forums/BlitzMax Beginners Area/How can i display cpu effort..?

Hardcoal(Posted 2016) [#1]
Hi.. I would like to display cpu effort as percentage.
How can i do so?

Tnx


xlsior(Posted 2016) [#2]
Under windows, it's tricky -- I don't believe there's a Win32 API call, you'll most likely have to query Window's WMI subsystem somehow.


RustyKristi(Posted 2016) [#3]
found a blog post with examples in C# and C++ also so maybe this will get you started. It is shown by thread id and its percentage.

http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/

Example binaries and sources also in post. It can be converted into a mod but of course with some changes and to your needs.


Hardcoal(Posted 2016) [#4]
Oh. I expected it to be simpler
Tnx


dw817(Posted 2016) [#5]
Hardcoal, there is a very useful Freeware utility I have been using for all iterations of Windows called, "Process Explorer."

With it you can track and trace every single process in Windows including seeing a small icon of your current CPU usage.

I find it invaluable as any time it peaks, I check to see what is using up my CPU. You can also designate individual programs to have higher or lesser priority.

You can find and download it from Microsoft HERE:

https://technet.microsoft.com/en-us/sysinternals/processexplorer.aspx


Hardcoal(Posted 2016) [#6]
Tnx dw..

Im trying to implant on my editor something that indicates how much my editor while running is consuming.
So i need a blitzmax command..

But since its not in my most urgent priorities atm, i delay it for now..

But tnx Mate


Fielder(Posted 2016) [#7]
Type CPUMonitor

	' References...
	
	' http://www.codeproject.com/Articles/9113/Get-CPU-Usage-with-GetSystemTimes
	' http://www.purebasic.fr/english/viewtopic.php?t=26200&start=3
	' http://msdn.microsoft.com/en-us/library/windows/desktop/ms724400%28v=vs.85%29.aspx

	Const SAMPLES:Int = 3

	Field cpu_sample:Int [SAMPLES]
	
	Field idle:Win32FileTime = New Win32FileTime
	Field kern:Win32FileTime = New Win32FileTime
	Field user:Win32FileTime = New Win32FileTime
	
	Field last_idle:Win32FileTime = New Win32FileTime
	Field last_kern:Win32FileTime = New Win32FileTime
	Field last_user:Win32FileTime = New Win32FileTime

	' Pass False for realtime value, though result will fluctuate a lot more...

	Method Usage:Int (average:Int = True)
	
		GetSystemTimes idle, kern, user
		
		' Apparently only need the 'low' part of the FILETIME structure...
		
		Local idl:Int = idle.lo - last_idle.lo
		Local krn:Int = kern.lo - last_kern.lo
		Local usr:Int = user.lo - last_user.lo
	
		last_idle.lo = idle.lo
		last_kern.lo = kern.lo
		last_user.lo = user.lo
	
		Local sys:Int = krn + usr
		
		Local cpu:Int
		
		If sys
			cpu = Int ((sys - idl) * 100 / sys)
		Else
			cpu = 0
		EndIf
	
		If average
		
			Local avg_cpu:Int = 0
			
			For Local loop:Int = 0 Until SAMPLES - 1
				cpu_sample [loop] = cpu_sample [loop + 1]
				'Print "cpu_sample [" + loop + "] = " + cpu_sample [loop]
				avg_cpu = avg_cpu + cpu_sample [loop]
			Next
			
			cpu_sample [SAMPLES - 1] = cpu
		
			avg_cpu = avg_cpu + cpu_sample [SAMPLES - 1]
			
			avg_cpu = avg_cpu / SAMPLES
			
			' Print "Current sample: " + cpu + " (Average of last three samples: " + avg_cpu + ")"
		
			If avg_cpu < 0 Then avg_cpu = 0
			
			Return avg_cpu
			
		Else
		
			If cpu < 0 Then cpu = 0
			
			Return cpu
			
		EndIf
		
	End Method
	
End Type


Global cpuuse:CPUMonitor = New CPUMonitor

valueofcpuusage=cpuuse.Usage ();


xlsior(Posted 2016) [#8]
That one seems to miss some pieces... Here's a working one, based on Blitzsupport's posting here: http://www.blitzbasic.com/Community/post.php?topic=103567&post=1248083




Hardcoal(Posted 2016) [#9]
Geees.. Tnx man for the effort..
Ill check it soon

I love this community

You too xlsior


Hardcoal(Posted 2016) [#10]
Now My real need is to display the effort of my Editor..
how can I display how much power only it takes?