2007-03Mar-01
Using FileMon
FileMon is a great utility if you need to debug performance problems in a Visual FoxPro application. After launching FileMon.EXE as an administrator change the filter to "VFP9.EXE" or the name of your application. When you now run your application, you can see all disk activities in your application.
One major pattern to watch out is a long list of read accesses on a single DBF file. These are usually table scan that are the result of un-optimized queries or frequent aggregations such as calculating sums or counts. When you test on a local machine you rarely notice these operations as a delay since your hard disk is fast enough to read dozens of MB in just one second. On a shared network, though, bandwidth is really criticial.
FileMon is pretty good at telling you what went wrong. However, it doesn't help you to relate this with the actual line numbers in your code. To achieve this I use markers in my Visual FoxPro application. A marker looks like this:
=FILE("MyClass.MyMethod.BeforeScan")
That is, I check for the existence of a not existing file. In FileMon this line produces output similar to the following:
11:14:08.182 vfp9.exe:2776 FASTIO_QUERY_OPEN
C:\DOCUMENTS AND SETTINGS\CHRISTOF\MY
DOCUMENTS\PROJECTS\lib\MyClass.MyMethod.BeforeScan
FILE NOT FOUND Attributes: Error
Now I can search for my markers in FileMon. I can be confident that all activities between two markers have been caused by the code between the two markers. By adding and moving markers I can quickly identify the lines that cause most traffic in an application.