April 28, 2006

Tracing Swag

Would you believe that I am writing Java again? My PowerBook didn’t crash for well over an hour, and I was able to work in Eclipse.

Tracing

My tracing swag will simply record objects. It will be based on the premise that object allocation is fast with the generational garbage collector. To report the status of an operation, create an object and send it down a pipe. That pipe may be in process or send accorss processes. The object is added to a linked list of objects. Only the head of the list needs concurrency control, since the contents of the list are immutable. On occasion, the list is flushed to disk. The objects are written.

If you don’t feel like tracing then you can build a map with a handy builder utlity.

When tracing is off, the record object is handed off to a null function, nothing happens, and the object is short lived and plucked by the garbage collector.

Controlling Tracing

Tracing starts by requesting a tracing object to which to write. This is done by handing off a class name to a look up algorithm based on something I saw Sedgewick do once. It will perform a linear search to find all the tracing settings and return an object whose methods are used to write the output. If tracing is entrely disabled then an object with no op methods is returned.

The objects are a TracerFactory which creates a TracerServer for a particular class name. The TracerServer returns a Tracer when one is needed.

Once you have the object, each trace has at least two method calls even if it is a no op.

Reporting

Reporting is driven by iterating through the list and serializing the objects as XML. Using XSLT, the objects are transformed into HTML and viewed in an Ajax application.

Architecture

There are three places where the list can be stored. One is in process. The lists get written out by a worker thread, or after a certian number of objects. Out of process means funneling the objects to a server that will build the lists and perform the occasional flush. Finally, there’s the option of having the reporting be a separate servlet, and that it polls the applications to flush their queues of objects. Polling is one option pushlets are another.

Leave a Reply