Debug.hpp File Reference
#include <iostream>
#include <cassert>
#include <sstream>
#include <string>
#include "PetscTools.hpp"
Go to the source code of this file.
Defines |
#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(); |
Functions |
std::string | FormDebugHead () |
void | PrintTheStack () |
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.
Define Documentation
#define HOW_MANY_TIMES_HERE |
( |
message |
|
) |
|
Value:{ \
static unsigned counter=1; \
std::cout << FormDebugHead() << "Num times here (" << message << "): " << counter++ << std::endl << std::flush; }
Print how many times this line has been reached, everytime it is reached.
- Parameters:
-
| message | message to include in brackets |
Definition at line 118 of file Debug.hpp.
#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 69 of file Debug.hpp.
#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 147 of file Debug.hpp.
#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 71 of file Debug.hpp.
#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:
-
Definition at line 80 of file Debug.hpp.
#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:
-
Definition at line 88 of file Debug.hpp.
#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:
-
Definition at line 97 of file Debug.hpp.
#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:
-
Definition at line 108 of file Debug.hpp.
#define PRINT_VARIABLE |
( |
var |
|
) |
std::cout << FormDebugHead() << #var " = " << var << std::endl << std::flush; |
Print the name and value of the given variable.
- Parameters:
-
Definition at line 74 of file Debug.hpp.
#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:
-
Definition at line 131 of file Debug.hpp.
#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:
-
Definition at line 114 of file Debug.hpp.
#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 152 of file Debug.hpp.
#define TRACE |
( |
stuff |
|
) |
std::cout << FormDebugHead() << stuff << std::endl << std::flush; |
Print a debug message.
- Parameters:
-
| stuff | what to print (can be a variable, or e.g. a << " " << b) |
Definition at line 66 of file Debug.hpp.
Referenced by PrintTheStack().
#define TRACE_FROM_NTH_VISIT |
( |
stuff, |
|
|
n |
|
) |
|
Value:{ \
static unsigned counter=0; \
if (++counter>=(n)) {TRACE(stuff<<" (visit "<<counter<<")");} }
Prints the given message, but only from the n-th time that line is reached, for the given n.
- Parameters:
-
Definition at line 125 of file Debug.hpp.
Function Documentation
std::string FormDebugHead |
( |
|
) |
|
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 55 of file Debug.cpp.
References TRACE.