Chaste  Release::3.4
Debug.hpp
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #ifndef DEBUG_HPP_
37 #define DEBUG_HPP_
38 
39 #include <iostream>
40 #include <cassert>
41 #include <sstream>
42 #include <string>
43 #include "PetscTools.hpp"
44 
55 extern double eMemoryAtMarker;
56 
58 std::string FormDebugHead();
59 
64 void PrintTheStack();
65 
74 void MarkMemory();
75 
82 void UnmarkMemory();
83 
90 void PrintMemory();
91 
96 #define TRACE(stuff) std::cout << FormDebugHead() << stuff << std::endl << std::flush;
97 
99 #define MARK std::cout << FormDebugHead() << __FILE__ << " at line " << __LINE__ << std::endl << std::flush;
100 
101 #define MARK_ON_PROCESS(proc) if (PetscTools::GetMyRank()==proc) std::cout << FormDebugHead() << __FILE__ << " at line " << __LINE__ << std::endl << std::flush;
102 
104 #define PRINT_VARIABLE(var) std::cout << FormDebugHead() << #var " = " << var << std::endl << std::flush;
105 
110 #define PRINT_2_VARIABLES(var1,var2) std::cout << FormDebugHead() << #var1 " = " << var1 << ", " \
111  #var2 " = " << var2 << std::endl << std::flush;
112 
118 #define PRINT_3_VARIABLES(var1,var2,var3) std::cout << FormDebugHead() << #var1 " = " << var1 << ", " \
119  #var2 " = " << var2 << ", " #var3 " = " << var3 << std::endl << std::flush;
120 
127 #define PRINT_4_VARIABLES(var1,var2,var3,var4) std::cout << FormDebugHead() << #var1 " = " << var1 << ", " \
128  #var2 " = " << var2 << ", " #var3 " = " << var3 << ", " \
129  #var4 " = " << var4 << std::endl << std::flush;
130 
138 #define PRINT_5_VARIABLES(var1,var2,var3,var4,var5) std::cout << FormDebugHead() << #var1 " = " << var1 << ", " \
139  #var2 " = " << var2 << ", " #var3 " = " << var3 << ", " \
140  #var4 " = " << var4 << ", " #var5 " = " << var5 <<std::endl << std::flush;
141 
144 #define QUIT_AFTER_N_VISITS(n) { static unsigned counter=0; if (++counter==(n)) {TRACE("User-forced quit."); assert(0);} }
145 
148 #define HOW_MANY_TIMES_HERE(message) { \
149  static unsigned counter=1; \
150  std::cout << FormDebugHead() << "Num times here (" << message << "): " << counter++ << std::endl << std::flush; }
151 
155 #define TRACE_FROM_NTH_VISIT(stuff,n) { \
156  static unsigned counter=0; \
157  if (++counter>=(n)) {TRACE(stuff<<" (visit "<<counter<<")");} }
158 
161 #define PRINT_VECTOR(v) \
162  { std::cout << FormDebugHead() << #v " = {"; \
163  for (unsigned _i=0; _i<v.size(); _i++) { \
164  std::cout << (_i==0?"":",") << v[_i]; } \
165  std::cout << "}" << std::endl << std::flush; }
166 
177 #define MARK_IN_ORDER PetscTools::BeginRoundRobin(); MARK; PetscTools::EndRoundRobin();
178 
182 #define STACK PrintTheStack();
183 
190 #define MARK_MEMORY MarkMemory();
191 
196 #define UNMARK_MEMORY UnmarkMemory();
197 
202 #define PRINT_MEMORY PrintMemory();
203 
204 #endif /*DEBUG_HPP_*/
std::string FormDebugHead()
Definition: Debug.cpp:47
void MarkMemory()
Definition: Debug.cpp:83
void PrintTheStack()
Definition: Debug.cpp:59
void PrintMemory()
Definition: Debug.cpp:105
double eMemoryAtMarker
Definition: Debug.cpp:45
void UnmarkMemory()
Definition: Debug.cpp:96