I've been working on a tool to measure the performance of print jobs and one little bug in it completely destroyed my day at work, but Luckily I had CCleaner to help me fix the problem. The concept of the tool is simple, but because I have to use multithreading it's gotten pretty complex, revision over revision.
The objective of the tool is simple. Whenever we make a substantial modification to the source of the renderer, we have to test for any degradation in performance. We have a bunch of XPS files and we simply use the AddJob method of the PrintQueue API to send the XPS data to the printer. This was a simple tool which was developed in the ancient days. So we add job after job to the printer and measure how long it takes to finish each print job. There was a separate tool that automatically dumped the start time and the finish time of the print job. (Did you think we measured it using a stopwatch?) Obviously we have to do this few time for each XPS file and take the average. It is such time waste.
The tool I wrote does this automatically. I just have to install the printer driver, load the data and bang. So easy. A lot of time saving.
There were some issues though. One of them was, sometimes the PrintFilterPipelineService, which is the process the print job is managed by, since Vista days, sometimes skips the print the job without doing anything if a new job is sent soon after the previous one finished. I've noticed this on my Athlon X2 4200+ rig, but not on the Core i7 2600 rig or the common test rig with Core i5 750. Anyways, the solution was to kill that process after every print job.
That worked fine until I had to measure the performance of a large amount of XPS files last week. I could actually finish the performance test alright, but the next day when I booted into Windows in the morning, the desktop didn't respond to my inputs for about 10 minutes!!! The problem didn't go away even after a multiple reboots. When I checked the Resource Monitor, I noticed that the Print Spooler service was doing a lot of I/O. When I stopped the Print Spooler service, the stalling stopped. But I need the Print Spooler service running. After a little bit of snooping around, I found the problem.