Sign in to follow this  
Followers 0
Tjalve

Identical function with identical input, give diffrent output?

7 posts in this topic

#1 ·  Posted (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:

func _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 by Tjalve

Share this post


Link to post
Share on other sites



$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.

Share this post


Link to post
Share on other sites

$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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by jaberwocky6669

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Ok, identified a possible issue.  Look at line #99 in the following code:

#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 by jaberwocky6669

Share this post


Link to post
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
Sign in to follow this  
Followers 0