Jump to content

TimerDiff() showing odd results


Recommended Posts

Hello all,

I'm new to the forum so please bear with me:

We’ve narrowed a hang in our AutoIt launch code scripts to the timerdiff() function. We've found it responds improperly on a new HP desktop we are testing while in Windows normally versus within Safe Mode or when using a USB device. The test script below should sleep for 5 seconds, then consistently reply with an elapsed time of about 5000; on our newer desktops it sleeps for the 5 seconds but then replies with about 100 elapsed time instead; it responds correctly on all our older model HPs including DC7900s. We’ve found two ways of making it respond normally again on the new model, one is to have a USB device connected the other is to boot up in Safe Mode. Obviously, neither work around can be used in our live environment. We use the timer concept in a bunch of our scripts and need to know what makes TimerInit() and TimerDiff() "tic" (pun intended). We've also tried running it using MSCONFIG, "load basic devices and services only"; same problem. We've read several of the existing forum entries but still have not seen a good description of how the two functions interact with the OS or hardware. Can someone help me understand the two functions and also give me an idea of why hardware might affect them?

$startTime = TimerInit()

Sleep(5000)

$timeElapsed = TimerDiff($startTime)

MsgBox(0, "Elapsed", $timeElapsed)

Link to comment
Share on other sites

Hello all,

I'm new to the forum so please bear with me:

We’ve narrowed a hang in our AutoIt launch code scripts to the timerdiff() function. We've found it responds improperly on a new HP desktop we are testing while in Windows normally versus within Safe Mode or when using a USB device. The test script below should sleep for 5 seconds, then consistently reply with an elapsed time of about 5000; on our newer desktops it sleeps for the 5 seconds but then replies with about 100 elapsed time instead; it responds correctly on all our older model HPs including DC7900s. We’ve found two ways of making it respond normally again on the new model, one is to have a USB device connected the other is to boot up in Safe Mode. Obviously, neither work around can be used in our live environment. We use the timer concept in a bunch of our scripts and need to know what makes TimerInit() and TimerDiff() "tic" (pun intended). We've also tried running it using MSCONFIG, "load basic devices and services only"; same problem. We've read several of the existing forum entries but still have not seen a good description of how the two functions interact with the OS or hardware. Can someone help me understand the two functions and also give me an idea of why hardware might affect them?

$startTime = TimerInit()

Sleep(5000)

$timeElapsed = TimerDiff($startTime)

MsgBox(0, "Elapsed", $timeElapsed)

No idea, but are you running a 64 bit OS?

What do you get for something like this?

$t1 = TimerInit()
$at = _TimerInit()

sleep(5000)
$t2 = TimerInit()
$t3 = timerdiff($t1)
$bt = _TimerDiff($at)

ConsoleWrite("time diff using GetTickCount = " & $bt & @CRLF)
ConsoleWrite("$t1 = " & $t1 & ', ' & "$t3 = " & $t2 & ', difference = ' & $t2 - $t1 & @CRLF)
ConsoleWrite("$t3 = " & $t3 & @CRLF)

Func _TimerInit($from=0)
Local $t = dllcall("kernel32.dll","int","GetTickCount")
return $t[0] - $from
EndFunc

func _TimerDiff($trel)
    Return _TimerInit($trel)
EndFunc

#cs 
results for me
time diff using GetTickCount = 5000
$t1 = 56313608084, $t3 = 56331505356, difference = 17897272
$t3 = 4999.88853331918
#ce
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks for the reply, I'll try your code on Monday when I'm back at work.

We are running WinXP 32bit OS; I tested under SP2 and SP3 with no difference.

The hardware is an HP 6000 Pro.

No idea, but are you running a 64 bit OS?

What do you get for something like this?

$t1 = TimerInit()
$at = _TimerInit()

sleep(5000)
$t2 = TimerInit()
$t3 = timerdiff($t1)
$bt = _TimerDiff($at)

ConsoleWrite("time diff using GetTickCount = " & $bt & @CRLF)
ConsoleWrite("$t1 = " & $t1 & ', ' & "$t3 = " & $t2 & ', difference = ' & $t2 - $t1 & @CRLF)
ConsoleWrite("$t3 = " & $t3 & @CRLF)

Func _TimerInit($from=0)
Local $t = dllcall("kernel32.dll","int","GetTickCount")
return $t[0] - $from
EndFunc

func _TimerDiff($trel)
    Return _TimerInit($trel)
EndFunc

#cs 
results for me
time diff using GetTickCount = 5000
$t1 = 56313608084, $t3 = 56331505356, difference = 17897272
$t3 = 4999.88853331918
#ce

Link to comment
Share on other sites

Thanks for the reply, I'll try your code on Monday when I'm back at work.

We are running WinXP 32bit OS; I tested under SP2 and SP3 with no difference.

The hardware is an HP 6000 Pro.

[/quote

Here are the results I show on the HP 6000 Pro,

we also found that if you tax the CPU the elapsed time goes up:

With a USB device connected:

time diff using GetTickCount = 5000

$t1 = 746179857045, $t3 = 761137930719, difference = 14958073674

$t3 = 4998.47830197191

Without a USB device connected:

time diff using GetTickCount = 5000

$t1 = 860006688831, $t3 = 860483774727, difference = 477085896

$t3 = 159.433724975188

Link to comment
Share on other sites

Interesting. If using GetTickCount is more reliable then the AutoIt Timerdiff function presumably does not use it but maybe should. I think it's worth making a suggestion that the TimerDiff and TimerInit functions should be changed so that they are more reliable. Since you found the problem as far as I am aware, do you want to make the suggestion?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I'm not exactly sure how to make that suggestion (I'm a newbie); however, I did find the TimerInit and TimerDiff author's name from the C++ source code Author's text file, it is Garrett R. Mueller garrett@mailsnare.net but his Email address fails. I wonder if anyone might know how to reach him? I'd like to find out what TimerDiff is really using if it is not using GetTickCount? Also, I tested Windows 7 on the 6000 Pro it does not experience the problem. This points me toward a Microsoft OS thing; I'm going to keep looking. Too bad we are not ready to move to Windows 7 yet; thanks again for any and all ideas.

Link to comment
Share on other sites

I'm fairly certain TimerDiff() users QueryPerformanceCounter. Check out my results calling those functions directly:

$F = DllCall("Kernel32.dll", "Int", "QueryPerformanceFrequency", "int64*", "")

$S = DllCall("Kernel32.dll", "Int", "QueryPerformanceCounter", "int64*", "")

sleep(5000)

$E = DllCall("Kernel32.dll", "Int", "QueryPerformanceCounter", "int64*", "")

; MsgBox(0,"", $E[1] & " " & $S[1] & " " & $F[1] & " " & ($E[1] - $S[1])/$F[1])

ConsoleWrite("Time difference using QueryPerformanceCounter:" & @CRLF & "Start Tick=" & $S[1] & " End Tick=" & $E[1] & " " & " Difference= " & $S[1]-$E[1] & " " & "Frequency=" & $F[1] & @CRLF & "(E-S)/F= " & ($E[1] - $S[1])/$F[1] & " Seconds" & @CRLF)

Results Without USB stick inserted:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Drivers\SharpTimerTest\AutoIt_QueryPerformanceCounter.au3"

Time difference using QueryPerformanceCounter:

Start Tick=5915525973700 End Tick=5916346056550 Difference= -820082850 Frequency=3325030000

(E-S)/F= 0.246639233330226 Seconds

>Exit code: 0 Time: 0.303

Results With USB stick inserted:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Drivers\SharpTimerTest\AutoIt_QueryPerformanceCounter.au3"

Time difference using QueryPerformanceCounter:

Start Tick=6232139910610 End Tick=6248753583120 Difference= -16613672510 Frequency=3325030000

(E-S)/F= 4.99654815445274 Seconds

>Exit code: 0 Time: 5.248

Link to comment
Share on other sites

I found this solution:

The /usepmtimer is a boot.ini switch that seems to take care of the problem.

http://support.microsoft.com/kb/895980

http://support.microsoft.com/kb/833721/en-us

http://blogs.technet.com/perfguru/archive/2008/02/18/explanation-for-the-usepmtimer-switch-in-the-boot-ini.aspx

Link to comment
Share on other sites

Good work SanDiegoGuy. Thanks for letting us know.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I found this solution:

The /usepmtimer is a boot.ini switch that seems to take care of the problem.

http://support.microsoft.com/kb/895980

http://support.microsoft.com/kb/833721/en-us

http://blogs.technet.com/perfguru/archive/2008/02/18/explanation-for-the-usepmtimer-switch-in-the-boot-ini.aspx

Did your new HP PCs have AMD-based motherboards?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 2 weeks later...

FYI: A final follow up on TimerDiff() showing odd results. HP says that it looks like the C4 state is not working correctly on the 6000 Pro (Intel not AMD) and that is what is causing this issue. BIOS for our other previous models does not support C4 state. They also found another work around: disable "Extended Idle Power Management" (default set to Normal) in F10 setup, under OS Power Management tab.

Link to comment
Share on other sites

Hello all,

I'm new to the forum so please bear with me:

We’ve narrowed a hang in our AutoIt launch code scripts to the timerdiff() function. We've found it responds improperly on a new HP desktop we are testing while in Windows normally versus within Safe Mode or when using a USB device. The test script below should sleep for 5 seconds, then consistently reply with an elapsed time of about 5000; on our newer desktops it sleeps for the 5 seconds but then replies with about 100 elapsed time instead; it responds correctly on all our older model HPs including DC7900s. We’ve found two ways of making it respond normally again on the new model, one is to have a USB device connected the other is to boot up in Safe Mode. Obviously, neither work around can be used in our live environment. We use the timer concept in a bunch of our scripts and need to know what makes TimerInit() and TimerDiff() "tic" (pun intended). We've also tried running it using MSCONFIG, "load basic devices and services only"; same problem. We've read several of the existing forum entries but still have not seen a good description of how the two functions interact with the OS or hardware. Can someone help me understand the two functions and also give me an idea of why hardware might affect them?

$startTime = TimerInit()

Sleep(5000)

$timeElapsed = TimerDiff($startTime)

MsgBox(0, "Elapsed", $timeElapsed)

I've been frustrated with the timerinit / timerdiff for a while now. It seems random / unusable. I am currently using Windows 7 64, and previously Vista x64. I don't know if the x64 has anything to do with it, but I had to write my own timer function.

Link to comment
Share on other sites

I've been frustrated with the timerinit / timerdiff for a while now. It seems random / unusable. I am currently using Windows 7 64, and previously Vista x64. I don't know if the x64 has anything to do with it, but I had to write my own timer function.

No it shouldn't, I would guess you have the same problem as SanDiegoGuy. Did you try to disable C4?
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...