Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Simplify .NET Debugging with SmartInspect

Debugging is hard enough—even without the complications involved in debugging multithreaded programs—so tools that can simplify your debugging tasks are definitely worth evaluating. SmartInspect lets you log and view any type of data, and is particularly useful for multithreaded debugging tasks.


advertisement
fficient software debugging is definitely an acquired talent. Most programmers have some ideas on how to do it when they first get started but typically can't handle a large complex program that doesn't work. Add multithreading to a complex program and you're sure to lose most junior software developers.

In the "old days" the only way to debug a program was to put in a bunch of print statements, or the language appropriate equivalent, interspersed with the rest of the code to dump out variables and let you know where the program got to before it crashed. This method still works well for any language without a suitable debugger.

SmartInspect from Gurock Software uses a mixture of old-fashioned techniques with tight Visual Studio integration to help ease the pain of debugging multithreaded applications. Today's version of the old print statements writes messages into a log file. The advantage of a log file is that you can typically put enough information there to help you find out what's going on—and you can make logging a feature that can be turned on or off via configuration in a production deployment of your application.

Installation and Setup
Installing SmartInspect takes only a few minutes and adds a single icon to your desktop to access the console program. To use the product with your projects, you'll need to perform this three-step process.

 
Figure 1. The Project Property Pages: This is where you add the Gurock.SmartInspect namespace as an import for your project.
  1. You must add a reference to the SmartInspect.dll. To do that, right click the References item in the Solution Explorer, browse to the folder where you installed the program, and select the SmartInspect.dll file.
  2. Add SmartInspect to the import list by right-clicking on your root project item in Solution Explorer and selecting Properties. From the Properties page, select "Imports," and then enter "Gurock.SmartInspect" in the namespace edit box (see Figure 1).
  3. Enabling SmartInspect in your project requires a single line of code in the form load method. In VB.NET, this line should look like:

SiAuto.Si.Enabled = True


After enabling SmartInspect, you have two choices for debugging code—you can debug through the SmartInspect console or exclusively through log files. The console is great for initial development and testing but it isn't something you'd want to leave in a production program. During development however, using the console for debugging sessions is much easier than wading through log files.

You can use either the TCP/IP protocol for real-time logging (the default) or specify a log file, for example:

SiAuto.Si.Connections = @"file(filename=c:\log.sil)";


The console can load a specified log file or receive the logging information via TCP/IP. For production use it's better to use log files, especially for a commercial app where support is likely to be offsite.

The best way to enable debugging for a production application is to use the LoadConnections method of the SmartInspect class. With this method, support staff can send a preconfigured connections file to the customer to enable logging. Here's an example of using the LoadConnections method:



SiAuto.Si.LoadConnections(@"c:\connections.sic");


In the example above, if you had deployed an application with a customer that was having problems, you could have the customer place a preconfigured connections file called connections.sic in the c:\ folder, thus enabling logging and directing the log output to a destination specified in the connections file. You can then use the log contents to debug the deployed application. Logging will remain disabled if SmartInspect can't find the specified connections file, or if the file doesn't contain a valid connection string.

The code that logs a message works with both the console and log file output. SmartInspect provides two additional methods, EnterMethod and LeaveMethod, that let you know when a program enters or leaves a method. The console also provides a button so you can display the call stack to trace program execution paths easily. Here's a code snippet from the downloadable TimeServer sample program showing several different log methods:

SiAuto.Main.LogMessage("Calculating minutes/seconds"); int minutes = DateTime.Now.Minute; int seconds = DateTime.Now.Second; SiAuto.Main.LogValue("seconds", seconds); SiAuto.Main.LogDateTime("System Time", System.DateTime.Now); int index = minutes / seconds; SiAuto.Main.LogMessage("Sending date to client."); w.WriteLine(DateTime.Now.ToString()); for( int j = 0; j<1024; j++) buffer[j] = (byte) (j * 431); SiAuto.Main.LogBinary("Byte Array",buffer,0,1024);




Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap