Tjalve Posted August 6, 2013 Share Posted August 6, 2013 (edited) Hi everyone. I have a kind of strange problem. Im doing some calucations on harddrive data. And for that ive created a function. This fucntion takes a txt file as input. This textfile containes an IO Trace from a harddrive. An IO trace is basicly a txtfile with a row for every singel IO that the harddrives read/writes to disk. I have timestamps for "start" and "end" of all the IOs, if its a read or a write. What i want, is to get the so called "service time", maximum IO latency, Standard deviation and some other stuff. The problem is that when i run the function in my script i get values thats not right. And theni take the function into a separet script and run it, i get the right values. So my question is. How can the reuslts from the funcrion be diffrent, even if the input and the conditions are the same?? Ive also seen that the reuslts can very depending on what computer i run it on. I do get concistent results though. Evertime i run the same script, i get the same results. Sorry for the shabby code. It was not meant o be "seen" here is my function: expandcollapse popupfunc _analyze_disk($tracefile,$disk) local $array[10] Local $file = FileOpen($tracefile, 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file " & $tracefile) Exit EndIf $tot = 0 $starttime = 0 $endtime = 0 $totaltime = 0 $totalIO = 0 $totalIOtime = 0 $IOover10ms = 0 $IOunder1ms = 0 $maxlatency = 0 $unit_start = 0 $unit_end = 0 $unit_time = 0 While 1 Local $line = FileReadLine($file) If @error = -1 Then $unit_time = $unit_end - $unit_start $totaltime = $totaltime + $unit_time ExitLoop EndIf $data = StringSplit($line,",") if $data[1] = "DISK #" & $disk Then $totalIO = $totalIO + 1 if $starttime = 0 Then $starttime = $data[2] EndIf $tot = $tot + $data[7] $totalIOtime = $totalIOtime + $data[4] if dec(hex($data[4])) > 10000 then $IOover10ms = $IOover10ms +1 if dec(hex($data[4])) < 1000 then $IOunder1ms = $IOunder1ms +1 if dec(hex($data[4])) > dec(hex($maxlatency)) then $maxlatency = $data[4] ;~ time unit if $unit_start = 0 then $unit_start = $data[2] $unit_end = $data[3] Else if dec(hex($data[2])) < dec(hex($unit_end)) Then if dec(hex($data[3])) < dec(hex($unit_end)) Then Else $unit_end = $data[3] EndIf Else $unit_time = $unit_end - $unit_start $unit_start = $data[2] $unit_end = $data[3] $totaltime = $totaltime + $unit_time EndIf EndIf EndIf WEnd FileClose($file) $endtime = $data[3] $meantime = $totalIOtime/$totalIO $deviation = 0 Local $file = FileOpen($tracefile, 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file " & $tracefile) Exit EndIf While 1 Local $line = FileReadLine($file) If @error = -1 Then ExitLoop $data = StringSplit($line,",") if $data[1] = "DISK #" & $disk Then $deviation = $deviation +($data[4] - $meantime)^2 EndIf WEnd $deviation = Sqrt($deviation / $totalIO) FileClose($file) while 1 sleep(200) if FileDelete($tracefile) = 1 then ExitLoop WEnd while 1 sleep(1000) if FileExists($tracefile) = 0 then ExitLoop WEnd $array[0] = ($endtime - $starttime)/1000000 $array[1] = round($totaltime/1000000,6) $array[2] = Round(((($tot*512)/1024)/1024),2) $array[3] = $totalIO $array[4] = Round(((($tot*512)/1024)/1024)/($totaltime/1000000),2) $array[5] = round(($totalIOtime/$totalIO)/1000,2) $array[6] = round(($IOover10ms/$totalIO)*100,2) $array[7] = round(($IOunder1ms/$totalIO)*100,2) $array[8] = round($deviation/1000,2) $array[9] = round($maxlatency/1000,2) return $array EndFunc The files i parse look like this: DISK #1,13019125551353648,13019125551354180,532,Read,69c6d80,256,0,0,2,0 DISK #1,13019125551361075,13019125551361607,532,Read,69c6e80,256,0,0,2,0 DISK #1,13019125551367553,13019125551368085,532,Read,69c6f80,256,0,0,2,0 aso Edited August 7, 2013 by Tjalve Link to comment Share on other sites More sharing options...
willichan Posted August 6, 2013 Share Posted August 6, 2013 Where is the 2nd script? My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
jaberwacky Posted August 6, 2013 Share Posted August 6, 2013 $tempfile, $path2 are undefined in the function. Are these global values or did you happen to forget to declare and assign them locally? If they are global variables, then can you pass them into the func via the parameter list? This will help to make the function easier to debug for any given set of parameters. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Tjalve Posted August 7, 2013 Author Share Posted August 7, 2013 $tempfile, $path2 are undefined in the function. Are these global values or did you happen to forget to declare and assign them locally? If they are global variables, then can you pass them into the func via the parameter list? This will help to make the function easier to debug for any given set of parameters. My bad. Both of theese variables are used in a step befor this step (the one that creates the txt file to begin with.) Iva noe modified the code above to reflect how it should be. Link to comment Share on other sites More sharing options...
jaberwacky Posted August 7, 2013 Share Posted August 7, 2013 (edited) Looking at your func I don't see anything that relies on global values, or random values, anything like that. So, the only thing I can figure is that whatever gets your drive info is not giving consistent results. Edited August 7, 2013 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Tjalve Posted August 7, 2013 Author Share Posted August 7, 2013 Looking at your func I don't see anything that relies on global values, or random values, anything like that. So, the only thing I can figure is that whatever gets your drive info is not giving consistent results. Thats what i cant figure out. I use the same input (same txt file with data) on two diffrent machines. I just dont know why it happends... Btw. Any way to make it more aexcat would also be helpful. Thank you so far. Link to comment Share on other sites More sharing options...
jaberwacky Posted August 7, 2013 Share Posted August 7, 2013 (edited) Ok, identified a possible issue. Look at line #99 in the following code: expandcollapse popup#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d #include <Constants.au3> #include <Array.au3> global $drive_stats = _analyze_disk(@DesktopDir & "\TEST.txt", 1) _ArrayDisplay($drive_stats) func _analyze_disk(const $tracefile, const $disk) local const $file_disk1 = FileOpen($tracefile, 0) If $file_disk1 = -1 Then MsgBox($MB_OK + $MB_ICONERROR, "Error", "Unable to open file " & $tracefile) Exit EndIf local $tot = 0 local $starttime = 0 local $totaltime = 0 local $totalIO = 0 local $totalIOtime = 0 local $IOover10ms = 0 local $IOunder1ms = 0 local $maxlatency = 0 local $unit_start = 0 local $unit_end = 0 local $unit_time = 0 local $line local $data While 1 $line = FileReadLine($file_disk1) If @error = -1 Then $unit_time = $unit_end - $unit_start $totaltime += $unit_time ExitLoop EndIf $data = StringSplit($line, ",") if $data[1] = "DISK #" & $disk Then $totalIO = $totalIO + 1 if $starttime = 0 Then $starttime = $data[2] EndIf $tot = $tot + $data[7] $totalIOtime = $totalIOtime + $data[4] if dec(hex($data[4])) > 10000 then $IOover10ms = $IOover10ms + 1 if dec(hex($data[4])) < 1000 then $IOunder1ms = $IOunder1ms + 1 if dec(hex($data[4])) > dec(hex($maxlatency)) then $maxlatency = $data[4] ; time unit if $unit_start = 0 then $unit_start = $data[2] $unit_end = $data[3] Else if dec(hex($data[2])) < dec(hex($unit_end)) Then if dec(hex($data[3])) >= dec(hex($unit_end)) Then $unit_end = $data[3] EndIf Else $unit_time = $unit_end - $unit_start $unit_start = $data[2] $unit_end = $data[3] $totaltime += $unit_time EndIf EndIf EndIf WEnd FileClose($file_disk1) local $endtime = $data[3] local $meantime = $totalIOtime/$totalIO local $deviation = 0 Local $file_disk0 = FileOpen($tracefile, 0) If $file_disk0 = -1 Then MsgBox($MB_OK + $MB_ICONERROR, "Error", "Unable to open file " & $tracefile) Exit EndIf While 1 $line = FileReadLine($file_disk0) If @error = -1 Then ExitLoop $data = StringSplit($line, ",") if $data[1] = "DISK #" & $disk Then $deviation += ($data[4] - $meantime) ^ 2 EndIf WEnd $deviation = Sqrt($deviation / $totalIO) FileClose($file_disk0) FileDelete($tracefile) local const $stats[10] = [($endtime - $starttime) / 1000000, _ round($totaltime / 1000000, 6), _ round(((($tot * 512) / 1024) / 1024), 2), _ $totalIO, _ round(((($tot * 512) / 1024) / 1024) / ($totaltime / 1000000), 2), _ round(($totalIOtime / $totalIO) / 1000, 2), _ round(($IOover10ms / $totalIO) * 100, 2), _ round(($IOunder1ms / $totalIO) * 100, 2), _ round($deviation / 1000, 2), _ round($maxlatency / 1000, 2)] return $stats EndFunc When you're reading Disk 0 this still says Disk 1 if 1 were the argument passed into the function. Edited August 7, 2013 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now