trace.hh revision 7811
12SN/A/*
24039Sbinkertn@umich.edu * Copyright (c) 2001-2006 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
292665Ssaidi@eecs.umich.edu *          Steve Reinhardt
302SN/A */
312SN/A
321354SN/A#ifndef __BASE_TRACE_HH__
331354SN/A#define __BASE_TRACE_HH__
342SN/A
354046Sbinkertn@umich.edu#include <string>
362SN/A#include <vector>
372SN/A
3856SN/A#include "base/cprintf.hh"
391031SN/A#include "base/match.hh"
404046Sbinkertn@umich.edu#include "base/traceflags.hh"
416214Snate@binkert.org#include "base/types.hh"
424167Sbinkertn@umich.edu#include "sim/core.hh"
432SN/A
442SN/Anamespace Trace {
452SN/A
464046Sbinkertn@umich.edustd::ostream &output();
474046Sbinkertn@umich.eduvoid setOutput(const std::string &filename);
482SN/A
494046Sbinkertn@umich.eduextern bool enabled;
504046Sbinkertn@umich.edutypedef std::vector<bool> FlagVec;
514046Sbinkertn@umich.eduextern FlagVec flags;
524046Sbinkertn@umich.eduinline bool IsOn(int t) { return flags[t]; }
534046Sbinkertn@umich.edubool changeFlag(const char *str, bool value);
544046Sbinkertn@umich.eduvoid dumpStatus();
552SN/A
564046Sbinkertn@umich.eduextern ObjectMatch ignore;
574046Sbinkertn@umich.eduextern const std::string DefaultName;
582SN/A
594046Sbinkertn@umich.eduvoid dprintf(Tick when, const std::string &name, const char *format,
604046Sbinkertn@umich.edu             CPRINTF_DECLARATION);
614046Sbinkertn@umich.eduvoid dump(Tick when, const std::string &name, const void *data, int len);
622SN/A
637811Ssteve.reinhardt@amd.com} // namespace Trace
644039Sbinkertn@umich.edu
651070SN/A// This silly little class allows us to wrap a string in a functor
661070SN/A// object so that we can give a name() that DPRINTF will like
671070SN/Astruct StringWrap
681070SN/A{
691070SN/A    std::string str;
701070SN/A    StringWrap(const std::string &s) : str(s) {}
711070SN/A    const std::string &operator()() const { return str; }
721070SN/A};
731070SN/A
742SN/Ainline const std::string &name() { return Trace::DefaultName; }
752SN/A
762SN/A//
772SN/A// DPRINTF is a debugging trace facility that allows one to
782SN/A// selectively enable tracing statements.  To use DPRINTF, there must
792SN/A// be a function or functor called name() that returns a const
802SN/A// std::string & in the current scope.
812SN/A//
822SN/A// If you desire that the automatic printing not occur, use DPRINTFR
832SN/A// (R for raw)
842SN/A//
852SN/A
862SN/A#if TRACING_ON
872SN/A
884042Sbinkertn@umich.edu#define DTRACE(x) (Trace::IsOn(Trace::x) && Trace::enabled)
892SN/A
904041Sbinkertn@umich.edu#define DDUMP(x, data, count) do {                              \
914041Sbinkertn@umich.edu    if (DTRACE(x))                                              \
924046Sbinkertn@umich.edu        Trace::dump(curTick, name(), data, count);              \
932SN/A} while (0)
942SN/A
954041Sbinkertn@umich.edu#define DPRINTF(x, ...) do {                                    \
964041Sbinkertn@umich.edu    if (DTRACE(x))                                              \
974041Sbinkertn@umich.edu        Trace::dprintf(curTick, name(), __VA_ARGS__);           \
982SN/A} while (0)
992SN/A
1005806Ssaidi@eecs.umich.edu#define DPRINTFS(x,s, ...) do {                                    \
1015806Ssaidi@eecs.umich.edu    if (DTRACE(x))                                              \
1025806Ssaidi@eecs.umich.edu        Trace::dprintf(curTick, s->name(), __VA_ARGS__);           \
1035806Ssaidi@eecs.umich.edu} while (0)
1045806Ssaidi@eecs.umich.edu
1055806Ssaidi@eecs.umich.edu
1064041Sbinkertn@umich.edu#define DPRINTFR(x, ...) do {                                   \
1074041Sbinkertn@umich.edu    if (DTRACE(x))                                              \
1084041Sbinkertn@umich.edu        Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__);   \
1092SN/A} while (0)
1102SN/A
1114046Sbinkertn@umich.edu#define DDUMPN(data, count) do {                                \
1124046Sbinkertn@umich.edu    Trace::dump(curTick, name(), data, count);                  \
1134046Sbinkertn@umich.edu} while (0)
1144046Sbinkertn@umich.edu
1154041Sbinkertn@umich.edu#define DPRINTFN(...) do {                                      \
1164041Sbinkertn@umich.edu    Trace::dprintf(curTick, name(), __VA_ARGS__);               \
1172SN/A} while (0)
1182SN/A
1194041Sbinkertn@umich.edu#define DPRINTFNR(...) do {                                     \
1204041Sbinkertn@umich.edu    Trace::dprintf((Tick)-1, string(), __VA_ARGS__);            \
121507SN/A} while (0)
122507SN/A
1232SN/A#else // !TRACING_ON
1242SN/A
1252SN/A#define DTRACE(x) (false)
1264046Sbinkertn@umich.edu#define DDUMP(x, data, count) do {} while (0)
1274041Sbinkertn@umich.edu#define DPRINTF(x, ...) do {} while (0)
1285806Ssaidi@eecs.umich.edu#define DPRINTFS(x, ...) do {} while (0)
1294041Sbinkertn@umich.edu#define DPRINTFR(...) do {} while (0)
1304046Sbinkertn@umich.edu#define DDUMPN(data, count) do {} while (0)
1314041Sbinkertn@umich.edu#define DPRINTFN(...) do {} while (0)
1324041Sbinkertn@umich.edu#define DPRINTFNR(...) do {} while (0)
1332SN/A
1345543Ssaidi@eecs.umich.edu#endif  // TRACING_ON
1352SN/A
1361354SN/A#endif // __BASE_TRACE_HH__
137