gem5  v21.1.0.2
profile.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __CPU_PROFILE_HH__
30 #define __CPU_PROFILE_HH__
31 
32 #include <map>
33 #include <string>
34 
35 #include "base/logging.hh"
36 #include "base/types.hh"
37 #include "cpu/static_inst.hh"
38 #include "debug/Stack.hh"
39 
40 namespace gem5
41 {
42 
43 class ThreadContext;
44 class FunctionProfile;
45 
46 GEM5_DEPRECATED_NAMESPACE(Loader, loader);
47 namespace loader
48 {
49  class SymbolTable;
50 } // namespace loader
51 
53 {
54  private:
55  void dump();
56 
57  protected:
58  ThreadContext *tc = nullptr;
60 
61  // Subclasses should implement this function so that it collects the
62  // the current and return addresses on the stack in the "stack" vector.
63  virtual void trace(ThreadContext *tc, bool is_call) = 0;
64 
65  public:
66  BaseStackTrace() : stack(64) {}
67  virtual ~BaseStackTrace() {}
68 
69  void
71  {
72  tc = nullptr;
73  stack.clear();
74  }
75 
76  bool valid() const { return tc; }
77 
78  bool
80  {
81  if (!inst->isCall() && !inst->isReturn())
82  return false;
83 
84  if (valid())
85  clear();
86 
87  trace(tc, !inst->isReturn());
88  return true;
89  }
90 
91  const std::vector<Addr> &getstack() const { return stack; }
92 
93  void dprintf() { if (debug::Stack) dump(); }
94 
95  // This function can be overridden so that special addresses which don't
96  // actually refer to PCs can be translated into special names. For
97  // instance, the address 1 could translate into "user" for user level
98  // code when the symbol table only has kernel symbols.
99  //
100  // It should return whether addr was recognized and symbol has been set to
101  // something.
102  virtual bool tryGetSymbol(std::string &symbol, Addr addr,
103  const loader::SymbolTable *symtab);
104 
105  void
106  getSymbol(std::string &symbol, Addr addr,
107  const loader::SymbolTable *symtab)
108  {
109  panic_if(!tryGetSymbol(symbol, addr, symtab),
110  "Could not find symbol for address %#x\n", addr);
111  }
112 };
113 
115 {
116  private:
117  friend class FunctionProfile;
118 
119  typedef std::map<Addr, ProfileNode *> ChildList;
121 
122  public:
124 
125  public:
126  void dump(const std::string &symbol, uint64_t id,
127  const FunctionProfile &prof, std::ostream &os) const;
128  void clear();
129 };
130 
132 {
133  private:
134  friend class ProfileNode;
135 
138  std::map<Addr, Counter> pc_count;
139  std::unique_ptr<BaseStackTrace> trace;
140 
141  public:
142  FunctionProfile(std::unique_ptr<BaseStackTrace> _trace,
143  const loader::SymbolTable &symtab);
144 
145  ProfileNode *consume(ThreadContext *tc, const StaticInstPtr &inst);
147  void clear();
148  void dump(std::ostream &out) const;
149  void sample(ProfileNode *node, Addr pc);
150 };
151 
152 inline ProfileNode *
154 {
155  if (!trace->trace(tc, inst))
156  return nullptr;
157  trace->dprintf();
158  return consume(trace->getstack());
159 }
160 
161 } // namespace gem5
162 
163 #endif // __CPU_PROFILE_HH__
gem5::BaseStackTrace::getstack
const std::vector< Addr > & getstack() const
Definition: profile.hh:91
gem5::FunctionProfile::clear
void clear()
Definition: profile.cc:122
gem5::BaseStackTrace::stack
std::vector< Addr > stack
Definition: profile.hh:59
gem5::ProfileNode::dump
void dump(const std::string &symbol, uint64_t id, const FunctionProfile &prof, std::ostream &os) const
Definition: profile.cc:71
gem5::FunctionProfile::sample
void sample(ProfileNode *node, Addr pc)
Definition: profile.cc:148
gem5::FunctionProfile
Definition: profile.hh:131
gem5::loader::SymbolTable
Definition: symtab.hh:65
gem5::FunctionProfile::pc_count
std::map< Addr, Counter > pc_count
Definition: profile.hh:138
std::vector< Addr >
gem5::ProfileNode::clear
void clear()
Definition: profile.cc:92
gem5::ProfileNode::count
Counter count
Definition: profile.hh:123
gem5::FunctionProfile::top
ProfileNode top
Definition: profile.hh:137
gem5::BaseStackTrace::clear
void clear()
Definition: profile.hh:70
gem5::RefCountingPtr< StaticInst >
gem5::BaseStackTrace::valid
bool valid() const
Definition: profile.hh:76
gem5::BaseStackTrace::tryGetSymbol
virtual bool tryGetSymbol(std::string &symbol, Addr addr, const loader::SymbolTable *symtab)
Definition: profile.cc:60
gem5::StaticInst::isReturn
bool isReturn() const
Definition: static_inst.hh:184
gem5::BaseStackTrace::~BaseStackTrace
virtual ~BaseStackTrace()
Definition: profile.hh:67
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:93
gem5::X86ISA::stack
Bitfield< 17, 16 > stack
Definition: misc.hh:593
gem5::ProfileNode
Definition: profile.hh:114
static_inst.hh
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::FunctionProfile::dump
void dump(std::ostream &out) const
Definition: profile.cc:129
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:203
gem5::BaseStackTrace::trace
bool trace(ThreadContext *tc, const StaticInstPtr &inst)
Definition: profile.hh:79
types.hh
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:809
gem5::BaseStackTrace::tc
ThreadContext * tc
Definition: profile.hh:58
gem5::MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:243
gem5::statistics::Counter
double Counter
All counters are of 64-bit values.
Definition: types.hh:47
logging.hh
gem5::StaticInst::isCall
bool isCall() const
Definition: static_inst.hh:183
gem5::ProfileNode::children
ChildList children
Definition: profile.hh:120
gem5::BaseStackTrace::trace
virtual void trace(ThreadContext *tc, bool is_call)=0
gem5::FunctionProfile::trace
std::unique_ptr< BaseStackTrace > trace
Definition: profile.hh:139
gem5::ProfileNode::ChildList
std::map< Addr, ProfileNode * > ChildList
Definition: profile.hh:119
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::BaseStackTrace
Definition: profile.hh:52
gem5::BaseStackTrace::BaseStackTrace
BaseStackTrace()
Definition: profile.hh:66
gem5::BaseStackTrace::dump
void dump()
Definition: profile.cc:44
gem5::BaseStackTrace::dprintf
void dprintf()
Definition: profile.hh:93
gem5::FunctionProfile::FunctionProfile
FunctionProfile(std::unique_ptr< BaseStackTrace > _trace, const loader::SymbolTable &symtab)
Definition: profile.cc:99
gem5::FunctionProfile::consume
ProfileNode * consume(ThreadContext *tc, const StaticInstPtr &inst)
Definition: profile.hh:153
gem5::BaseStackTrace::getSymbol
void getSymbol(std::string &symbol, Addr addr, const loader::SymbolTable *symtab)
Definition: profile.hh:106
gem5::FunctionProfile::symtab
const loader::SymbolTable & symtab
Definition: profile.hh:136
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Tue Sep 21 2021 12:25:06 for gem5 by doxygen 1.8.17