Code: Select all
CPULoad() { ; By SKAN, CD:22-Apr-2014 / MD:05-May-2014. Thanks to ejor, Codeproject: http://goo.gl/epYnkO
Static PIT, PKT, PUT ; http://ahkscript.org/boards/viewtopic.php?p=17166#p17166
IfEqual, PIT,, Return 0, DllCall( "GetSystemTimes", "Int64P",PIT, "Int64P",PKT, "Int64P",PUT )
DllCall( "GetSystemTimes", "Int64P",CIT, "Int64P",CKT, "Int64P",CUT )
, IdleTime := PIT - CIT, KernelTime := PKT - CKT, UserTime := PUT - CUT
, SystemTime := KernelTime + UserTime
Return ( ( SystemTime - IdleTime ) * 100 ) // SystemTime, PIT := CIT, PKT := CKT, PUT := CUT
}
Code: Select all
Loop {
Tooltip % CPULoad()
Sleep 250
}
The following samples are extremely light on CPU and takes several hours ( 6 - 12 ) to consume one second of CPU Time.
Sample #1 - High-Resolution plotting
Will plot CPU usage for trivial things like mouse movement.
- MKV in Windows Media Player ( Peace / Loading / Running / Paused / Resumed / Closing / Peace )
Processor in peace.
Code: Select all
#NoEnv
#SingleInstance, Force
ListLines, Off
Process, Priority,, High
OnExit, GuiClose
Gui +AlwaysOnTop +ToolWindow
Gui, Margin, 0, 0
Gui, Add, Text, w610 h111 hwndhGraph
pGraph := XGraph( hGraph, 0x000044, 1, "5,5,5,5", 0x8080FF )
Gui, Show,, CPU Load Monitor - High Resolution ( One minute window )
SetTimer, XGraph_Plot, 100
F1::Msgbox, 0x1040, XGraph, % XGraph_Info( pGraph ) ; // end of auto-execute section //
XGraph_Plot:
CPUL := CPULoad()
XGraph_Plot( pGraph, 100 - CPUL, CPUL )
Return
GuiClose:
pGraph := XGraph_Detach( pGraph )
OnExit
ExitApp
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CPULoad() { ; By SKAN, CD:22-Apr-2014 / MD:05-May-2014. Thanks to ejor, Codeproject: http://goo.gl/epYnkO
Static PIT, PKT, PUT ; http://ahkscript.org/boards/viewtopic.php?p=17166#p17166
IfEqual, PIT,, Return 0, DllCall( "GetSystemTimes", "Int64P",PIT, "Int64P",PKT, "Int64P",PUT )
DllCall( "GetSystemTimes", "Int64P",CIT, "Int64P",CKT, "Int64P",CUT )
, IdleTime := PIT - CIT, KernelTime := PKT - CKT, UserTime := PUT - CUT
, SystemTime := KernelTime + UserTime
Return ( ( SystemTime - IdleTime ) * 100 ) // SystemTime, PIT := CIT, PKT := CKT, PUT := CUT
}
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#Include XGraph.ahk
Clicking on a column reveals the percentage in status bar.
Toggling ALT key will pause/un-pause the timer. ( wasn't aware until today )
- Google Chrome ( Middle click smooth scroll, uses 2 processes in my dual core )
Processor in peace.
Code: Select all
#NoEnv
#SingleInstance, Force
ListLines, Off
OnExit, GuiClose
OnMessage( 0xF, "WM_PAINT")
Gui +AlwaysOnTop
Gui, Margin, 10, 10
Gui, Font, s8, Verdana
Loop, % 11 + ( Y := 15 ) - 15 ; Loop 11 times
Gui, Add, Text, xm y%y% w22 h10 0x200 Right, % 125 - (Y += 10)
ColumnW := 10
hBM := XGraph_MakeGrid( ColumnW, 10, 40, 12, 0x008000, 0, GraphW, GraphH )
Gui, Add, Text, % "xm+25 ym w" ( GraphW + 2 ) " h" ( GraphH + 2 ) " 0x1000" ; SS_SUNKEN := 0x1000
Gui, Add, Text, xp+1 yp+1 w%GraphW% h%GraphH% hwndhGraph gXGraph_GetVal 0xE, pGraph
pGraph := XGraph( hGraph, hBM, ColumnW, "1,10,0,10", 0x00FF00, 1, True )
Gui, Add, StatusBar
SB_SetParts( 100, 150 )
Gui, Show,, CPU Load Monitor ( One minute window )
SetTimer, XGraph_Plot, 1500
GoTo, XGraph_Plot
F1::MsgbOx, 0x1040, XGraph, % XGraph_Info( pGraph ) ; // end of auto-execute section //
F2::MsgbOx, 0x1040, XGraph - Array, % XGraph_Info( pGraph, "0.2" )
XGraph_GetVal:
Value := XGraph_GetVal( pGraph )
If ( Col := ErrorLevel )
SB_SetText( "`tColumn : " Col, 1 ), SB_SetText( "`tValue : " Value, 2 )
Return
XGraph_Paint:
Sleep -1
XGraph_Plot( pGraph )
Return
XGraph_Plot:
CPUL := CPULoad()
XGraph_Plot( pGraph, 100 - CPUL, CPUL )
Return
GuiClose:
OnExit
ExitApp
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
WM_PAINT() {
IfEqual, A_GuiControl, pGraph, SetTimer, XGraph_Paint, -1
}
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CPULoad() { ; By SKAN, CD:22-Apr-2014 / MD:05-May-2014. Thanks to ejor, Codeproject: http://goo.gl/epYnkO
Static PIT, PKT, PUT ; http://ahkscript.org/boards/viewtopic.php?p=17166#p17166
IfEqual, PIT,, Return 0, DllCall( "GetSystemTimes", "Int64P",PIT, "Int64P",PKT, "Int64P",PUT )
DllCall( "GetSystemTimes", "Int64P",CIT, "Int64P",CKT, "Int64P",CUT )
, IdleTime := PIT - CIT, KernelTime := PKT - CKT, UserTime := PUT - CUT
, SystemTime := KernelTime + UserTime
Return ( ( SystemTime - IdleTime ) * 100 ) // SystemTime, PIT := CIT, PKT := CKT, PUT := CUT
}
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#Include xGraph.ahk
Background gradient created with CreateDIB()
- Google Chrome ( Middle click smooth scroll, uses 2 processes in my dual core )
Processor in peace.
Code: Select all
#SingleInstance, Force
#Include xGraph.ahk
SetWorkingDir %A_ScriptDir%
OnExit, GuiClose
OnMessage( 0xF, "WM_PAINT")
Gui +AlwaysOnTop
Gui, Margin, 10, 10
Gui, Font, s8 c4D7186, Verdana
Loop, % 21 + ( Y := 15 ) - 15 ; Loop 21 times
Gui, Add, Text, xm y%y% w25 h10 0x200 Right, % Abs( 125 - ( Y += 10 ) ) "-"
Gui, Add, Text, xm+25 ym w483 h223 0x1000 ; SS_SUNKEN := 0x1000
Gui, Add, Text, xp+1 yp+1 w481 h221 hwndhGraph, pGraph
hBM := CreateDIB( "E9F5F8|E9F5F8|FFFFFF|FFFFFF|E9F5F8|E9F5F8", 2, 3, 481, 221 )
pGraph := XGraph( hGraph, hBM, 5, "1,10,0,10", 0xAF9977, 1 )
Gui, Show,, CPU Load Monitor ( bi-directional spikes )
SetTimer, XGraph_Plot, 200
GoTo, XGraph_Plot
F1::MsgBox, 0x1040, XGraph, % XGraph_Info( pGraph ) ; // end of auto-execute section //
XGraph_Plot:
CPUL := CPULoad()
XGraph_Plot( pGraph, 100 + CPUL, "", False )
XGraph_Plot( pGraph, 100 - CPUL, "", True )
Return
GuiClose:
OnExit
ExitApp
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CPULoad() { ; By SKAN, CD:22-Apr-2014 / MD:05-May-2014. Thanks to ejor, Codeproject: http://goo.gl/epYnkO
Static PIT, PKT, PUT ; http://ahkscript.org/boards/viewtopic.php?p=17166#p17166
IfEqual, PIT,, Return 0, DllCall( "GetSystemTimes", "Int64P",PIT, "Int64P",PKT, "Int64P",PUT )
DllCall( "GetSystemTimes", "Int64P",CIT, "Int64P",CKT, "Int64P",CUT )
, IdleTime := PIT - CIT, KernelTime := PKT - CKT, UserTime := PUT - CUT
, SystemTime := KernelTime + UserTime
Return ( ( SystemTime - IdleTime ) * 100 ) // SystemTime, PIT := CIT, PKT := CKT, PUT := CUT
}
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CreateDIB( PixelData, W, H, ResizeW := 0, ResizeH := 0, Gradient := 1 ) {
; http://ahkscript.org/boards/viewtopic.php?t=3203 SKAN, CD: 01-Apr-2014 MD: 05-May-2014
Static LR_Flag1 := 0x2008 ; LR_CREATEDIBSECTION := 0x2000 | LR_COPYDELETEORG := 8
, LR_Flag2 := 0x200C ; LR_CREATEDIBSECTION := 0x2000 | LR_COPYDELETEORG := 8 | LR_COPYRETURNORG := 4
, LR_Flag3 := 0x0008 ; LR_COPYDELETEORG := 8
WB := Ceil( ( W * 3 ) / 2 ) * 2, VarSetCapacity( BMBITS, WB * H + 1, 0 ), P := &BMBITS
Loop, Parse, PixelData, |
P := Numput( "0x" A_LoopField, P+0, 0, "UInt" ) - ( W & 1 and Mod( A_Index * 3, W * 3 ) = 0 ? 0 : 1 )
hBM := DllCall( "CreateBitmap", "Int",W, "Int",H, "UInt",1, "UInt",24, "Ptr",0, "Ptr" )
hBM := DllCall( "CopyImage", "Ptr",hBM, "UInt",0, "Int",0, "Int",0, "UInt",LR_Flag1, "Ptr" )
DllCall( "SetBitmapBits", "Ptr",hBM, "UInt",WB * H, "Ptr",&BMBITS )
If not ( Gradient + 0 )
hBM := DllCall( "CopyImage", "Ptr",hBM, "UInt",0, "Int",0, "Int",0, "UInt",LR_Flag3, "Ptr" )
Return DllCall( "CopyImage", "Ptr",hBM, "Int",0, "Int",ResizeW, "Int",ResizeH, "Int",LR_Flag2, "UPtr" )
}
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -