moved the helper functions for the resource monitoring to the analogous library

This commit is contained in:
joten 2012-09-30 21:16:31 +02:00
parent 2c01cb6f8b
commit 8a3f890f3e
3 changed files with 117 additions and 97 deletions

View file

@ -168,9 +168,6 @@ Bar_init(m) {
DllCall("Shell32.dll\SHAppBarMessage", "UInt", (ABM_SETPOS := 0x3) , "UInt", &Bar_appBarData)
; SKAN: Crazy Scripting : Quick Launcher for Portable Apps (http://www.autohotkey.com/forum/topic22398.html)
}
Bar_hDrive := DllCall("CreateFile", "Str", "\\.\PhysicalDrive0", "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 0)
Bar_getNetworkInterface()
}
Bar_initCmdGui() {
@ -406,24 +403,6 @@ Bar_getBatteryStatus(ByRef batteryLifePercent, ByRef acLineStatus) {
}
; PhiLho: AC/Battery status (http://www.autohotkey.com/forum/topic7633.html)
Bar_getDiskLoad(ByRef readLoad, ByRef writeLoad) {
Global Bar_hDrive
Static oldReadCount, oldWriteCount
dpSize := 5 * 8 + 4 + 4 + 4 + 4 + 8 + 4 + 8 * (A_IsUnicode ? 2 : 1) + 12 ; 88?
VarSetCapacity(dp, dpSize)
DllCall("DeviceIoControl", "UInt", Bar_hDrive, "UInt", 0x00070020, "UInt", 0, "UInt", 0, "UInt", &dp, "UInt", dpSize, "UIntP", nReturn, "UInt", 0) ; IOCTL_DISK_PERFORMANCE
newReadCount := NumGet(dp, 40)
newWriteCount := NumGet(dp, 44)
readLoad := SubStr(" " Round((1 - 1 / (1 + newReadCount - oldReadCount)) * 100), -2)
writeLoad := SubStr(" " Round((1 - 1 / (1 + newWriteCount - oldWriteCount)) * 100), -2)
oldReadCount := newReadCount
oldWriteCount := newWriteCount
}
; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329)
; SKAN: HDD Activity Monitoring LED (http://www.autohotkey.com/community/viewtopic.php?p=113890&sid=64d9824fdf252697ff4d5026faba91f8#p113890)
Bar_getHeight() {
Global Bar_#0_#1, Bar_#0_#1H, Bar_#0_#2, Bar_#0_#2H, Bar_ctrlHeight, Bar_height, Bar_textHeight
Global Config_fontName, Config_fontSize, Config_singleRowBar, Config_spaciousBar, Config_verticalBarPos
@ -458,77 +437,6 @@ Bar_getHeight() {
}
}
Bar_getMemoryUsage() {
VarSetCapacity(memoryStatus, 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4)
DllCall("kernel32.dll\GlobalMemoryStatus", "UInt", &memoryStatus)
Return, SubStr(" " Round(*(&memoryStatus + 4)), -2) ; LS byte is enough, 0..100
}
; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329)
Bar_getNetworkInterface() {
Global Bar_networkInterface, Bar_networkInterfaceTable
DllCall("iphlpapi\GetNumberOfInterfaces", "UIntP", n)
nSize := 4 + 860 * n + 8
VarSetCapacity(Bar_networkInterfaceTable, nSize)
If Not DllCall("iphlpapi\GetIfTable", "UInt", &Bar_networkInterfaceTable, "UIntP", nSize, "Int", False) {
Loop, 2 {
i := 0
j := A_Index
Loop, % NumGet(Bar_networkInterfaceTable) {
If NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 544) < 4
|| NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 516) = 24
Continue
i += 1
dn_#%i%_#%j% := NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 552)
up_#%i%_#%j% := NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 576)
}
If (A_Index < 2)
RunWait, %Comspec% /c ping -n 1 127.0.0.1, , hide
}
Loop, % i
If (dn_#%i%_#2 > dn_#%i%_1) {
Bar_networkInterface := i
Break
}
}
}
; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329)
Bar_getNetworkLoad(ByRef upLoad, ByRef dnLoad) {
Global Bar_networkInterface, Bar_networkInterfaceTable
Static dn_#0, t_#0, up_#0
DllCall("iphlpapi\GetIfEntry", "UInt", &Bar_networkInterfaceTable + 4 + 860 * (Bar_networkInterface - 1))
dn_#1 := NumGet(Bar_networkInterfaceTable, 4 + 860 * (Bar_networkInterface - 1) + 552) ; Total Incoming Bytes
up_#1 := NumGet(Bar_networkInterfaceTable, 4 + 860 * (Bar_networkInterface - 1) + 576) ; Total Outgoing Bytes
tDiff := (A_TickCount - t_#0) / 1000
t_#0 := A_TickCount
dnLoad := SubStr(" " Round((dn_#1 - dn_#0) / 1024 / tDiff), -3)
upLoad := SubStr(" " Round((up_#1 - up_#0) / 1024 / tDiff), -3)
dn_#0 := dn_#1
up_#0 := up_#1
}
; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329)
; Sean: Network Download/Upload Meter (http://www.autohotkey.com/community/viewtopic.php?t=18033)
Bar_getSystemTimes() { ; Total CPU Load
Static oldIdleTime, oldKrnlTime, oldUserTime
Static newIdleTime, newKrnlTime, newUserTime
oldIdleTime := newIdleTime
oldKrnlTime := newKrnlTime
oldUserTime := newUserTime
DllCall("GetSystemTimes", "Int64P", newIdleTime, "Int64P", newKrnlTime, "Int64P", newUserTime)
sysTime := SubStr(" " . Round((1 - (newIdleTime - oldIdleTime) / (newKrnlTime - oldKrnlTime+newUserTime - oldUserTime)) * 100), -2)
Return, sysTime ; system time in percent
}
; Sean: CPU LoadTimes (http://www.autohotkey.com/forum/topic18913.html)
Bar_getTextWidth(x, reverse=False) {
Global Config_fontSize

View file

@ -49,6 +49,7 @@ SetWinDelay, 10
Menu, Tray, Add,
Menu, Tray, Add, Exit, Main_quit
ResourceMonitor_init()
Manager_init()
Return ;; end of the auto-execute section
@ -58,7 +59,7 @@ Main_cleanup:
If Config_autoSaveSession
Config_saveSession()
Manager_cleanup()
DllCall("CloseHandle", "UInt", Bar_hDrive) ;; used in Bar_getDiskLoad
ResourceMonitor_cleanup()
Debug_logMessage("Exiting bug.n", 0)
ExitApp

View file

@ -18,31 +18,42 @@
@version 8.3.0
*/
ResourceMonitor_init()
{
ResourceMonitor_hDrive := DllCall("CreateFile", "Str", "\\.\PhysicalDrive0", "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 0)
ResourceMonitor_getNetworkInterface()
}
ResourceMonitor_cleanup()
{
DllCall("CloseHandle", "UInt", ResourceMonitor_hDrive) ;; used in ResourceMonitor_getDiskLoad
}
ResourceMonitor_getText()
{
Global Config_readinCpu, Config_readinDate, Config_readinDiskLoad, Config_readinMemoryUsage, Config_readinNetworkLoad
text := ""
If Config_readinCpu
text .= " CPU: " Bar_getSystemTimes() "% "
text .= " CPU: " ResourceMonitor_getSystemTimes() "% "
If Config_readinMemoryUsage
{
If Config_readinCpu
text .= "|"
text .= " RAM: " Bar_getMemoryUsage() "% "
text .= " RAM: " ResourceMonitor_getMemoryUsage() "% "
}
If Config_readinDiskLoad
{
If (Config_readinCpu Or Config_readinMemoryUsage)
text .= "|"
Bar_getDiskLoad(rLoad, wLoad)
ResourceMonitor_getDiskLoad(rLoad, wLoad)
text .= " Dr: " rLoad "% | Dw: " wLoad "% "
}
If Config_readinNetworkLoad
{
If (Config_readinCpu Or Config_readinMemoryUsage Or Config_readinDiskLoad)
text .= "|"
Bar_getNetworkLoad(upLoad, dnLoad)
ResourceMonitor_getNetworkLoad(upLoad, dnLoad)
text .= " UP: " upLoad " KB/s | dn: " dnLoad " KB/s "
}
If Config_readinDate And (Config_readinCpu Or Config_readinMemoryUsage Or Config_readinDiskLoad Or Config_readinNetworkLoad)
@ -50,3 +61,103 @@ ResourceMonitor_getText()
Return, text
}
ResourceMonitor_getDiskLoad(ByRef readLoad, ByRef writeLoad)
{
Global ResourceMonitor_hDrive
Static oldReadCount, oldWriteCount
dpSize := 5 * 8 + 4 + 4 + 4 + 4 + 8 + 4 + 8 * (A_IsUnicode ? 2 : 1) + 12 ;; 88?
VarSetCapacity(dp, dpSize)
DllCall("DeviceIoControl", "UInt", ResourceMonitor_hDrive, "UInt", 0x00070020, "UInt", 0, "UInt", 0, "UInt", &dp, "UInt", dpSize, "UIntP", nReturn, "UInt", 0) ;; IOCTL_DISK_PERFORMANCE
newReadCount := NumGet(dp, 40)
newWriteCount := NumGet(dp, 44)
readLoad := SubStr(" " Round((1 - 1 / (1 + newReadCount - oldReadCount)) * 100), -2)
writeLoad := SubStr(" " Round((1 - 1 / (1 + newWriteCount - oldWriteCount)) * 100), -2)
oldReadCount := newReadCount
oldWriteCount := newWriteCount
}
;; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329)
;; SKAN: HDD Activity Monitoring LED (http://www.autohotkey.com/community/viewtopic.php?p=113890&sid=64d9824fdf252697ff4d5026faba91f8#p113890)
ResourceMonitor_getMemoryUsage()
{
VarSetCapacity(memoryStatus, 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4)
DllCall("kernel32.dll\GlobalMemoryStatus", "UInt", &memoryStatus)
Return, SubStr(" " Round(*(&memoryStatus + 4)), -2) ;; LS byte is enough, 0..100
}
;; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329)
ResourceMonitor_getNetworkInterface()
{
Global ResourceMonitor_networkInterface, ResourceMonitor_networkInterfaceTable
DllCall("iphlpapi\GetNumberOfInterfaces", "UIntP", n)
nSize := 4 + 860 * n + 8
VarSetCapacity(ResourceMonitor_networkInterfaceTable, nSize)
If Not DllCall("iphlpapi\GetIfTable", "UInt", &ResourceMonitor_networkInterfaceTable, "UIntP", nSize, "Int", False)
{
Loop, 2
{
i := 0
j := A_Index
Loop, % NumGet(ResourceMonitor_networkInterfaceTable)
{
If NumGet(ResourceMonitor_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 544) < 4
|| NumGet(ResourceMonitor_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 516) = 24
Continue
i += 1
dn_#%i%_#%j% := NumGet(ResourceMonitor_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 552)
up_#%i%_#%j% := NumGet(ResourceMonitor_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 576)
}
If (A_Index < 2)
RunWait, %Comspec% /c ping -n 1 127.0.0.1, , hide
}
Loop, % i
{
If (dn_#%i%_#2 > dn_#%i%_1)
{
ResourceMonitor_networkInterface := i
Break
}
}
}
}
;; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329)
ResourceMonitor_getNetworkLoad(ByRef upLoad, ByRef dnLoad)
{
Global ResourceMonitor_networkInterface, ResourceMonitor_networkInterfaceTable
Static dn_#0, t_#0, up_#0
DllCall("iphlpapi\GetIfEntry", "UInt", &ResourceMonitor_networkInterfaceTable + 4 + 860 * (ResourceMonitor_networkInterface - 1))
dn_#1 := NumGet(ResourceMonitor_networkInterfaceTable, 4 + 860 * (ResourceMonitor_networkInterface - 1) + 552) ;; Total Incoming Bytes
up_#1 := NumGet(ResourceMonitor_networkInterfaceTable, 4 + 860 * (ResourceMonitor_networkInterface - 1) + 576) ;; Total Outgoing Bytes
tDiff := (A_TickCount - t_#0) / 1000
t_#0 := A_TickCount
dnLoad := SubStr(" " Round((dn_#1 - dn_#0) / 1024 / tDiff), -3)
upLoad := SubStr(" " Round((up_#1 - up_#0) / 1024 / tDiff), -3)
dn_#0 := dn_#1
up_#0 := up_#1
}
;; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329)
;; Sean: Network Download/Upload Meter (http://www.autohotkey.com/community/viewtopic.php?t=18033)
ResourceMonitor_getSystemTimes()
{ ;; Total CPU Load
Static oldIdleTime, oldKrnlTime, oldUserTime
Static newIdleTime, newKrnlTime, newUserTime
oldIdleTime := newIdleTime
oldKrnlTime := newKrnlTime
oldUserTime := newUserTime
DllCall("GetSystemTimes", "Int64P", newIdleTime, "Int64P", newKrnlTime, "Int64P", newUserTime)
sysTime := SubStr(" " . Round((1 - (newIdleTime - oldIdleTime) / (newKrnlTime - oldKrnlTime+newUserTime - oldUserTime)) * 100), -2)
Return, sysTime ;; system time in percent
}
;; Sean: CPU LoadTimes (http://www.autohotkey.com/forum/topic18913.html)