autohit.utils
Class Log

java.lang.Object
  |
  +--autohit.vm.VM
        |
        +--autohit.utils.Log

public class Log
extends VM

A logging mechanism. It will add timing information and is syncronized so more than one thread can post. The data is put in a temp file, so memory usage should not get out of hand ( as does a StringBuffer).

All entries will automatically have a LF appended to the end. Timing information shows up to 7 digits--[0000000]. Granularity is passed to the constructor; note that the timing will automatically be scaled by the VM class. DO NOT USE the default constructor.

Note that while the log timing does support pause() and resume(), it does not account for the timing of client threads, so timing information for items posted by threads may or may not be completely accurate. (For instance, pausing all the running VMs AND the Log will not happen instantaniously, so there may be some variances in timing when they are all resumed.)

To ensure that the temp file is removed, call the close() method when done.

Any exceptions that are caught during a put() or putSub() are caught and ignored. I really don't expect any to come out of those methods, and if they do, then other REAL bad stuff is probibly already underway...

This class actually extends the VM base class, as it provides the timing functionality that we want.

NOTE! The timing is started on construction. If you want to wait, immeadiatly call the pause() method.

See Also:
VM

Field Summary
 int gran
          Granulatiry for each tick of the VM's clock.
 
Fields inherited from class autohit.vm.VM
ip, scDirty, scope, state, STATE_DONE, STATE_NEW, STATE_NO_VM, STATE_PAUSED, STATE_RUNNING, TIME_GRAN, vars
 
Constructor Summary
Log(int granularity)
          Constructor.
 
Method Summary
 void close()
          Close the log and free/close any resources.
 java.io.InputStream done()
          Done with the log.
 java.io.File done(java.lang.String pathName)
          Done with the log.
 void execute()
          Doesn't do a thing.
 void put(java.lang.String text)
          Put an entry in the log.
 void putSub(java.lang.String text)
          Put a sub-entry in the log.
 
Methods inherited from class autohit.vm.VM
discardScopeFrame, getIntegerVar, getState, getVar, pause, popScope, prepare, pushScope, removeVar, resume, setVar, start, subVar, ticks
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gran

public int gran
Granulatiry for each tick of the VM's clock. This will scale the tick value. A typical value would be 1000, as this would show timing information in seconds (given that the VM class granularity is set to milliseconds).
Constructor Detail

Log

public Log(int granularity)
    throws java.lang.Exception
Constructor. It throws any exceptions related to creating the temporary file. It will start the timing. See the VM base class to see how timing is implimented.
Parameters:
granulariy - granularity for timing information. This should be a Positive number. If it is 0, the constructor will throw an Exception (since it would cause divide by 0 exceptions in other methods of this class).
Throws:
java.lang.Exception -  
See Also:
VM
Method Detail

put

public void put(java.lang.String text)
Put an entry in the log. It will append timing information.
Parameters:
text - the text to log.

putSub

public void putSub(java.lang.String text)
Put a sub-entry in the log. It will not append timing information. It will be tabbed to match the time text.
Parameters:
text - the text to log.

done

public java.io.InputStream done()
Done with the log. It returns an InputStream from which the log can be read. Once this method is called, no further entries will be logged when calling put() or putSub() (though no error will occur). This method (or its overloaded peer) can only be called once. After that, a null will be returned, instead of an InputStream.
Returns:
an InputStream presenting the log data.

done

public java.io.File done(java.lang.String pathName)
Done with the log. Returns a File pointing to a file where the log resides. This method (or its overloaded peer) can only be called once. After that, a null will be returned, instead of a File.
Parameters:
pathName - pathname to the file where the log should be written.
Returns:
a File describing the new log file.

close

public void close()
Close the log and free/close any resources.

execute

public void execute()
Doesn't do a thing. This isn't an actual VM. However, we have to impliment it since Log extends the abstract VM.
Overrides:
execute in class VM