Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
Debug.hpp File Reference
#include <iostream>
#include <cassert>
#include <sstream>
#include <string>
#include "PetscTools.hpp"
+ Include dependency graph for Debug.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TRACE(stuff)   std::cout << FormDebugHead() << stuff << std::endl << std::flush;
 
#define MARK   std::cout << FormDebugHead() << __FILE__ << " at line " << __LINE__ << std::endl << std::flush;
 
#define MARK_ON_PROCESS(proc)   if (PetscTools::GetMyRank()==proc) std::cout << FormDebugHead() << __FILE__ << " at line " << __LINE__ << std::endl << std::flush;
 
#define PRINT_VARIABLE(var)   std::cout << FormDebugHead() << #var " = " << var << std::endl << std::flush;
 
#define PRINT_2_VARIABLES(var1, var2)
 
#define PRINT_3_VARIABLES(var1, var2, var3)
 
#define PRINT_4_VARIABLES(var1, var2, var3, var4)
 
#define PRINT_5_VARIABLES(var1, var2, var3, var4, var5)
 
#define QUIT_AFTER_N_VISITS(n)   { static unsigned counter=0; if (++counter==(n)) {TRACE("User-forced quit."); assert(0);} }
 
#define HOW_MANY_TIMES_HERE(message)
 
#define TRACE_FROM_NTH_VISIT(stuff, n)
 
#define PRINT_VECTOR(v)
 
#define MARK_IN_ORDER   PetscTools::BeginRoundRobin(); MARK; PetscTools::EndRoundRobin();
 
#define STACK   PrintTheStack();
 
#define MARK_MEMORY   MarkMemory();
 
#define UNMARK_MEMORY   UnmarkMemory();
 
#define PRINT_MEMORY   PrintMemory();
 

Functions

std::string FormDebugHead ()
 
void PrintTheStack ()
 
void MarkMemory ()
 
void UnmarkMemory ()
 
void PrintMemory ()
 

Variables

double eMemoryAtMarker
 

Detailed Description

A bunch of useful macros for debugging. These all output information to stdout as lines starting "DEBUG: ". When running in parallel the process number is also displayed. Each line is flushed as soon as it is written.

Note
Use of these should be removed from source code when committing.

Definition in file Debug.hpp.

Macro Definition Documentation

◆ HOW_MANY_TIMES_HERE

#define HOW_MANY_TIMES_HERE (   message)
Value:
{ \
static unsigned counter=1; \
std::cout << FormDebugHead() << "Num times here (" << message << "): " << counter++ << std::endl << std::flush; }
std::string FormDebugHead()
Definition Debug.cpp:47

Print how many times this line has been reached, everytime it is reached.

Parameters
messagemessage to include in brackets

Definition at line 148 of file Debug.hpp.

◆ MARK

#define MARK   std::cout << FormDebugHead() << __FILE__ << " at line " << __LINE__ << std::endl << std::flush;

Print some trace containing the file name and line number.

Definition at line 99 of file Debug.hpp.

◆ MARK_IN_ORDER

#define MARK_IN_ORDER   PetscTools::BeginRoundRobin(); MARK; PetscTools::EndRoundRobin();

(For debugging on a seriously large number of processes) Show the mark that we have reached this line of code, but do it in process order, which is important if we suspect that one or more processes are missing.

This will also isolate all the MARKs which appear for a particular line of code, since all process have to synchronise at the beginning of the round-robin.

Note that this will change the parallel behaviour of the code – if one process really is missing then the first barrier inside the round-robin will cause deadlock.

Definition at line 177 of file Debug.hpp.

◆ MARK_MEMORY

#define MARK_MEMORY   MarkMemory();

Allows use of PRINT_MEMORY to give results relative to the footprint at this call.

Set sMemoryAtMarker to the current approximate memory footprint. This value is subtracted from the memory footprint if the macro PRINT_MEMORY is called.

Definition at line 190 of file Debug.hpp.

◆ MARK_ON_PROCESS

#define MARK_ON_PROCESS (   proc)    if (PetscTools::GetMyRank()==proc) std::cout << FormDebugHead() << __FILE__ << " at line " << __LINE__ << std::endl << std::flush;

Print some trace containing the file name and line number, but only on the matching process

Definition at line 101 of file Debug.hpp.

◆ PRINT_2_VARIABLES

#define PRINT_2_VARIABLES (   var1,
  var2 
)
Value:
std::cout << FormDebugHead() << #var1 " = " << var1 << ", " \
#var2 " = " << var2 << std::endl << std::flush;

Print the name and value of the given variables.

Parameters
var1
var2

Definition at line 110 of file Debug.hpp.

◆ PRINT_3_VARIABLES

#define PRINT_3_VARIABLES (   var1,
  var2,
  var3 
)
Value:
std::cout << FormDebugHead() << #var1 " = " << var1 << ", " \
#var2 " = " << var2 << ", " #var3 " = " << var3 << std::endl << std::flush;

Print the name and value of the given variables.

Parameters
var1
var2
var3

Definition at line 118 of file Debug.hpp.

◆ PRINT_4_VARIABLES

#define PRINT_4_VARIABLES (   var1,
  var2,
  var3,
  var4 
)
Value:
std::cout << FormDebugHead() << #var1 " = " << var1 << ", " \
#var2 " = " << var2 << ", " #var3 " = " << var3 << ", " \
#var4 " = " << var4 << std::endl << std::flush;

Print the name and value of the given variables.

Parameters
var1
var2
var3
var4

Definition at line 127 of file Debug.hpp.

◆ PRINT_5_VARIABLES

#define PRINT_5_VARIABLES (   var1,
  var2,
  var3,
  var4,
  var5 
)
Value:
std::cout << FormDebugHead() << #var1 " = " << var1 << ", " \
#var2 " = " << var2 << ", " #var3 " = " << var3 << ", " \
#var4 " = " << var4 << ", " #var5 " = " << var5 <<std::endl << std::flush;

Print the name and value of the given variables.

Parameters
var1
var2
var3
var4
var5

Definition at line 138 of file Debug.hpp.

◆ PRINT_MEMORY

#define PRINT_MEMORY   PrintMemory();

Print the approximate memory footprint. This is the current memory footprint minus sMemoryAtMarker, which will be zero if the MARK_MEMORY macro has not been used.

Definition at line 202 of file Debug.hpp.

◆ PRINT_VARIABLE

#define PRINT_VARIABLE (   var)    std::cout << FormDebugHead() << #var " = " << var << std::endl << std::flush;

Print the name and value of the given variable.

Parameters
var

Definition at line 104 of file Debug.hpp.

◆ PRINT_VECTOR

#define PRINT_VECTOR (   v)
Value:
{ std::cout << FormDebugHead() << #v " = {"; \
for (unsigned _i=0; _i<v.size(); _i++) { \
std::cout << (_i==0?"":",") << v[_i]; } \
std::cout << "}" << std::endl << std::flush; }

Display a std::vector.

Parameters
v

Definition at line 161 of file Debug.hpp.

◆ QUIT_AFTER_N_VISITS

#define QUIT_AFTER_N_VISITS (   n)    { static unsigned counter=0; if (++counter==(n)) {TRACE("User-forced quit."); assert(0);} }

Quit (assert(0)) on the n-th time this line is reached, for the given n.

Parameters
n

Definition at line 144 of file Debug.hpp.

◆ STACK

#define STACK   PrintTheStack();

In extremis, print enough of the stack to see how we got to this point (e.g. at EXCEPTION time)

Definition at line 182 of file Debug.hpp.

◆ TRACE

#define TRACE (   stuff)    std::cout << FormDebugHead() << stuff << std::endl << std::flush;

Print a debug message.

Parameters
stuffwhat to print (can be a variable, or e.g. a << " " << b)

Definition at line 96 of file Debug.hpp.

◆ TRACE_FROM_NTH_VISIT

#define TRACE_FROM_NTH_VISIT (   stuff,
 
)
Value:
{ \
static unsigned counter=0; \
if (++counter>=(n)) {TRACE(stuff<<" (visit "<<counter<<")");} }
#define TRACE(stuff)
Definition Debug.hpp:96

Prints the given message, but only from the n-th time that line is reached, for the given n.

Parameters
stuffwhat to print
n

Definition at line 155 of file Debug.hpp.

◆ UNMARK_MEMORY

#define UNMARK_MEMORY   UnmarkMemory();

Set sMemoryAtMarker to zero meaning subsequent use of PRINT_MEMORY will give an absolute memory footprint, rather than relative to a fixed value.

Definition at line 196 of file Debug.hpp.

Function Documentation

◆ FormDebugHead()

std::string FormDebugHead ( )
Returns
a 'header' which can be printed in each debug output line

Definition at line 47 of file Debug.cpp.

References PetscTools::GetMyRank(), and PetscTools::IsParallel().

◆ MarkMemory()

void MarkMemory ( )

Allows use of PRINT_MEMORY to give results relative to the footprint at this call.

Set sMemoryAtMarker to the current approximate memory footprint. This value is subtracted from the memory footprint if the macro PRINT_MEMORY is called.

This is used with the macro MARK_MEMORY

Definition at line 83 of file Debug.cpp.

References TRACE.

◆ PrintMemory()

void PrintMemory ( )

Print the approximate memory footprint. This is the current memory footprint minus sMemoryAtMarker, which will be zero if the MARK_MEMORY macro has not been used.

This is used with the macro PRINT_MEMORY

Definition at line 105 of file Debug.cpp.

◆ PrintTheStack()

void PrintTheStack ( )

In extremis, print enough of the stack to see how we got to this point (e.g. at EXCEPTION time). This is used with the macro STACK

Definition at line 59 of file Debug.cpp.

References TRACE.

◆ UnmarkMemory()

void UnmarkMemory ( )

Set sMemoryAtMarker to zero meaning subsequent use of PRINT_MEMORY will give an absolute memory footprint, rather than relative to a fixed value.

This is used with the macro UNMARK_MEMORY

Definition at line 96 of file Debug.cpp.

References TRACE.

Variable Documentation

◆ eMemoryAtMarker

double eMemoryAtMarker
extern

Can be set as approximate memory footprint in Mb at marker using the macro MARK_MEMORY

Definition at line 45 of file Debug.cpp.