Jump to content

Stat Viewer


Recommended Posts

Hello,

I am creating a script to read stats from a forum, but it seems I made some sort of memory leak instead.

As it each 10 seconds collects information from the forum (http://www.hardstylersunited.dk) the memory usage just keeps raising.

My best bet is that it's because I used Adlib to loop a function.

Any ideas to prevent this memory leak?

#Region ### INCLUDE ###
#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#EndRegion ### INCLUDE ###


; Check for Settings.ini
If Not FileExists("settings.ini") Then
; Create Settings.ini
    IniWrite("settings.ini", "Settings", "update_rate", "10")
    IniWrite("settings.ini", "Settings", "log", "0")
EndIf

#Region ### GUI ###
$hu_stats = GUICreate("HU Stat Viewer", 302, 205, 241, 122)
$user_group = GUICtrlCreateGroup("Bruger stats", 0, 0, 301, 116, -1, $WS_EX_TRANSPARENT)
$users_total = GUICtrlCreateLabel("Antal tilmeldte brugere på HU:", 10, 20, 151, 17, $SS_RIGHT)
$users_online = GUICtrlCreateLabel("Antal brugere online:", 10, 40, 151, 15, $SS_RIGHT)
$users_most_online = GUICtrlCreateLabel("Flest brugere online:", 10, 90, 151, 17, $SS_RIGHT)
$users_online_users = GUICtrlCreateLabel("Brugere:", 115, 55, 46, 15, $SS_RIGHT)
$users_online_guests = GUICtrlCreateLabel("Gæster:", 115, 70, 46, 15, $SS_RIGHT)
$users_mark1 = GUICtrlCreateLabel("»", 105, 53, 10, 15)
$users_mark2 = GUICtrlCreateLabel("»", 105, 68, 10, 15)
$users_total_stat = GUICtrlCreateLabel("...henter...", 165, 20, 131, 17, $SS_CENTER)
$users_online_stat = GUICtrlCreateLabel("...henter...", 165, 40, 131, 15, $SS_CENTER)
$users_online_users_stat = GUICtrlCreateLabel("...henter...", 165, 55, 131, 15, $SS_CENTER)
$users_online_guests_stat = GUICtrlCreateLabel("...henter...", 165, 70, 131, 15, $SS_CENTER)
$users_most_online_stat = GUICtrlCreateLabel("...henter...", 165, 90, 131, 17, $SS_CENTER)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$stats_group = GUICtrlCreateGroup("Andre stats", 0, 115, 301, 66, -1, $WS_EX_TRANSPARENT)
$stats_response = GUICtrlCreateLabel("Antal indlæg på HU:", 10, 135, 151, 17, $SS_RIGHT)
$stats_response_stat = GUICtrlCreateLabel("...henter...", 165, 135, 131, 17, $SS_CENTER)
$stats_topic = GUICtrlCreateLabel("Antal emner på HU:", 10, 155, 151, 17, $SS_RIGHT)
$stats_topic_stat = GUICtrlCreateLabel("...henter...", 165, 155, 131, 17, $SS_CENTER)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$update = GUICtrlCreateLabel("Sidst opdateret: ##:##:##", 0, 186, 301, 15, $SS_CENTER)
GUISetState(@SW_SHOW)
#EndRegion ### GUI ###

; Get update rate from Settings.ini
$update_rate = IniRead("settings.ini", "Settings", "update_rate", "10")

; Open IE connection
$oIE = _IECreate("http://www.hardstylersunited.dk/", 0, 0, 1)
; Read HTML from IE connection
$html = _IEBodyReadHTML($oIE)

; Read HTML to strings
$Members = StringRegExp($html, "(?i)Tilmeldte brugere <strong>(.*?)</strong>", 1)
$Res = StringRegExp($html, "(?i)Indlæg <strong>(.*?)</strong>", 1)
$topics = StringRegExp($html, "(?i)Emner <strong>(.*?)</strong>", 1)
$online = StringRegExp($html, "(?i)Der er <strong>(.*?)</strong> brugere online", 1)
$users = StringRegExp($html, "(?i): (.*?) tilmeldte", 1)
$guests = StringRegExp($html, "(?i)og (.*?) gæst", 1)
$most = StringRegExp($html, "(?i)Flest brugere online på samme tid var <strong>(.*?)</strong>", 1)

; Close IE connection
_IEQuit($oIE)

; Set variables to ""
$html = ""
$oIE = ""

; Update GUI labels
GUICtrlSetData($users_total_stat, $Members[0])
GUICtrlSetData($stats_response_stat, $Res[0])
GUICtrlSetData($stats_topic_stat, $topics[0])
GUICtrlSetData($users_online_stat, $online[0])
GUICtrlSetData($users_online_users_stat, $users[0])
GUICtrlSetData($users_online_guests_stat, $guests[0])
GUICtrlSetData($users_most_online_stat, $most[0])

; Set last-update time
GUICtrlSetData($update, "Sidst opdateret: " & @HOUR & ":" & @MIN & ":" & @SEC)

; Run update each ($update_rate) second
AdlibEnable("Update", $update_rate * 1000)

While 1
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func Update()

; Write updating message
    GUICtrlSetData($update, "...henter...")

; Open IE connection
    $oIE = _IECreate("http://www.hardstylersunited.dk/", 0, 0, 1)
; Read HTML from IE connection
    $html = _IEBodyReadHTML($oIE)

; Read HTML to strings
    $Members = StringRegExp($html, "(?i)Tilmeldte brugere <strong>(.*?)</strong>", 1)
    $Res = StringRegExp($html, "(?i)Indlæg <strong>(.*?)</strong>", 1)
    $topics = StringRegExp($html, "(?i)Emner <strong>(.*?)</strong>", 1)
    $online = StringRegExp($html, "(?i)Der er <strong>(.*?)</strong> brugere online", 1)
    $users = StringRegExp($html, "(?i): (.*?) tilmeldte", 1)
    $guests = StringRegExp($html, "(?i)og (.*?) gæst", 1)
    $most = StringRegExp($html, "(?i)Flest brugere online på samme tid var <strong>(.*?)</strong>", 1)

; Close IE connection
    _IEQuit($oIE)

; Set variables to ""
    $html = ""
    $oIE = ""

; Update GUI labels
    GUICtrlSetData($users_total_stat, $Members[0])
    GUICtrlSetData($stats_response_stat, $Res[0])
    GUICtrlSetData($stats_topic_stat, $topics[0])
    GUICtrlSetData($users_online_stat, $online[0])
    GUICtrlSetData($users_online_users_stat, $users[0])
    GUICtrlSetData($users_online_guests_stat, $guests[0])
    GUICtrlSetData($users_most_online_stat, $most[0])

; Set last-update time
    GUICtrlSetData($update, "Sidst opdateret: " & @HOUR & ":" & @MIN & ":" & @SEC)
    
EndFunc  ;==>Update

Thanks in advance!

// Vossen

EDIT: Updated the script for the newest AutoIt.

Edited by Vossen
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...