gem5  v22.1.0.0
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/match.hh"
43 #include "base/types.hh"
44 #include "sim/cur_tick.hh"
45 
46 // Return the global context name "global". This function gets called when
47 // the DPRINTF macros are used in a context without a visible name() function
48 // @todo This should be moved to the gem5 namespace
49 const std::string &name();
50 
51 namespace gem5
52 {
53 
54 namespace trace {
55 
58 class Logger
59 {
60  protected:
63 
64  public:
66  template <typename ...Args>
67  void dprintf(Tick when, const std::string &name, const char *fmt,
68  const Args &...args)
69  {
70  dprintf_flag(when, name, "", fmt, args...);
71  }
72 
74  template <typename ...Args>
75  void dprintf_flag(Tick when, const std::string &name,
76  const std::string &flag,
77  const char *fmt, const Args &...args)
78  {
79  if (!name.empty() && ignore.match(name))
80  return;
81  std::ostringstream line;
82  ccprintf(line, fmt, args...);
83  logMessage(when, name, flag, line.str());
84  }
85 
87  void dump(Tick when, const std::string &name,
88  const void *d, int len, const std::string &flag);
89 
91  virtual void logMessage(Tick when, const std::string &name,
92  const std::string &flag, const std::string &message) = 0;
93 
99  virtual std::ostream &getOstream() = 0;
100 
102  void setIgnore(ObjectMatch &ignore_) { ignore = ignore_; }
103 
105  void addIgnore(const ObjectMatch &ignore_) { ignore.add(ignore_); }
106 
107  virtual ~Logger() { }
108 };
109 
112 class OstreamLogger : public Logger
113 {
114  protected:
115  std::ostream &stream;
116 
117  public:
118  OstreamLogger(std::ostream &stream_) : stream(stream_)
119  { }
120 
121  void logMessage(Tick when, const std::string &name,
122  const std::string &flag, const std::string &message) override;
123 
124  std::ostream &getOstream() override { return stream; }
125 };
126 
130 
132 std::ostream &output();
133 
135 void setDebugLogger(Logger *logger);
136 
138 void enable();
139 void disable();
140 
141 } // namespace trace
142 
143 // This silly little class allows us to wrap a string in a functor
144 // object so that we can give a name() that DPRINTF will like
146 {
147  std::string str;
148  StringWrap(const std::string &s) : str(s) {}
149  const std::string &operator()() const { return str; }
150 };
151 
180 #define DDUMP(x, data, count) do { \
181  if (GEM5_UNLIKELY(TRACING_ON && ::gem5::debug::x)) \
182  ::gem5::trace::getDebugLogger()->dump( \
183  ::gem5::curTick(), name(), data, count, #x); \
184 } while (0)
185 
186 #define DPRINTF(x, ...) do { \
187  if (GEM5_UNLIKELY(TRACING_ON && ::gem5::debug::x)) { \
188  ::gem5::trace::getDebugLogger()->dprintf_flag( \
189  ::gem5::curTick(), name(), #x, __VA_ARGS__); \
190  } \
191 } while (0)
192 
193 #define DPRINTFS(x, s, ...) do { \
194  if (GEM5_UNLIKELY(TRACING_ON && ::gem5::debug::x)) { \
195  ::gem5::trace::getDebugLogger()->dprintf_flag( \
196  ::gem5::curTick(), (s)->name(), #x, __VA_ARGS__); \
197  } \
198 } while (0)
199 
200 #define DPRINTFR(x, ...) do { \
201  if (GEM5_UNLIKELY(TRACING_ON && ::gem5::debug::x)) { \
202  ::gem5::trace::getDebugLogger()->dprintf_flag( \
203  (::gem5::Tick)-1, std::string(), #x, __VA_ARGS__); \
204  } \
205 } while (0)
206 
207 #define DPRINTFV(x, ...) do { \
208  if (GEM5_UNLIKELY(TRACING_ON && (x))) { \
209  ::gem5::trace::getDebugLogger()->dprintf_flag( \
210  ::gem5::curTick(), name(), x.name(), __VA_ARGS__); \
211  } \
212 } while (0)
213 
214 #define DPRINTFN(...) do { \
215  if (TRACING_ON) { \
216  ::gem5::trace::getDebugLogger()->dprintf( \
217  ::gem5::curTick(), name(), __VA_ARGS__); \
218  } \
219 } while (0)
220 
221 #define DPRINTFNR(...) do { \
222  if (TRACING_ON) { \
223  ::gem5::trace::getDebugLogger()->dprintf( \
224  (::gem5::Tick)-1, "", __VA_ARGS__); \
225  } \
226 } while (0)
227 
228 #define DPRINTF_UNCONDITIONAL(x, ...) \
229  GEM5_DEPRECATED_MACRO_STMT(DPRINTF_UNCONDITIONAL, \
230  do { \
231  if (TRACING_ON) { \
232  ::gem5::trace::getDebugLogger()->dprintf_flag( \
233  ::gem5::curTick(), name(), #x, __VA_ARGS__); \
234  } \
235  } while (0), \
236  "Use DPRINTFN or DPRINTF with a debug flag instead.")
237  // end of api_trace
239 
240 } // namespace gem5
241 
242 #endif // __BASE_TRACE_HH__
const std::string & name()
Definition: trace.cc:49
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:69
Debug logging base class.
Definition: trace.hh:59
void setIgnore(ObjectMatch &ignore_)
Set objects to ignore.
Definition: trace.hh:102
ObjectMatch ignore
Name match for objects to ignore.
Definition: trace.hh:62
virtual std::ostream & getOstream()=0
Return an ostream that can be used to send messages to the 'same place' as formatted logMessage messa...
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:75
void addIgnore(const ObjectMatch &ignore_)
Add objects to ignore.
Definition: trace.hh:105
virtual ~Logger()
Definition: trace.hh:107
virtual void logMessage(Tick when, const std::string &name, const std::string &flag, const std::string &message)=0
Log formatted message.
void dump(Tick when, const std::string &name, const void *d, int len, const std::string &flag)
Dump a block of data of length len.
Definition: trace.cc:109
void dprintf(Tick when, const std::string &name, const char *fmt, const Args &...args)
Log a single message.
Definition: trace.hh:67
Logging wrapper for ostreams with the format: <when>: <name>: <message-body>
Definition: trace.hh:113
void logMessage(Tick when, const std::string &name, const std::string &flag, const std::string &message) override
Log formatted message.
Definition: trace.cc:149
OstreamLogger(std::ostream &stream_)
Definition: trace.hh:118
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:124
std::ostream & stream
Definition: trace.hh:115
uint16_t len
Definition: helpers.cc:62
Bitfield< 9 > d
Definition: misc_types.hh:64
Bitfield< 1 > s
Definition: pagetable.hh:64
void enable()
Enable/disable debug logging.
Definition: trace.cc:94
void setDebugLogger(Logger *logger)
Delete the current global logger and assign a new one.
Definition: trace.cc:85
void disable()
Definition: trace.cc:100
Logger * getDebugLogger()
Get the current global debug logger.
Definition: trace.cc:69
std::ostream & output()
Get the ostream from the current global logger.
Definition: trace.cc:79
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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:147
StringWrap(const std::string &s)
Definition: trace.hh:148
const std::string & operator()() const
Definition: trace.hh:149

Generated on Wed Dec 21 2022 10:22:29 for gem5 by doxygen 1.9.1