Intro Download and install Frequently Asked Questions Tips and tricks

Homepage







© J.C. Kessels 2009
MyDefrag Forum
April 24, 2014, 06:52:59 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: AddGap and SetVariable misbehavior  (Read 2371 times)
homay2
Newbie
*
Posts: 4


View Profile
« on: March 22, 2011, 07:29:19 pm »

To put it short, I'm doing the followings:
  SetVariable(x, RoundUp(ZoneEnd + ZoneSize, 16MB))
  SortByName(Ascending)
  AddGap(x)

and the beginning of the next zone is _before_ x. (ZoneSize is about 60MB).

First I used AddGap(RoundUp(ZoneEnd + ZoneSize, 16MB))
Second I introduced x and used AppendLogfile() + pause() to debug the value of x.
Finally I turned on Debug(447) and stopped MyDefrag when in the pause(). I did not attach the whole MyDefrag.debuglog file because it is 32M, but the relevant part only. The value of 'x' that is written by AppendLogfile() is proper, but from the debuglog it seems that internally MyDefrag stores a different value (why?)

Here are the details:
Relevant piece of my script:
  ...
  SetVariable(zoneName,"WMITracing.log")
  FileSelect FileName("!zoneName!") FileActions SortByName(Ascending) AddGap(RoundUp(ZoneEnd,RoundUp(ZoneSize/2,16MB))) FileEnd
  SetVariable(zoneName,"avguard.tmp")
  FileSelect FileName("!zoneName!") FileActions
    SetVariable(x, RoundUp(ZoneEnd + ZoneSize, 16MB))
    AppendLogfile("!Logfn!","x=!x! ")
    SortByName(Ascending)
    AddGap(x)
    AppendLogfile("!Logfn!","AddGap(!x!)
    ")
  FileEnd
    AppendLogfile("!Logfn!","ZoneBegin=!ZoneBegin!
    ")
  SetVariable(zoneName,"global-messages-db.sqlite")
  FileSelect FileName("!zoneName!") FileActions pause() SortByName(Ascending) AddGap(RoundUp(ZoneEnd,RoundUp(ZoneSize/2,16MB))) FileEnd
  ...

---------------------------------------------------------
This is what I got in the .log file:

Date:                       2011-03-22 18:56:21
Script:                     robin-C:
MyDefrag version:           MyDefrag v4.3.1 for X64
Commandline:                MyDefrag.exe  "D:\users\robin\Programs\MyDefrag\robin-C.MyD"
Working directory:          C:\Program Files\MyDefrag v4.3.1
x=6593445888.000000 AddGap(6593445888.000000)
    ZoneBegin=    6 526 337 024

ZoneBegin<x despite AddGap(x)

I think AddGap(x) should execute because the file named "avguard.tmp" DOES exist and was not selected by preceding zones.

The debuglog contains:
19:03:44     Variable x = '6526337024.000000'
19:03:44       Value of Variable x = 6526337024.000000

This is contradicts with the output of AppendLogfile().
The relevant part of the debug log is attached.

Thank you in advance,
homay

* MyDefrag.debuglog.txt (11.43 KB - downloaded 106 times.)
« Last Edit: March 22, 2011, 09:34:10 pm by homay2 » Logged
jeroen
Administrator
JkDefrag Hero
*****
Posts: 7183



View Profile WWW
« Reply #1 on: March 24, 2011, 05:04:07 am »

from the debuglog it seems that internally MyDefrag stores a different value (why?)
MyDefrag does it's calculations internally in Logical Cluster Numbers. For output it multiplies that automatically with the cluster size, to get at the bytes and megabytes that people are used to.

Quote
This is contradicts with the output of AppendLogfile().
I have looked at your debug logfile but everything looks ok to me. The only explanation I can think of right now is that you are comparing the debug logfile with the regular logfile from 2 different runs of MyDefrag. Do you have a WriteLogFile() somewhere in the beginning of your script? If not then make sure you scroll down to the end of the logfile.
Logged
homay2
Newbie
*
Posts: 4


View Profile
« Reply #2 on: March 24, 2011, 12:56:37 pm »

This thought came to me, too, therefore I made sure that I'm comparing the corresponding debuglog and regular logfile. This is why I included the header of the debuglog and regular log in my post:
Debuglog:   Date: 2011/03/22 18:56:21
Regular log: Date:                       2011-03-22 18:56:21
I surely did not start MyDefrag twice in the very same second, so these must be the same run.

Furthermore, I do have WriteLogfile() in my script (before VolumeSelect).

Usually AddGap() works, it seems to fail after this "avguard.tmp" file only. When I had a close look at that file on the disk map, its "height" (in rows) seems to be equal to the "height" of "global-messages-db.sqlite", despite the fact that the file size of  "avguard.tmp" is 38MB and "global-messages-db.sqlite" is 82MB. "avguard.tmp" is a temp file of Avira Antivirus (it gets reallocated and heavily fragmented after every boot, this is why I'm trying to make room around it).
I'm suspecting that this file may have different allocated size than its "valid length"... Actually, I don't know these terms but I've heard about that these can be different... maybe this confuses MyDefrag?...

I will post again when I have more evidences about the problem. Currently I found a workaround:

  FileSelect FileName("avguard.tmp") FileActions SortByName(Ascending) FileEnd
  MakeGap(ZoneBegin + 90MB)

This avoids AddGap() and has the gap size hard-coded, but it works (vacates about 70M after "avguard.tmp").

By the way, is it normal that the value of a variable that is set inside a FileAction becomes zero after the end of the FileAction?
I experienced this, too. I'll try to reproduce it if you're interested.

Thank you for your attention!

homay
Logged
Eurythrace
Newbie
*
Posts: 3


View Profile
« Reply #3 on: November 01, 2012, 11:36:19 pm »

Hi, Joeren.

I'm a new user to MyDefrag and I love the concept and really appreciate all the work you've done on this "hobby".

But, I have a couple of issues I've noticed after playing with MyDefrag for the last couple of weeks. Maybe this has been addressed elsewhere, but this is the best thread that I could find for the problems I have experienced.

1) Mixed mode arithmetic (combined integer and floating point) problem:

SetVariable( NL, "
" )
SetVariable( FixedGap, RoundDown( 0.01 * VolumeSize, BytesPerCluster ) )
AppendLogfile( "MyDefrag.log", "ClusterSize: !BytesPerCluster!!NL!" )
AppendLogfile( "MyDefrag.log", "FixedGap: !FixedGap!!NL!" )


Log Results:
-----------
  Total disk space: 617,062,068,224 bytes (574.6838 GigaBytes)
  Volume type: NTFS

  ClusterSize: 4,096
  FixedGap: 6170620682.240000


The RoundDown() function treats the BytesPerCluster integer as 0 (zero), so no rounding takes place. If I do the following, though, it works just great:

SetVariable( NL, "
" )
SetVariable( ClusterSize, 4KB )
SetVariable( FixedGap, RoundDown( 0.01 * VolumeSize, ClusterSize ) )
AppendLogfile( "MyDefrag.log", "ClusterSize: !ClusterSize!!NL!" )
AppendLogfile( "MyDefrag.log", "FixedGap: !FixedGap!!NL!" )


Log Results:
-----------
  Total disk space: 617,062,068,224 bytes (574.6838 GigaBytes)
  Volume type: NTFS

  ClusterSize: 4096.000000
  FixedGap: 6170619904.000000

Which is correct. The RoundDown() function has rounded the FixedGap variable to the next lowest multiple of the cluster size. Other similar tests yielded the same result. This appears to be a problem with mixed mode arithmetic, with integer values being treated as 0 (zero) in the rounding functions, at least.

2) User variables set inside a File Action block do not retain their correct value outside of the File Action block if those user variables are based on program Zone variables:

SetVariable( NL, "
" )
SetVariable( ClusterSize, 4KB )
SetVariable( ZoneAlignment, 1GB )
SetVariable( ArchMaxGap, 0.1 * VolumeFree )

MakeGap( RoundUp( 0.8 * VolumeSize, ClusterSize ), DoNotVacate )

FileSelect
   .
   .
   .
FileActions
   SetVariable( ZoneBased, RoundDown( VolumeSize - ( 2 * ZONE221N ), ZoneAlignment ) )
   SetVariable( FreeBased, RoundUp( VolumeSize - ZONE221N - ArchMaxGap, ClusterSize ) )
   AddGap( Maximum( ZoneBased, FreeBased ), DoNotVacate )
   AppendLogfile( "MyDefrag.log", "Zone Size Based: !ZoneBased!!NL!" )
   AppendLogfile( "MyDefrag.log", "Available Based: !FreeBased!!NL!!NL!" )
   SetVariable( ZoneXzero, RoundDown( VolumeSize - ( 2 * 0 ), ZoneAlignment ) )
   SetVariable( FreeXzero, RoundUp( VolumeSize - 0 - ArchMaxGap, ClusterSize ) )
   AppendLogfile( "MyDefrag.log", "Zone Size Xzero: !ZoneXzero!!NL!" )
   AppendLogfile( "MyDefrag.log", "Available Xzero: !FreeXzero!!NL!!NL!" )
   AppendLogfile( "MyDefrag.log", "ZoneBegin: !ZoneBegin!!NL!!NL!" )
#   SortByName( Ascending )
FileEnd

MakeGap( Maximum( ZoneBased, FreeBased ), DoNotVacate )
AppendLogfile( "MyDefrag.log", "Zone Size Based: !ZoneBased!!NL!" )
AppendLogfile( "MyDefrag.log", "Available Based: !FreeBased!!NL!!NL!" )
AppendLogfile( "MyDefrag.log", "Zone Size Xzero: !ZoneXzero!!NL!" )
AppendLogfile( "MyDefrag.log", "Available Xzero: !FreeXzero!!NL!!NL!" )
AppendLogfile( "MyDefrag.log", "ZoneBegin: !ZoneBegin!!NL!!NL!" )
Pause()

Log Results:
-----------
<---- Inside File Action Block ---->
  Zone Size Based: 601295421440.000000
  Available Based: 594381119488.000000

  Zone Size Xzero: 616327806976.000000
  Available Xzero: 601847705600.000000

  ZoneBegin: 493,649,657,856

<---- Outside File Action Block ---->
  Zone Size Based: 616327806976.000000
  Available Based: 601847705600.000000


  Zone Size Xzero: 616327806976.000000
  Available Xzero: 601982304256.000000

  ZoneBegin: 616,327,806,976

This points out the already known bug with the AddGap() function (the AddGap() function does not move the ZoneBegin), but more importantly it highlights the problem with user variables set inside a File Action block. The values of the user variables "ZoneBased" and "FreeBased" have one value inside the File Action block based on the value of the program Zone variable "ZONE221N". If I use the same formula to calculate the values of these user variables inside the File Action block, but replace "ZONE221N" with 0 (zero), the variables "ZoneXzero" and "FreeXzero"; then that is the exact same result that I get for the values of "ZoneBased" and "FreeBased" OUTSIDE the File Action block. The values of "ZoneXzero" and "FreeXzero" remain the same inside and outside of the File Action block, apparently because they do NOT utilize any of the program Zone variables in their creation inside the File Action block.

Note that the volume size is 617062068224 bytes and that RoundDown( 617062068224, 1GB ) = 616327806976, the value of "ZoneXzero" inside and outside the File Action block, and the value of "ZoneBased" outside the File Action block. So the rounding functions are working properly (with all floating point arithmetic only!), but the user variables based on program Zone variables set inside of the File Action block are reset outside of it to values that are consistent with values calculated as if the program Zone variables had a value of 0 (zero).

If I am missing something, I would greatly appreciate being shown what I am doing wrong. Otherwise, I hope you have found a solution to these issues, and will be releasing an updated version of MyDefrag soon, as these issues necessitate a lot of manual calculation to set Zone beginning points based on the Zone size after the initial defragmentation is done with fixed Zone gaps. Also, I hope that any corrections to the AddGap() function will allow it to be used to change the ZoneBegin inside the File Action block BEFORE any file movement / defragmentation has occured to allow setting of the current Zone's beginning point based upon it's parameters, like size.

Thanks, and keep up the great work.
Logged
Rohk
JkDefrag Hero
*****
Posts: 152



View Profile
« Reply #4 on: November 02, 2012, 04:53:19 pm »

Hi, here's what I found.

BytesPerCluster is zero until the disk is analyzed. On my test, if it was used straight after the volume selection, as the first volume action, it does not trigger the disk analysis and it is still zero. You can try it with this test script:

Code:
WriteLogfile("MyDefrag.log","BytesPerCluster test:
")


VolumeSelect
  Name("C:")
VolumeActions

SetVariable(test, RoundDown(5000, BytesPerCluster))
AppendLogfile( "MyDefrag.log", "Before analysis: !test!
")

SetVariable(test, RoundDown(5000, BytesPerCluster))
AppendLogfile( "MyDefrag.log", "After analysis: !test!
")

VolumeEnd

MyDefrag seems to process SetVariable actions after the volume selection first before it starts to analyze the disk. Notice that the AppendLogfile is the action that starts the disk analysis in here and it is processed after the analysis. Thus, the correct value for the second BytesPerCluster. Does this behavior also apply to your problem?

For the second problem, I also experienced this with ZoneSize variable when I tried to use it as a macro to another script by using the RunProgram action outside the file actions. It also worked if the RunProgram was used inside the same file actions where the zone size variable was defined, but this way it would only allow to use one zone size for the new script.

As an idea for this, the zone sizes can be saved separately to their own log files by first only analyzing the zones in the first script, and then using them in the second script with actions or gaps based on the zone sizes. This technique is used in here, see if you are interested: http://www.mydefrag.com/forum/index.php?topic=4202.0
Logged
lordkevin8
Newbie
*
Posts: 1


View Profile
« Reply #5 on: January 02, 2013, 11:42:11 am »

Thanks for the nice post and happy new year...
Logged

lord
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!