Using JrDebugEnclose |
Top Previous Next |
This example shows how to use the the JrDebugEnclose macro with the debugblock construct; it will automatically report the start and end of scoped blocks, and the time taken; you can also use the debugblockreport() function to report current offset time within the current block. You will find this demo project in the DebugLibrary source code directory, along with project files for ms .net2003,vc6, and dev-c++.
//--------------------------------------------------------------------------- // System includes #include <iostream> //---------------------------------------------------------------------------
//--------------------------------------------------------------------------- // Include the Debugging Library files // Note that only our main .cpp needs to include the JRutils_debugout_main.h file // alternatively, you could add this cpp to your project or makefile. #include "../../jrdebug_main.cpp" //---------------------------------------------------------------------------
//--------------------------------------------------------------------------- // Forward declaration int WorkFunction(); //---------------------------------------------------------------------------
//--------------------------------------------------------------------------- int main(int argc, char *argv[]) { // call the work function and report it + time it int retv; JrDebugEnclose(WorkFunction()); JrDebugEnclose(retv=WorkFunction());
dbprintf("Program has finished: %d.",retv);
// all done return 0; } //---------------------------------------------------------------------------
//--------------------------------------------------------------------------- int WorkFunction() { int count3,count4,count5; for (int count2=0;count2<10;++count2) { // report this loop block debugblock("inner loop"); // take some time for (count3=0;count3<30000;++count3) { for (count4=0;count4<300;++count4) { // just eat up some cpu cycles count5=count3-count2; count5++; count5--; count5=count3-count2; } } } // return dummy value return 999; } //---------------------------------------------------------------------------
|