Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

CPU usage


  • Please log in to reply
12 replies to this topic
Babis
  • Members
  • 69 posts
  • Last active: Aug 26 2015 09:31 AM
  • Joined: 08 Dec 2005
Hi. I am using a "cpu usage" script by Laszlo, trimmed by evl.

This script displays the cpu usage numerically at the start button.

I am trying to personalize it (without success), in way that it will show numbers in white when the cpu usage is 1-33, orange when usage is 34-66 and red when 67-100.

Please guide/advise

Thanks.


#Persistent
SetTimer, CheckCPULoad, 1000
return

CheckCPULoad:
  SetFormat, float, 02
  ControlSetText, Button1, % " " GetCPULoad() " %", ahk_class Shell_TrayWnd
return

GetCPULoad()
{
  Global
  SetBatchLines, -1
  IdleTime0 = %IdleTime%  ; Save previous values
  Tick0 = %Tick%
  DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
  IdleTime := *(&IdleTicks)
  Loop 7                  ; Ticks when Windows was idle
    IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
  Tick := A_TickCount     ; Ticks all together
  load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
  Return, load
}


majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
Hm... very annoying to have it in start button
Plus everybody that use themes will not be able to see it.

You should examine dynamic tray icons.
For instance you can create 10 icons and when Xn
Or you can draw icons real time, not to complex.. even histogram
Posted Image

Andi
  • Members
  • 195 posts
  • Last active: Apr 18 2014 05:03 PM
  • Joined: 11 Feb 2005
Try this... but I don't know, how to change the color :?
#Persistent 
SetTimer, CheckCPULoad, 1000 
return 

CheckCPULoad: 
  SetFormat, float, 02 
  ControlSetText, Button1, % GetCPULoad(), ahk_class Shell_TrayWnd 
return 

GetCPULoad() 
{ 
  Global 
  SetBatchLines, -1 
  IdleTime0 = %IdleTime%  ; Save previous values 
  Tick0 = %Tick% 
  DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0) 
  IdleTime := *(&IdleTicks) 
  Loop 7                  ; Ticks when Windows was idle 
    IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index ) 
  Tick := A_TickCount     ; Ticks all together 
  load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0) 
  Return, load 
}


mc
  • Members
  • 2 posts
  • Last active: Oct 03 2011 08:32 PM
  • Joined: 25 Jan 2006

...
Or you can draw icons real time, not to complex.. even histogram


How??? :?:

Carlol
  • Members
  • 163 posts
  • Last active: Aug 03 2010 03:45 AM
  • Joined: 14 Aug 2006
Not to hijack the thread but a related request:

I'm also very fond of Lazlo's script:
#Persistent
SetTimer, CheckCPULoad, 1000
return

CheckCPULoad:
  SetFormat, float, 02
  ControlSetText, Button1, % " " GetCPULoad() [color=red]" %",[/color] ahk_class Shell_TrayWnd
return

GetCPULoad()
{
  Global
  SetBatchLines, -1
  IdleTime0 = %IdleTime%  ; Save previous values
  Tick0 = %Tick%
  DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
  IdleTime := *(&IdleTicks)
  Loop 7                  ; Ticks when Windows was idle
    IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
  Tick := A_TickCount     ; Ticks all together
  load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
  Return, load
}

But my problem is that my start button is not big enough to accomodate the full text, so I've modified the script removing the space in front of the % sign, but when I reach a load of a hundred the % sign "falls" out of the picture, anyway to fix this, smaller font size? Thanks for listening!

CarlosTheTackle
  • Members
  • 102 posts
  • Last active: Jan 29 2007 12:07 PM
  • Joined: 19 Oct 2004
Hi there, just stumbled across this script when looking for a method of monitoring CPU usage, and it looks promising.

However, when running (exactly as posted above), I get this error:

Error: This DllCall requires a prior VarSetCapacity. The program is now unstable and will exit.

Line#
023: SetFormat,float,02
024: ControlSetText,Button1," " GetCPULoad() " %",ahk_class Shell_TrayWnd
025: Return
028: {
030: SetBatchLines,-1
031: IdleTime0 = %IdleTime%
032: Tick0 = %Tick%
---> 033: DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
034: IdleTime := *(&IdleTicks)
035: Loop,7
036: IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
037: Tick := A_TickCount
038: load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
039: Return,load
040: }


Obviously this requires an earlier VarSetCapacity, but what exactly? And why did no one else have this problem. Is it to do with a new version of AHK?

tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
Yes, it's new.

Use VarSetCapacity(IdleTicks,8,0) before the DllCall to allocate 8 bytes initialized with 0 for the variable.

CarlosTheTackle
  • Members
  • 102 posts
  • Last active: Jan 29 2007 12:07 PM
  • Joined: 19 Oct 2004
Hey thanks, tonne. Much obliged.

YMP
  • Members
  • 424 posts
  • Last active: Apr 05 2012 01:18 AM
  • Joined: 23 Dec 2006

smaller font size?

Or larger button size. :wink:
#Persistent 
SetTimer, CheckCPULoad, 1000
ControlMove, Button1,,, 110,, ahk_class Shell_TrayWnd  ; Width = 110
return 


Carlol
  • Members
  • 163 posts
  • Last active: Aug 03 2010 03:45 AM
  • Joined: 14 Aug 2006

Or larger button size. :wink:


YMP you're are regular Einstein, a question of relativity, thank you so much for removing a long time annoyance! :wink:

Veovis
  • Members
  • 389 posts
  • Last active: Mar 17 2009 12:24 AM
  • Joined: 13 Feb 2006

Or you can draw icons real time, not to complex.. even histogram


I am very interested in hearing how excactly one might do this
Posted Image
"Power can be given overnight, but responsibility must be taught. Long years go into its making."

YMP
  • Members
  • 424 posts
  • Last active: Apr 05 2012 01:18 AM
  • Joined: 23 Dec 2006
@Carlol
Well, but it's turned out to be not quite so simple. The taskbar seems to update itself from time to time, in response to some events, and the button's size is brought back to its defaults. So it may be better to insert the resizing command into the timer's code to make it execute periodically. It may also make sense to shift the button to the left to partially compensate its larger size.
CheckCPULoad:
  ControlMove, Button1, -7,, 110,, ahk_class Shell_TrayWnd 
  SetFormat, float, 02
  ControlSetText, Button1, % " " GetCPULoad() " %", ahk_class Shell_TrayWnd 
return 


Carlol
  • Members
  • 163 posts
  • Last active: Aug 03 2010 03:45 AM
  • Joined: 14 Aug 2006
@YMP
Funny you should come in this very moment, I've was just trying to solve this problem by placing:
ControlMove, Button1,,, 110,, ahk_class Shell_TrayWnd  ; Width = 110
In different places in the script, but to no avail, now I will look into your new ideas...Thanks! 8)