|
Comments
|
Today's Top SOA Links
Debugging Faster Debugging with CFTIMER and CFTRACE
Hidden gems
By: Shlomy Gantz
Oct. 5, 2006 12:00 PM
Two of the most common debugging tasks are displaying variables and identifying bottlenecks. For years I relied on CFDUMP and CFABORT to display variables and getTickCount() to calculate processing time and identify slow-running code.
<CFSET Email = "shlomy@bluebrick.com"> In the approach above I used <CFDUMP> and <CFABORT> tags to display the value of a variable. Want to display a few variables? The screen quickly becomes a rainbow of purple, green, and gray as you look for your variables. While the wonders of CFDUMP probably deserve their own article, Adobe recently introduced a powerful new tag called CFTRACE.
Introducing CFTrace
<CFSET Email = "shlomy@bluebrick.com">
*Note that with CFTRACE the var attribute accepts a variable name without pound signs.
The Advantages of CFTrace Well, there are many reasons. Have you ever had to display a variable more than once? The task of identifying those values on the screen can become very cumbersome, especially if manipulated and changed multiple times. Showing variable values at different points in a template is easy with CFTRACE. Simply add CFTRACE tags after every change and you'll see an organized list in the debugging info section at the bottom of the screen.
<CFSET Email = "shlomy@bluebrick.com">
Another clear advantage of CFTRACE is that it can easily be turned on and off via the ColdFusion administrator. I find it extremely useful not to constantly remove and add code during the development process just to display variables. Simply browse the ColdFusion Administrator and go to Debugging & Logging -> Debugging Settings to turn CFTRACE on and off.
Not convinced yet? Consider the fact that CFTRACE also lets you categorize and type information as well as display the time differences between traces. CFTRACE calls are also displayed in Dreamweaver's server debug tab results window and ColdFusion logs <cftrace> calls to the {CFUSIONMX}\logs\cftrace.log. All of the above should be enough to convince any developer to give CFTRACE a test drive. It's a hidden gem that has long been overlooked.
Measuring Processing Time with CFTIMER
<cfset start = GetTickCount()>
But recently I've been using a new tag called CFTIMER. Simply wrap a section of your code with CFTIMER and, voilà, you instantly know how long it took to run that section.
<CFTIMER label="Long Loop">
CFTIMER lets you put the information inline (as seen in the example above) in an HTML comment, in the debugging info, or even in a nice outline as seen in the example below.
<CFTIMER label="Long Loop" type="outline">
Using "outline" can become very useful when you have several nested sections you want to test.
Summary Reader Feedback: Page 1 of 1
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||