[UDF] Debug-Timer

  • Guten Abend zusammen,

    aus aktuellem Anlass habe ich eine winzig kleine UDF geschrieben, welche es sehr einfach ermöglicht einen Timer zum Debuggen zu erstellen. Seht selbst:

    _debugTimer.au3

    Spoiler anzeigen
    [autoit]


    #include-once
    $timer = False

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _StartDebugTimer
    ; Description ...: Starts the timer. Necessary for all upcomming functions.
    ; Syntax ........: _StartDebugTimer([$consoleoutput = False])
    ; Parameters ....: $consoleoutput - [optional] Defines the output in the console with the time as suffix. Default is no output.
    ; Return values .: Success: True; Failure: False
    ; Author ........: ErrorKid @ autoit.de
    ; Modified ......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: Yes. See DebugTimerDemo.au3
    ; ===============================================================================================================================
    Func _StartDebugTimer($consoleoutput = False)
    If $timer = False Then
    Global $timer = TimerInit()
    Global $lastcheckpoint = 0
    If $consoleoutput Then
    ConsoleWrite($consoleoutput & @CRLF)
    EndIf
    Return True
    Else
    ConsoleWrite("_debugTimer-Error: Timer already started. Stop it with _EndDebugTimer()" & @CRLF)
    Return False
    EndIf
    EndFunc ;==>_StartDebugTimer

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _DisplayCurrentTime
    ; Description ...: Displays the current time from the beginning of _StartDebugTimer() or from the last call from _DisplayCurrentTime() which had the value $fromlascheckpoint = True
    ; Syntax ........: _DisplayCurrentTime([$consoleoutput = False[, $fromlascheckpoint = False]])
    ; Parameters ....: $consoleoutput - [optional] Defines the output in the console with the time as suffix. Default is no output.
    ; $fromlascheckpoint - [optional] True = Returns/prints the time from the last call from _DisplayCurrentTime() which had the value $fromlascheckpoint = True. Default is the time from the beginning of _StartDebugTimer()
    ; Return values .: Success: The time what would be print if $consoleoutput <> False (see parameters); Failure: False
    ; Author ........: ErrorKid @ autoit.de
    ; Modified ......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: Yes. See DebugTimerDemo.au3
    ; ===============================================================================================================================
    Func _DisplayCurrentTime($consoleoutput = False, $fromlascheckpoint = False)
    If $timer <> False Then
    $time = TimerDiff($timer)
    If $fromlascheckpoint Then
    $time = $time - $lastcheckpoint
    $lastcheckpoint = $time
    EndIf
    If $consoleoutput Then
    ConsoleWrite($consoleoutput & $time & @CRLF)
    EndIf
    Return $time
    Else
    ConsoleWrite("_debugTimer-Error: Timer isn't started. Start it with _StartDebugTimer()" & @CRLF)
    Return False
    EndIf
    EndFunc ;==>_DisplayCurrentTime

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _EndDebugTimer
    ; Description ...: Closes the Timer. Works only after the call from _StartDebugTimer()
    ; Syntax ........: _EndDebugTimer([$consoleoutput = False])
    ; Parameters ....: $consoleoutput - [optional] Defines the output in the console with the time as suffix. Default is no output.
    ; Return values .: Success: True; Failure: False
    ; Author ........: ErrorKid @ autoit.de
    ; Modified ......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: Yes. See DebugTimerDemo.au3
    ; ===============================================================================================================================
    Func _EndDebugTimer($consoleoutput = False)
    $time = TimerDiff($timer)
    If $timer <> False Then
    Global $timer = False
    If $consoleoutput Then
    ConsoleWrite($consoleoutput & $time & @CRLF)
    EndIf
    Return True
    Else
    ConsoleWrite("_debugTimer-Error: Timer isn't started. Start it with _StartDebugTimer()" & @CRLF)
    Return False
    EndIf
    EndFunc ;==>_EndDebugTimer

    [/autoit]

    DebugTimerDemo.au3

    Spoiler anzeigen
    [autoit]


    #include <_debugTimer.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    _StartDebugTimer("Starting debugtimer!")

    [/autoit] [autoit][/autoit] [autoit]

    Local $msg
    _DisplayCurrentTime("Createt $msg, took: ", True)

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("My GUI")
    _DisplayCurrentTime("GuiCreate() took: ", True)
    GUISetState(@SW_SHOW)
    _DisplayCurrentTime("GUISetState() took: ", True)
    _EndDebugTimer()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()

    [/autoit] [autoit][/autoit] [autoit]

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    _StartDebugTimer()
    GUIDelete()
    _DisplayCurrentTime("GUIDelete() took: ", True)

    [/autoit]

    Es sollte eigentlich recht selbsterklärend sein. Habe versucht die Funktionen so genau wie möglich zu beschreiben. Falls es aber Probleme gibt kann ich gerne Helfen bzw. noch den Beispieltext kommentieren!

    Grüße ErrorKid