FastTrace Implementation


As you can see, FastTrace is quite simple to use, and as you'll learn in this section, its implementation is nearly that simple as well. The main magic behind FastTrace is per-thread storage. Each thread has its own copy of the file-writing class, so it writes only to a single file. Much of the core implementation is straightforward. All the source code is in the FastTrace project, which accompanies this book's sample files.

I had to make only two interesting decisions while implementing FastTrace. The first thought I had when designing the tool was to store the individual thread trace logs as text files. That way the files were easily readable right off the bat. Of course, when I thought about the work that I was going to cause by merging them, I figured there had to be another way. Consequently, I chose to store each entry with a binary timestamp along with the particular trace string. I originally considered allowing variable length strings in that file format, but I didn't want to slow down the tracing by needing to count the characters in each string on each trace statement. Additionally, variable length strings would have made the reading that much more difficult.

The second issue I needed some time to think about was which time format to store the timestamps in. I don't know if you've ever looked at the Time help for the operating system, but there seems to be a plethora of different formats. After playing around a little bit, I chose to use the FILETIME format because it's only 8 bytes, whereas the SYSTEMTIME format is 16 bytes. I also looked at the processing involved and determined the fastest way to get the time was to call only GetSystemTimeAsFileTime instead of other time functions.




Debugging Applications for Microsoft. NET and Microsoft Windows
Debugging Applications for MicrosoftВ® .NET and Microsoft WindowsВ® (Pro-Developer)
ISBN: 0735615365
EAN: 2147483647
Year: 2003
Pages: 177
Authors: John Robbins

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net