Jump to content

Memory Statistics Application


themax90
 Share

Recommended Posts

I have created a real time memory statistics application that updates every 1/5 of a second. There are 3 hotkeys, F1 Shows the program and keeps it ontop, F2 hides it, and Esc exit's it so if u are running it in hide mode and want to just exit hit esc. The code is below.

http://www.autoitscript.com/fileman/users/public/Agent%20Smith/memstat.exe

http://www.autoitscript.com/fileman/users/public/Agent%20Smith/memstat.au3

This is coded in AutoitVersion 3.0.118

HotKeySet("{F1}", "_show")
HotKeySet("{F2}", "_hide")
HotKeySet("{ESC}", "_exit")
Opt ("TrayIconHide", 1)
#include <GuiConstants.au3>
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000
GUICreate("MemStat", 300, 140, (@DesktopWidth - 299) / 2, (@DesktopHeight - 192) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$Label_1 = GUICtrlCreateLabel("Memory Statistics:", 100, 10, 90, 20)
$Label_2 = GUICtrlCreateLabel("", 10, 40, 280, 150)
WinSetOnTop("MemStat", "", 1)
GUISetState()
While 1
   $msg = GUIGetMsg()
   $mem = MemGetStats()
   $file = "Mem"
   FileOpen($file, 2)
   FileWriteLine($file, "Memory Load (Percentage of memory currently in use): " & $mem[0] & "%")
   FileWriteLine($file, "Total Physical RAM: " & $mem[1] & " Kilobytes" & @CRLF)
   FileWriteLine($file, "Available Physical RAM: " & $mem[2] & " Kilobytes" & @CRLF)
   FileWriteLine($file, "Total Pagefile: " & $mem[3] & " Kilobytes" & @CRLF)
   FileWriteLine($file, "Available Pagefile: " & $mem[4] & " Kilobytes" & @CRLF)
   FileWriteLine($file, "Total virtual: " & $mem[5] & " Kilobytes" & @CRLF)
   FileWriteLine($file, "Available virtual: " & $mem[6] & " Kilobytes" & @CRLF)
   FileClose($file)
   $chars = FileRead($file, 300000)
   GUICtrlSetData($Label_2, "" & $chars)
   Sleep(20)
   FileDelete($file)
   If $msg = $GUI_EVENT_CLOSE Then
      Call(_exit())
   EndIf
Wend
Func _hide()
   WinSetOnTop("MemStat", "", 0)
   WinSetState("MemStat", "", @SW_HIDE)
EndFunc ;==>_hide
Func _show()
   WinSetState("MemStat", "", @SW_SHOW)
   WinSetOnTop("MemStat", "", 1)
EndFunc ;==>_show
Func _exit()
   FileDelete($file)
   Exit
EndFunc ;==>_exit

Hope you all like it!

Edited by Agent Smith
Link to comment
Share on other sites

You can use this code also instead of writing and reading a file everytime

$mem = MemGetStats()
  $mem[0] = "Memory Load (% of memory currently in use): " & $mem[0] & "%" & @CRLF
  $mem[1] = "Total Physical RAM: " & $mem[1] & " Kilobytes" & @CRLF
  $mem[2] = "Available Physical RAM: " & $mem[2] & " Kilobytes" & @CRLF
  $mem[3] = "Total Pagefile: " & $mem[3] & " Kilobytes" & @CRLF
  $mem[4] = "Available Pagefile: " & $mem[4] & " Kilobytes" & @CRLF
  $mem[5] = "Total virtual: " & $mem[5] & " Kilobytes" & @CRLF
  $mem[6] =  "Available virtual: " & $mem[6] & " Kilobytes" & @CRLF
  GUICtrlSetData($Label_2, "" & $mem[0] & $mem[1] & $mem[2] & _
                                $mem[3] & $mem[4] & $mem[5])

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

Because it was easier. If you were to write a string using the variable arrays it would take awhile to update. It's faster this way, write all the stuff and update in a clean fashion. With only a 1/5 second delay.

Implementing others code is something I dont normally do, I have tested it and it's more of a secure way of operating with the file, that way a memory breach or anti virus program wont close the program for accessing the memory. Tested with many antivirus and firewall programs it is better for notepad to access this information then read it to the label instead of a direct access. But none the less, if you want a secondary version here it is:

HotKeySet("{F1}", "_show")
HotKeySet("{F2}", "_hide")
HotKeySet("{ESC}", "_exit")
Opt ("TrayIconHide", 1)
#include <GuiConstants.au3>
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000
GUICreate("MemStat", 300, 140, (@DesktopWidth - 299) / 2, (@DesktopHeight - 192) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$Label_1 = GUICtrlCreateLabel("Memory Statistics:", 100, 10, 90, 20)
$Label_2 = GUICtrlCreateLabel("", 10, 40, 280, 150)
WinSetOnTop("MemStat", "", 1)
GUISetState()
While 1
   $msg = GUIGetMsg()
   $mem = MemGetStats()
   $mem[0] = "Memory Load (% of memory currently in use): " & $mem[0] & "%" & @CRLF
   $mem[1] = "Total Physical RAM: " & $mem[1] & " Kilobytes" & @CRLF
   $mem[2] = "Available Physical RAM: " & $mem[2] & " Kilobytes" & @CRLF
   $mem[3] = "Total Pagefile: " & $mem[3] & " Kilobytes" & @CRLF
   $mem[4] = "Available Pagefile: " & $mem[4] & " Kilobytes" & @CRLF
   $mem[5] = "Total virtual: " & $mem[5] & " Kilobytes" & @CRLF
   $mem[6] = "Available virtual: " & $mem[6] & " Kilobytes" & @CRLF
   GUICtrlSetData($Label_2, "" & $mem[0] & $mem[1] & $mem[2] & $mem[3] & $mem[4] & $mem[5] & $mem[6])
   If $msg = $GUI_EVENT_CLOSE Then
      Call(_exit())
   EndIf
Wend
Func _hide()
   WinSetOnTop("MemStat", "", 0)
   WinSetState("MemStat", "", @SW_HIDE)
EndFunc;==>_hide
Func _show()
   WinSetState("MemStat", "", @SW_SHOW)
   WinSetOnTop("MemStat", "", 1)
EndFunc;==>_show
Func _exit()
   Exit
EndFunc;==>_exit

I just warn you that if the program errors in any way and there is a memory malfunction, your computer screws up big time untill you restart it.

Edited by Agent Smith
Link to comment
Share on other sites

Because it was easier. If you were to write a string using the variable arrays it would take awhile to update. It's faster this way, write all the stuff and update in a clean fashion. With only a 1/5 second delay.

Are you crazy? Put some timerInit and TimerDiff in there and check yourself. It takes LONGER to get the memory, write it to a file then read the file, and after that update the label, than it does to get the memory and update the label.

Link to comment
Share on other sites

I think it takes less time to update the arrays that it does to write it to a file and read it back into the program. Both ways used the same cpu usage on my computer. Maybe one of the developers could tell us which is actually faster. I couldn't tell a difference between either way. :idiot:

As far as your guidelines on implementing someone else's code, any code you see me post on this forum is free and clear of any guidelines on my part. I'm just here as part of the community to help.

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

If writing to a file and reading it back in is faster, then something is seriously wrong in the script thats causing a bottleneck and it is not the array (Unless arrays are bugged, in which case, that should of been found long ago). In memory operations will always be faster than any operation that involves disk access.

Link to comment
Share on other sites

I guess on my custom computer it's faster, and it could cause malfunctions because you are rewriting the array to a string. If a program calls on that string and it calls the autoit program using the string instead of the actual stuff then it malfunctions.

Edited by Agent Smith
Link to comment
Share on other sites

Ok please no bickering I will accept the secondary code without protest.

http://www.autoitscript.com/fileman/users/public/Agent%20Smith/MemStat%20%7E%20Original.au33 is mine

http://www.autoitscript.com/fileman/users/public/Agent%20Smith/MemStat.exe is the updated one

http://www.autoitscript.com/fileman/users/public/Agent%20Smith/MemStat.au3 is the updated source

Edited by Agent Smith
Link to comment
Share on other sites

Not to "bicker" but can you tell me what you get for this.

$start = TimerInit()
$mem = MemGetStats()
$file = "Mem"
FileOpen($file, 2)
FileWriteLine($file, "Memory Load (Percentage of memory currently in use): " & $mem[0] & "%")
FileWriteLine($file, "Total Physical RAM: " & $mem[1] & " Kilobytes" & @CRLF)
FileWriteLine($file, "Available Physical RAM: " & $mem[2] & " Kilobytes" & @CRLF)
FileWriteLine($file, "Total Pagefile: " & $mem[3] & " Kilobytes" & @CRLF)
FileWriteLine($file, "Available Pagefile: " & $mem[4] & " Kilobytes" & @CRLF)
FileWriteLine($file, "Total virtual: " & $mem[5] & " Kilobytes" & @CRLF)
FileWriteLine($file, "Available virtual: " & $mem[6] & " Kilobytes" & @CRLF)
FileClose($file)
$chars = FileRead($file, 300000)
MsgBox(0, "Prompt", "It took " & TimerDiff($start) / 1000 & " seconds to complete the task")
FileDelete($file)

$start = TimerInit()
$mem = MemGetStats()
$mem[0] = "Memory Load (% of memory currently in use): " & $mem[0] & "%" & @CRLF
$mem[1] = "Total Physical RAM: " & $mem[1] & " Kilobytes" & @CRLF
$mem[2] = "Available Physical RAM: " & $mem[2] & " Kilobytes" & @CRLF
$mem[3] = "Total Pagefile: " & $mem[3] & " Kilobytes" & @CRLF
$mem[4] = "Available Pagefile: " & $mem[4] & " Kilobytes" & @CRLF
$mem[5] = "Total virtual: " & $mem[5] & " Kilobytes" & @CRLF
$mem[6] =  "Available virtual: " & $mem[6] & " Kilobytes" & @CRLF
MsgBox(0, "Prompt", "It took " & TimerDiff($start) / 1000 & " seconds to complete the task")
Link to comment
Share on other sites

I guess on my custom computer it's faster, and it could cause malfunctions because you are rewriting the array to a string. If a program calls on that string and it calls the autoit program using the string instead of the actual stuff then it malfunctions.

<{POST_SNAPBACK}>

Umm... what? Nothing in that is even close to being correct.

No matter what, the sequence of events of doing something all in-memory will be faster than writing it to disk and reading it back into memory.

Then, the string-array comment... I don't even know what to say about it. I don't even understand what you are trying to say. It makes no sense.

Edit: Added quote so there would be no confusion about what I was replying to.

Edited by Valik
Link to comment
Share on other sites

0.0049816..........

Then

0.005823........

Edit:On my computer to create higher effenciency I have it a script that writes values every 0.00001 seconds, then it when an application needs it, it mirrors the value into a file for the application to use, like when I am playing a game. For my computer it would malfunction if the two scripts got confused. Sorry but I forgot not everyone has my little program on it. :idiot:

Edited by Agent Smith
Link to comment
Share on other sites

Ooh, now I see and understand the "rewriting the array to a string" comment now, thanks to killaz219 example.

AgentSmith, nothing is overwriting the array. Only each element is manually being overwritten. However, AutoIt is able to retrieve the old value before setting the new value. Nothing will get corrupt or "malfunction". If something is happening, then something is wrong with your system.

Link to comment
Share on other sites

Ooh, now I see and understand the "rewriting the array to a string" comment now, thanks to killaz219 example.

AgentSmith, nothing is overwriting the array.  Only each element is manually being overwritten.  However, AutoIt is able to retrieve the old value before setting the new value.  Nothing will get corrupt or "malfunction".  If something is happening, then something is wrong with your system.

<{POST_SNAPBACK}>

OK Thats answers my question ... Thanks Valik

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

  • 1 year later...

Speaking of MemStat A.I. Smith, I tried that out too. It is a very good idea. I did modify the presentation presentation a bit to be a little neater and easier to read. Thank you for sharing it with us. The revised code is below.

; F12 Show, F11 Hide, Esc Close
;Written by AutoIt Smith, revised by Gene
#include <GUIConstants.au3>
;#NoTrayIcon
Local $Gui
Local $MemStats
Local $Mem
Local $MemBuffer
Local $Msg
$Gui = GUICreate("MemStat", 350, 150, (@DesktopWidth - 300) / 2, (@DesktopHeight - 140) / 2, 0xCF0000 + 0x10000000 + 0x04000000)
$MemStats = GUICtrlCreateLabel("", 10, 10, 320, 130, $SS_CENTER)
; The font set in the next line must be a fixed pitch font to maintain the format.
GUICtrlSetFont($MemStats, 8, 400, 0, "Lucida Sans Typewriter")
GUISetState()
WinSetState("MemStat", "", @SW_SHOW)
WinSetOnTop("MemStat", "", 1)
$sUnit = " MB"
$iOutLen = 36
$sCaption1 = "Total Physical RAM:"
$sCaption2 = "Available Physical RAM:"
$sCaption3 = "Total Pagefile:"
$sCaption4 = "Available Pagefile:"
$sCaption5 = "Total virtual:"
$sCaption6 = "Available virtual:"
While 1
 $Msg = GUIGetMsg()
 $Mem = MemGetStats()
 $Mem[0] = "Memory Load (% of Memory currently in use): " & $Mem[0] & "%" & @CRLF
 While StringLen(StringFormat ( "%s" & "%.3f",$sCaption1, ($Mem[1]/1000) ) & $sUnit) < $iOutLen
  $sCaption1 = $sCaption1 & "-"
 WEnd
 $Mem[1] = StringFormat ( "%s" & "%.3f",$sCaption1, ($Mem[1]/1000) ) & $sUnit & @CRLF
 While StringLen(StringFormat ( "%s" & "%.3f",$sCaption2, ($Mem[2]/1000) ) & $sUnit) < $iOutLen
  $sCaption2 = $sCaption2 & " "
 WEnd
 $Mem[2] = StringFormat ( "%s" & "%.3f",$sCaption2, ($Mem[2]/1000) ) & $sUnit & @CRLF
 While StringLen(StringFormat ( "%s" & "%.3f",$sCaption3, ($Mem[3]/1000) ) & $sUnit) < $iOutLen
  $sCaption3 = $sCaption3 & "-"
 WEnd
 $Mem[3] = StringFormat ( "%s" & "%.3f",$sCaption3, ($Mem[3]/1000) ) & $sUnit & @CRLF
 While StringLen(StringFormat ( "%s" & "%.3f",$sCaption4, ($Mem[4]/1000) ) & $sUnit) < $iOutLen
  $sCaption4 = $sCaption4 & " "
 WEnd
 $Mem[4] = StringFormat ( "%s" & "%.3f",$sCaption4, ($Mem[4]/1000) ) & $sUnit & @CRLF
 While StringLen(StringFormat ( "%s" & "%.3f",$sCaption5, ($Mem[5]/1000) ) & $sUnit) < $iOutLen
  $sCaption5 = $sCaption5 & "-"
 WEnd
 $Mem[5] = StringFormat ( "%s" & "%.3f",$sCaption5, ($Mem[5]/1000) ) & $sUnit & @CRLF
 While StringLen(StringFormat ( "%s" & "%.3f",$sCaption6, ($Mem[6]/1000) ) & $sUnit) < $iOutLen
  $sCaption6 = $sCaption6 & " "
 WEnd
 $Mem[6] = StringFormat ( "%s" & "%.3f",$sCaption6, ($Mem[6]/1000) ) & $sUnit & @CRLF
 $Mem = $Mem[0] & $Mem[1] & $Mem[2] & $Mem[3] & $Mem[4] & $Mem[5] & $Mem[6]
 Select
  Case $Msg = -3 Or _IsPressed("0D") = 1
   Exit
  Case $MemBuffer <> $Mem
   GUICtrlSetData($MemStats, $Mem)
   $MemBuffer = $Mem
  Case _IsPressed("7B") = 1
   GUISetState(@SW_SHOW, $Gui)
  Case _IsPressed("7A") = 1
   GUISetState(@SW_HIDE, $Gui)
 EndSelect
WEnd
Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
 Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
 If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
 Return 0
EndFunc  ;==>_IsPressed

I have created a real time memory statistics application that updates every 1/5 of a second. There are 3 hotkeys, F1 Shows the program and keeps it ontop, F2 hides it, and Esc exit's it so if u are running it in hide mode and want to just exit hit esc. The code is below.

http://www.autoitscript.com/fileman/users/...ith/memstat.exe

http://www.autoitscript.com/fileman/users/...ith/memstat.au3

This is coded in AutoitVersion 3.0.118

HotKeySet("{F1}", "_show")
HotKeySet("{F2}", "_hide")
HotKeySet("{ESC}", "_exit")
Opt ("TrayIconHide", 1)
#include <GuiConstants.au3>
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000
GUICreate("MemStat", 300, 140, (@DesktopWidth - 299) / 2, (@DesktopHeight - 192) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$Label_1 = GUICtrlCreateLabel("Memory Statistics:", 100, 10, 90, 20)
$Label_2 = GUICtrlCreateLabel("", 10, 40, 280, 150)
WinSetOnTop("MemStat", "", 1)
GUISetState()
While 1
  $msg = GUIGetMsg()
  $mem = MemGetStats()
  $file = "Mem"
  FileOpen($file, 2)
  FileWriteLine($file, "Memory Load (Percentage of memory currently in use): " & $mem[0] & "%")
  FileWriteLine($file, "Total Physical RAM: " & $mem[1] & " Kilobytes" & @CRLF)
  FileWriteLine($file, "Available Physical RAM: " & $mem[2] & " Kilobytes" & @CRLF)
  FileWriteLine($file, "Total Pagefile: " & $mem[3] & " Kilobytes" & @CRLF)
  FileWriteLine($file, "Available Pagefile: " & $mem[4] & " Kilobytes" & @CRLF)
  FileWriteLine($file, "Total virtual: " & $mem[5] & " Kilobytes" & @CRLF)
  FileWriteLine($file, "Available virtual: " & $mem[6] & " Kilobytes" & @CRLF)
  FileClose($file)
  $chars = FileRead($file, 300000)
  GUICtrlSetData($Label_2, "" & $chars)
  Sleep(20)
  FileDelete($file)
  If $msg = $GUI_EVENT_CLOSE Then
     Call(_exit())
  EndIf
Wend
Func _hide()
  WinSetOnTop("MemStat", "", 0)
  WinSetState("MemStat", "", @SW_HIDE)
EndFunc;==>_hide
Func _show()
  WinSetState("MemStat", "", @SW_SHOW)
  WinSetOnTop("MemStat", "", 1)
EndFunc;==>_show
Func _exit()
  FileDelete($file)
  Exit
EndFunc;==>_exit

Hope you all like it!

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...