gem5 v24.0.0.0
Loading...
Searching...
No Matches
trace.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014, 2019, 2021 Arm Limited
3 * All rights reserved
4 *
5 * Copyright (c) 2001-2006 The Regents of The University of Michigan
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met: redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer;
12 * redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution;
15 * neither the name of the copyright holders nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef __BASE_TRACE_HH__
33#define __BASE_TRACE_HH__
34
35#include <ostream>
36#include <string>
37#include <sstream>
38
39#include "base/compiler.hh"
40#include "base/cprintf.hh"
41#include "base/debug.hh"
42#include "base/logging.hh"
43#include "base/match.hh"
44#include "base/types.hh"
45#include "sim/cur_tick.hh"
46
47// Return the global context name "global". This function gets called when
48// the DPRINTF macros are used in a context without a visible name() function
49// @todo This should be moved to the gem5 namespace
50const std::string &name();
51
52namespace gem5
53{
54
55namespace trace {
56
59class Logger
60{
61 protected:
66
67 bool isEnabled(const std::string &name) const
68 {
69 if (name.empty()) // Enable the logger with a empty name.
70 return true;
71 bool ignore_match = ignore.match(name);
72 bool activate_match = activate.match(name);
73 if (ignore_match && activate_match)
74 panic("%s in both ignore and activate.\n", name);
75 if (ignore_match)
76 return false;
77 if (!activate.empty() && !activate_match)
78 return false;
79 return true;
80 }
81
82 public:
84 template <typename ...Args>
85 void dprintf(Tick when, const std::string &name, const char *fmt,
86 const Args &...args)
87 {
88 dprintf_flag(when, name, "", fmt, args...);
89 }
90
92 template <typename ...Args>
93 void dprintf_flag(Tick when, const std::string &name,
94 const std::string &flag,
95 const char *fmt, const Args &...args)
96 {
97 if (!isEnabled(name))
98 return;
99 std::ostringstream line;
100 ccprintf(line, fmt, args...);
101 logMessage(when, name, flag, line.str());
102 }
103
105 void dump(Tick when, const std::string &name,
106 const void *d, int len, const std::string &flag);
107
109 virtual void logMessage(Tick when, const std::string &name,
110 const std::string &flag, const std::string &message) = 0;
111
117 virtual std::ostream &getOstream() = 0;
118
120 void setIgnore(ObjectMatch &ignore_) { ignore = ignore_; }
121
123 void addIgnore(const ObjectMatch &ignore_) { ignore.add(ignore_); }
124
126 void setActivate(ObjectMatch &activate_) { activate = activate_; }
127
129 void addActivate(const ObjectMatch &activate_) { activate.add(activate_); }
130
131 virtual ~Logger() { }
132};
133
136class OstreamLogger : public Logger
137{
138 protected:
139 std::ostream &stream;
140
141 public:
142 OstreamLogger(std::ostream &stream_) : stream(stream_)
143 { }
144
145 void logMessage(Tick when, const std::string &name,
146 const std::string &flag, const std::string &message) override;
147
148 std::ostream &getOstream() override { return stream; }
149};
150
154
156std::ostream &output();
157
159void setDebugLogger(Logger *logger);
160
162void enable();
163void disable();
164
165} // namespace trace
166
167// This silly little class allows us to wrap a string in a functor
168// object so that we can give a name() that DPRINTF will like
170{
171 std::string str;
172 StringWrap(const std::string &s) : str(s) {}
173 const std::string &operator()() const { return str; }
174};
175
204#define DDUMP(x, data, count) do { \
205 if (GEM5_UNLIKELY(TRACING_ON && ::gem5::debug::x)) \
206 ::gem5::trace::getDebugLogger()->dump( \
207 ::gem5::curTick(), name(), data, count, #x); \
208} while (0)
209
210#define DPRINTF(x, ...) do { \
211 if (GEM5_UNLIKELY(TRACING_ON && ::gem5::debug::x)) { \
212 ::gem5::trace::getDebugLogger()->dprintf_flag( \
213 ::gem5::curTick(), name(), #x, __VA_ARGS__); \
214 } \
215} while (0)
216
217#define DPRINTFS(x, s, ...) do { \
218 if (GEM5_UNLIKELY(TRACING_ON && ::gem5::debug::x)) { \
219 ::gem5::trace::getDebugLogger()->dprintf_flag( \
220 ::gem5::curTick(), (s)->name(), #x, __VA_ARGS__); \
221 } \
222} while (0)
223
224#define DPRINTFR(x, ...) do { \
225 if (GEM5_UNLIKELY(TRACING_ON && ::gem5::debug::x)) { \
226 ::gem5::trace::getDebugLogger()->dprintf_flag( \
227 (::gem5::Tick)-1, std::string(), #x, __VA_ARGS__); \
228 } \
229} while (0)
230
231#define DPRINTFV(x, ...) do { \
232 if (GEM5_UNLIKELY(TRACING_ON && (x))) { \
233 ::gem5::trace::getDebugLogger()->dprintf_flag( \
234 ::gem5::curTick(), name(), x.name(), __VA_ARGS__); \
235 } \
236} while (0)
237
238#define DPRINTFN(...) do { \
239 if (TRACING_ON) { \
240 ::gem5::trace::getDebugLogger()->dprintf( \
241 ::gem5::curTick(), name(), __VA_ARGS__); \
242 } \
243} while (0)
244
245#define DPRINTFNR(...) do { \
246 if (TRACING_ON) { \
247 ::gem5::trace::getDebugLogger()->dprintf( \
248 (::gem5::Tick)-1, "", __VA_ARGS__); \
249 } \
250} while (0)
251
252#define DPRINTF_UNCONDITIONAL(x, ...) \
253 GEM5_DEPRECATED_MACRO_STMT(DPRINTF_UNCONDITIONAL, \
254 do { \
255 if (TRACING_ON) { \
256 ::gem5::trace::getDebugLogger()->dprintf_flag( \
257 ::gem5::curTick(), name(), #x, __VA_ARGS__); \
258 } \
259 } while (0), \
260 "Use DPRINTFN or DPRINTF with a debug flag instead.")
261
262 // end of api_trace
263
264} // namespace gem5
265
266#endif // __BASE_TRACE_HH__
const std::string & name()
Definition trace.cc:48
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
ObjectMatch contains a vector of expressions.
Definition match.hh:57
void add(const ObjectMatch &other)
Definition match.cc:47
bool match(const std::string &name) const
Definition match.hh:73
bool empty() const
Definition match.hh:69
Debug logging base class.
Definition trace.hh:60
void setIgnore(ObjectMatch &ignore_)
Set objects to ignore.
Definition trace.hh:120
ObjectMatch ignore
Name match for objects to ignore.
Definition trace.hh:63
void addActivate(const ObjectMatch &activate_)
Add objects to activate.
Definition trace.hh:129
void dprintf_flag(Tick when, const std::string &name, const std::string &flag, const char *fmt, const Args &...args)
Log a single message with a flag prefix.
Definition trace.hh:93
bool isEnabled(const std::string &name) const
Definition trace.hh:67
void addIgnore(const ObjectMatch &ignore_)
Add objects to ignore.
Definition trace.hh:123
virtual ~Logger()
Definition trace.hh:131
virtual std::ostream & getOstream()=0
Return an ostream that can be used to send messages to the 'same place' as formatted logMessage messa...
void setActivate(ObjectMatch &activate_)
Set objects to activate.
Definition trace.hh:126
ObjectMatch activate
Name match for objects to activate log.
Definition trace.hh:65
virtual void logMessage(Tick when, const std::string &name, const std::string &flag, const std::string &message)=0
Log formatted message.
void dprintf(Tick when, const std::string &name, const char *fmt, const Args &...args)
Log a single message.
Definition trace.hh:85
Logging wrapper for ostreams with the format: <when>: <name>: <message-body>
Definition trace.hh:137
void logMessage(Tick when, const std::string &name, const std::string &flag, const std::string &message) override
Log formatted message.
Definition trace.cc:148
OstreamLogger(std::ostream &stream_)
Definition trace.hh:142
std::ostream & getOstream() override
Return an ostream that can be used to send messages to the 'same place' as formatted logMessage messa...
Definition trace.hh:148
std::ostream & stream
Definition trace.hh:139
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 18, 16 > len
Bitfield< 4 > s
Bitfield< 9 > d
Definition misc_types.hh:64
void dump()
Dump all statistics data to the registered outputs.
void enable()
Enable/disable debug logging.
Definition trace.cc:93
void setDebugLogger(Logger *logger)
Delete the current global logger and assign a new one.
Definition trace.cc:84
void disable()
Definition trace.cc:99
Logger * getDebugLogger()
Get the current global debug logger.
Definition trace.cc:68
std::ostream & output()
Get the ostream from the current global logger.
Definition trace.cc:78
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Tick
Tick count type.
Definition types.hh:58
void ccprintf(cp::Print &print)
Definition cprintf.hh:130
std::string str
Definition trace.hh:171
StringWrap(const std::string &s)
Definition trace.hh:172
const std::string & operator()() const
Definition trace.hh:173
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0