Using DebugBlocks

Top  Previous  Next

This example shows how to use 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"

//---------------------------------------------------------------------------

 

//---------------------------------------------------------------------------

int main(int argc, char *argv[])

{

 // disable or enable?

 // JrDebug::SetEnabled(false);

 

 // main function report

 debugblock("mymain");

 

 // here is another loop but with activity push/pop - this will report timings of activities

 // note we enclose it in a {} to properly scope the debugblock

 {

 debugblock("all looping");

 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;

                         }

                 }

         }

 }

 

 // we can also just report current offset time of nearest enclosing debugblock (main)

 debugblockreport("before ending");

 

 // anything here is outside of scope of the "all looping" debugblock

 dbprintf("Program has finished.");

 

 // all done

 return 0;

}

//---------------------------------------------------------------------------