Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
Debug.hpp
Go to the documentation of this file.
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF 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
55extern double eMemoryAtMarker;
56
58std::string FormDebugHead();
59
64void PrintTheStack();
65
74void MarkMemory();
75
82void UnmarkMemory();
83
90void 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;
101#define MARK_ON_PROCESS(proc) if (PetscTools::GetMyRank()==proc) std::cout << FormDebugHead() << __FILE__ << " at line " << __LINE__ << std::endl << std::flush;
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_*/
double eMemoryAtMarker
Definition Debug.cpp:45
void PrintMemory()
Definition Debug.cpp:105
std::string FormDebugHead()
Definition Debug.cpp:47
void PrintTheStack()
Definition Debug.cpp:59
void MarkMemory()
Definition Debug.cpp:83
void UnmarkMemory()
Definition Debug.cpp:96