trace.hh revision 10292
12SN/A/* 210292SAndreas.Sandberg@ARM.com * Copyright (c) 2014 ARM Limited 310292SAndreas.Sandberg@ARM.com * All rights reserved 410292SAndreas.Sandberg@ARM.com * 510292SAndreas.Sandberg@ARM.com * The license below extends only to copyright in the software and shall 610292SAndreas.Sandberg@ARM.com * not be construed as granting a license to any other intellectual 710292SAndreas.Sandberg@ARM.com * property including but not limited to intellectual property relating 810292SAndreas.Sandberg@ARM.com * to a hardware implementation of the functionality of the software 910292SAndreas.Sandberg@ARM.com * licensed hereunder. You may use the software subject to the license 1010292SAndreas.Sandberg@ARM.com * terms below provided that you ensure that this notice is replicated 1110292SAndreas.Sandberg@ARM.com * unmodified and in its entirety in all distributions of the software, 1210292SAndreas.Sandberg@ARM.com * modified or unmodified, in source code or in binary form. 1310292SAndreas.Sandberg@ARM.com * 144039Sbinkertn@umich.edu * Copyright (c) 2001-2006 The Regents of The University of Michigan 152SN/A * All rights reserved. 162SN/A * 172SN/A * Redistribution and use in source and binary forms, with or without 182SN/A * modification, are permitted provided that the following conditions are 192SN/A * met: redistributions of source code must retain the above copyright 202SN/A * notice, this list of conditions and the following disclaimer; 212SN/A * redistributions in binary form must reproduce the above copyright 222SN/A * notice, this list of conditions and the following disclaimer in the 232SN/A * documentation and/or other materials provided with the distribution; 242SN/A * neither the name of the copyright holders nor the names of its 252SN/A * contributors may be used to endorse or promote products derived from 262SN/A * this software without specific prior written permission. 272SN/A * 282SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu * 402665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 412665Ssaidi@eecs.umich.edu * Steve Reinhardt 422SN/A */ 432SN/A 441354SN/A#ifndef __BASE_TRACE_HH__ 451354SN/A#define __BASE_TRACE_HH__ 462SN/A 474046Sbinkertn@umich.edu#include <string> 482SN/A 4956SN/A#include "base/cprintf.hh" 508232Snate@binkert.org#include "base/debug.hh" 511031SN/A#include "base/match.hh" 526214Snate@binkert.org#include "base/types.hh" 534167Sbinkertn@umich.edu#include "sim/core.hh" 542SN/A 552SN/Anamespace Trace { 562SN/A 578232Snate@binkert.orgusing Debug::SimpleFlag; 588232Snate@binkert.orgusing Debug::CompoundFlag; 598232Snate@binkert.org 604046Sbinkertn@umich.edustd::ostream &output(); 614046Sbinkertn@umich.eduvoid setOutput(const std::string &filename); 622SN/A 634046Sbinkertn@umich.eduextern bool enabled; 644046Sbinkertn@umich.edubool changeFlag(const char *str, bool value); 654046Sbinkertn@umich.eduvoid dumpStatus(); 662SN/A 674046Sbinkertn@umich.eduextern ObjectMatch ignore; 684046Sbinkertn@umich.eduextern const std::string DefaultName; 692SN/A 7010292SAndreas.Sandberg@ARM.combool __dprintf_prologue(Tick when, const std::string &name); 7110292SAndreas.Sandberg@ARM.com 7210292SAndreas.Sandberg@ARM.comtemplate<typename ...Args> void 7310292SAndreas.Sandberg@ARM.comdprintf(Tick when, const std::string &name, const char *format, 7410292SAndreas.Sandberg@ARM.com const Args &...args) 7510292SAndreas.Sandberg@ARM.com{ 7610292SAndreas.Sandberg@ARM.com if (!__dprintf_prologue(when, name)) 7710292SAndreas.Sandberg@ARM.com return; 7810292SAndreas.Sandberg@ARM.com 7910292SAndreas.Sandberg@ARM.com std::ostream &os(output()); 8010292SAndreas.Sandberg@ARM.com ccprintf(os, format, args...); 8110292SAndreas.Sandberg@ARM.com os.flush(); 8210292SAndreas.Sandberg@ARM.com} 8310292SAndreas.Sandberg@ARM.com 844046Sbinkertn@umich.eduvoid dump(Tick when, const std::string &name, const void *data, int len); 852SN/A 867811Ssteve.reinhardt@amd.com} // namespace Trace 874039Sbinkertn@umich.edu 881070SN/A// This silly little class allows us to wrap a string in a functor 891070SN/A// object so that we can give a name() that DPRINTF will like 901070SN/Astruct StringWrap 911070SN/A{ 921070SN/A std::string str; 931070SN/A StringWrap(const std::string &s) : str(s) {} 941070SN/A const std::string &operator()() const { return str; } 951070SN/A}; 961070SN/A 972SN/Ainline const std::string &name() { return Trace::DefaultName; } 982SN/A 9910259SAndrew.Bardsley@arm.com// Interface for things with names. (cf. SimObject but without other 10010259SAndrew.Bardsley@arm.com// functionality). This is useful when using DPRINTF 10110259SAndrew.Bardsley@arm.comclass Named 10210259SAndrew.Bardsley@arm.com{ 10310259SAndrew.Bardsley@arm.com protected: 10410259SAndrew.Bardsley@arm.com const std::string _name; 10510259SAndrew.Bardsley@arm.com 10610259SAndrew.Bardsley@arm.com public: 10710259SAndrew.Bardsley@arm.com Named(const std::string &name_) : _name(name_) { } 10810259SAndrew.Bardsley@arm.com 10910259SAndrew.Bardsley@arm.com public: 11010259SAndrew.Bardsley@arm.com const std::string &name() const { return _name; } 11110259SAndrew.Bardsley@arm.com}; 11210259SAndrew.Bardsley@arm.com 1132SN/A// 1142SN/A// DPRINTF is a debugging trace facility that allows one to 1152SN/A// selectively enable tracing statements. To use DPRINTF, there must 1162SN/A// be a function or functor called name() that returns a const 1172SN/A// std::string & in the current scope. 1182SN/A// 1192SN/A// If you desire that the automatic printing not occur, use DPRINTFR 1202SN/A// (R for raw) 1212SN/A// 1222SN/A 1232SN/A#if TRACING_ON 1242SN/A 1258232Snate@binkert.org#define DTRACE(x) ((Debug::x) && Trace::enabled) 1262SN/A 1274041Sbinkertn@umich.edu#define DDUMP(x, data, count) do { \ 1288232Snate@binkert.org using namespace Debug; \ 1294041Sbinkertn@umich.edu if (DTRACE(x)) \ 1307823Ssteve.reinhardt@amd.com Trace::dump(curTick(), name(), data, count); \ 1312SN/A} while (0) 1322SN/A 1334041Sbinkertn@umich.edu#define DPRINTF(x, ...) do { \ 1348232Snate@binkert.org using namespace Debug; \ 1354041Sbinkertn@umich.edu if (DTRACE(x)) \ 1367823Ssteve.reinhardt@amd.com Trace::dprintf(curTick(), name(), __VA_ARGS__); \ 1372SN/A} while (0) 1382SN/A 1398232Snate@binkert.org#define DPRINTFS(x, s, ...) do { \ 1408232Snate@binkert.org using namespace Debug; \ 1415806Ssaidi@eecs.umich.edu if (DTRACE(x)) \ 1428232Snate@binkert.org Trace::dprintf(curTick(), s->name(), __VA_ARGS__); \ 1435806Ssaidi@eecs.umich.edu} while (0) 1445806Ssaidi@eecs.umich.edu 1454041Sbinkertn@umich.edu#define DPRINTFR(x, ...) do { \ 1468232Snate@binkert.org using namespace Debug; \ 1474041Sbinkertn@umich.edu if (DTRACE(x)) \ 1484041Sbinkertn@umich.edu Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \ 1492SN/A} while (0) 1502SN/A 1514046Sbinkertn@umich.edu#define DDUMPN(data, count) do { \ 1527823Ssteve.reinhardt@amd.com Trace::dump(curTick(), name(), data, count); \ 1534046Sbinkertn@umich.edu} while (0) 1544046Sbinkertn@umich.edu 1554041Sbinkertn@umich.edu#define DPRINTFN(...) do { \ 1567823Ssteve.reinhardt@amd.com Trace::dprintf(curTick(), name(), __VA_ARGS__); \ 1572SN/A} while (0) 1582SN/A 1594041Sbinkertn@umich.edu#define DPRINTFNR(...) do { \ 1604041Sbinkertn@umich.edu Trace::dprintf((Tick)-1, string(), __VA_ARGS__); \ 161507SN/A} while (0) 162507SN/A 1632SN/A#else // !TRACING_ON 1642SN/A 1652SN/A#define DTRACE(x) (false) 1664046Sbinkertn@umich.edu#define DDUMP(x, data, count) do {} while (0) 1674041Sbinkertn@umich.edu#define DPRINTF(x, ...) do {} while (0) 1685806Ssaidi@eecs.umich.edu#define DPRINTFS(x, ...) do {} while (0) 1694041Sbinkertn@umich.edu#define DPRINTFR(...) do {} while (0) 1704046Sbinkertn@umich.edu#define DDUMPN(data, count) do {} while (0) 1714041Sbinkertn@umich.edu#define DPRINTFN(...) do {} while (0) 1724041Sbinkertn@umich.edu#define DPRINTFNR(...) do {} while (0) 1732SN/A 1745543Ssaidi@eecs.umich.edu#endif // TRACING_ON 1752SN/A 1761354SN/A#endif // __BASE_TRACE_HH__ 177