2012-09-30 17:52:06 +00:00
/*
bug . n - - tiling window management
2015-01-25 12:07:37 +00:00
Copyright ( c ) 2010 - 2015 Joshua Fuhs , joten
2012-12-05 12:39:51 +00:00
2012-09-30 17:52:06 +00:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
2015-01-25 12:07:37 +00:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
2012-09-30 17:52:06 +00:00
GNU General Public License for more details .
2012-12-05 12:39:51 +00:00
2015-01-25 12:07:37 +00:00
@license GNU General Public License version 3
. . / LICENSE . md or < http : / / www . gnu . org / licenses / >
2012-12-05 12:39:51 +00:00
2015-01-25 13:04:17 +00:00
@version 9.0 . 0
2012-09-30 17:52:06 +00:00
* /
2014-03-04 19:53:33 +00:00
ResourceMonitor_init ( ) {
Global Config_readinDiskLoad , Config_readinNetworkLoad , ResourceMonitor_hDrive
If Config_readinDiskLoad
ResourceMonitor_hDrive := DllCall ( " CreateFile " , " Str " , " \\.\PhysicalDrive0 " , " UInt " , 0 , " UInt " , 3 , " UInt " , 0 , " UInt " , 3 , " UInt " , 0 , " UInt " , 0 )
;; This call may lead to bug.n hanging (bug 019005).
If Config_readinNetworkLoad
ResourceMonitor_getNetworkInterface ( )
2012-09-30 19:16:31 +00:00
}
2014-03-04 19:53:33 +00:00
ResourceMonitor_cleanup ( ) {
Global Config_readinDiskLoad , ResourceMonitor_hDrive
If Config_readinDiskLoad
DllCall ( " CloseHandle " , " UInt " , ResourceMonitor_hDrive ) ;; used in ResourceMonitor_getDiskLoad
2012-09-30 19:16:31 +00:00
}
2012-12-05 12:39:51 +00:00
ResourceMonitor_getText ( )
2012-09-30 17:52:06 +00:00
{
2014-10-01 21:20:32 +00:00
Global Config_readinCpu , Config_readinDate , Config_readinDiskLoad , Config_readinMemoryUsage , Config_readinNetworkLoad , Config_readinVolume
2012-12-05 12:39:51 +00:00
2012-09-30 17:52:06 +00:00
text := " "
2014-10-01 21:20:32 +00:00
If Config_readinVolume
{
text .= " VOL: " ResourceMonitor_getSoundVolume ( ) " % "
}
2012-09-30 17:52:06 +00:00
If Config_readinCpu
2014-10-01 21:20:32 +00:00
{
If Config_readinVolume
text .= " | "
2012-09-30 19:16:31 +00:00
text .= " CPU: " ResourceMonitor_getSystemTimes ( ) " % "
2014-10-01 21:20:32 +00:00
}
2012-12-05 12:39:51 +00:00
If Config_readinMemoryUsage
2012-09-30 17:52:06 +00:00
{
2014-10-01 21:20:32 +00:00
If ( Config_readinVolume Or Config_readinCpu )
2012-09-30 17:52:06 +00:00
text .= " | "
2012-09-30 19:16:31 +00:00
text .= " RAM: " ResourceMonitor_getMemoryUsage ( ) " % "
2012-09-30 17:52:06 +00:00
}
2012-12-05 12:39:51 +00:00
If Config_readinDiskLoad
2012-09-30 17:52:06 +00:00
{
2014-10-01 21:20:32 +00:00
If ( Config_readinVolume Or Config_readinCpu Or Config_readinMemoryUsage )
2012-09-30 17:52:06 +00:00
text .= " | "
2012-09-30 19:16:31 +00:00
ResourceMonitor_getDiskLoad ( rLoad , wLoad )
2012-09-30 17:52:06 +00:00
text .= " Dr: " rLoad " % | Dw: " wLoad " % "
}
2012-12-05 12:39:51 +00:00
If Config_readinNetworkLoad
2012-09-30 17:52:06 +00:00
{
2014-10-01 21:20:32 +00:00
If ( Config_readinVolume Or Config_readinCpu Or Config_readinMemoryUsage Or Config_readinDiskLoad )
2012-09-30 17:52:06 +00:00
text .= " | "
2012-09-30 19:16:31 +00:00
ResourceMonitor_getNetworkLoad ( upLoad , dnLoad )
2012-09-30 17:52:06 +00:00
text .= " UP: " upLoad " KB/s | dn: " dnLoad " KB/s "
}
2014-10-01 21:20:32 +00:00
If Config_readinDate And ( Config_readinVolume Or Config_readinCpu Or Config_readinMemoryUsage Or Config_readinDiskLoad Or Config_readinNetworkLoad )
2012-09-30 17:52:06 +00:00
text .= " | "
2012-12-05 12:39:51 +00:00
2012-09-30 17:52:06 +00:00
Return , text
}
2012-09-30 19:16:31 +00:00
2012-12-05 12:39:51 +00:00
ResourceMonitor_getDiskLoad ( ByRef readLoad , ByRef writeLoad )
2012-09-30 19:16:31 +00:00
{
Global ResourceMonitor_hDrive
Static oldReadCount , oldWriteCount
2012-12-05 12:39:51 +00:00
2012-09-30 19:16:31 +00:00
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
2012-12-05 12:39:51 +00:00
2012-09-30 19:16:31 +00:00
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)
2012-12-05 12:39:51 +00:00
ResourceMonitor_getMemoryUsage ( )
2012-09-30 19:16:31 +00:00
{
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)
2014-03-04 19:53:33 +00:00
ResourceMonitor_getNetworkInterface ( ) {
Global Config_readinNetworkLoad , ResourceMonitor_networkInterface
2012-12-05 12:39:51 +00:00
2014-03-04 19:53:33 +00:00
objWMIService := ComObjGet ( " winmgmts:{impersonationLevel=impersonate}!\\ " . A_ComputerName . " \root\cimv2 " )
WQLQuery := " SELECT * FROM Win32_PerfFormattedData_Tcpip_NetworkInterface WHERE Name LIKE '% " . Config_readinNetworkLoad . " %' "
ResourceMonitor_networkInterface := objWMIService . ExecQuery ( WQLQuery ) . ItemIndex ( 0 )
2012-09-30 19:16:31 +00:00
}
2014-03-04 19:53:33 +00:00
;; Pillus: System monitor (HDD/Wired/Wireless) using keyboard LEDs (http://www.autohotkey.com/board/topic/65308-system-monitor-hddwiredwireless-using-keyboard-leds/)
2012-09-30 19:16:31 +00:00
2012-12-05 12:39:51 +00:00
ResourceMonitor_getNetworkLoad ( ByRef upLoad , ByRef dnLoad )
2012-09-30 19:16:31 +00:00
{
2014-03-04 19:53:33 +00:00
Global ResourceMonitor_networkInterface
2012-12-05 12:39:51 +00:00
2014-03-04 19:53:33 +00:00
ResourceMonitor_networkInterface . Refresh_
dnLoad := SubStr ( " " Round ( ResourceMonitor_networkInterface . BytesReceivedPerSec / 1024 ) , - 3 )
upLoad := SubStr ( " " Round ( ResourceMonitor_networkInterface . BytesSentPerSec / 1024 ) , - 3 )
2012-09-30 19:16:31 +00:00
}
2014-03-04 19:53:33 +00:00
;; Pillus: System monitor (HDD/Wired/Wireless) using keyboard LEDs (http://www.autohotkey.com/board/topic/65308-system-monitor-hddwiredwireless-using-keyboard-leds/)
2012-09-30 19:16:31 +00:00
2014-10-01 21:20:32 +00:00
ResourceMonitor_getSoundVolume ( ) {
SoundGet , volume , MASTER , VOLUME
SoundGet , mute , MASTER , MUTE
text := " "
If mute = On
text .= " m "
Else
text .= " "
text .= SubStr ( " " Round ( volume ) , - 2 )
Return , text
}
2012-12-05 12:39:51 +00:00
ResourceMonitor_getSystemTimes ( )
2012-09-30 19:16:31 +00:00
{ ;; 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)