gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 namespace loader
47 {
48  class SymbolTable;
49 } // namespace loader
50 
52 {
53  private:
54  void dump();
55 
56  protected:
57  ThreadContext *tc = nullptr;
59 
60  // Subclasses should implement this function so that it collects the
61  // the current and return addresses on the stack in the "stack" vector.
62  virtual void trace(ThreadContext *tc, bool is_call) = 0;
63 
64  public:
65  BaseStackTrace() : stack(64) {}
66  virtual ~BaseStackTrace() {}
67 
68  void
70  {
71  tc = nullptr;
72  stack.clear();
73  }
74 
75  bool valid() const { return tc; }
76 
77  bool
79  {
80  if (!inst->isCall() && !inst->isReturn())
81  return false;
82 
83  if (valid())
84  clear();
85 
86  trace(tc, !inst->isReturn());
87  return true;
88  }
89 
90  const std::vector<Addr> &getstack() const { return stack; }
91 
92  void dprintf() { if (debug::Stack) dump(); }
93 
94  // This function can be overridden so that special addresses which don't
95  // actually refer to PCs can be translated into special names. For
96  // instance, the address 1 could translate into "user" for user level
97  // code when the symbol table only has kernel symbols.
98  //
99  // It should return whether addr was recognized and symbol has been set to
100  // something.
101  virtual bool tryGetSymbol(std::string &symbol, Addr addr,
102  const loader::SymbolTable *symtab);
103 
104  void
105  getSymbol(std::string &symbol, Addr addr,
106  const loader::SymbolTable *symtab)
107  {
108  panic_if(!tryGetSymbol(symbol, addr, symtab),
109  "Could not find symbol for address %#x\n", addr);
110  }
111 };
112 
114 {
115  private:
116  friend class FunctionProfile;
117 
118  typedef std::map<Addr, ProfileNode *> ChildList;
120 
121  public:
123 
124  public:
125  void dump(const std::string &symbol, uint64_t id,
126  const FunctionProfile &prof, std::ostream &os) const;
127  void clear();
128 };
129 
131 {
132  private:
133  friend class ProfileNode;
134 
137  std::map<Addr, Counter> pc_count;
138  std::unique_ptr<BaseStackTrace> trace;
139 
140  public:
141  FunctionProfile(std::unique_ptr<BaseStackTrace> _trace,
142  const loader::SymbolTable &symtab);
143 
144  ProfileNode *consume(ThreadContext *tc, const StaticInstPtr &inst);
146  void clear();
147  void dump(std::ostream &out) const;
148  void sample(ProfileNode *node, Addr pc);
149 };
150 
151 inline ProfileNode *
153 {
154  if (!trace->trace(tc, inst))
155  return nullptr;
156  trace->dprintf();
157  return consume(trace->getstack());
158 }
159 
160 } // namespace gem5
161 
162 #endif // __CPU_PROFILE_HH__
gem5::BaseStackTrace::getstack
const std::vector< Addr > & getstack() const
Definition: profile.hh:90
gem5::FunctionProfile::clear
void clear()
Definition: profile.cc:122
gem5::BaseStackTrace::stack
std::vector< Addr > stack
Definition: profile.hh:58
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:130
gem5::loader::SymbolTable
Definition: symtab.hh:64
gem5::FunctionProfile::pc_count
std::map< Addr, Counter > pc_count
Definition: profile.hh:137
std::vector< Addr >
gem5::ProfileNode::clear
void clear()
Definition: profile.cc:92
gem5::ProfileNode::count
Counter count
Definition: profile.hh:122
gem5::FunctionProfile::top
ProfileNode top
Definition: profile.hh:136
gem5::BaseStackTrace::clear
void clear()
Definition: profile.hh:69
gem5::RefCountingPtr< StaticInst >
gem5::BaseStackTrace::valid
bool valid() const
Definition: profile.hh:75
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:162
gem5::BaseStackTrace::~BaseStackTrace
virtual ~BaseStackTrace()
Definition: profile.hh:66
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
gem5::X86ISA::stack
Bitfield< 17, 16 > stack
Definition: misc.hh:592
gem5::ProfileNode
Definition: profile.hh:113
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::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:214
gem5::BaseStackTrace::trace
bool trace(ThreadContext *tc, const StaticInstPtr &inst)
Definition: profile.hh:78
types.hh
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:810
gem5::BaseStackTrace::tc
ThreadContext * tc
Definition: profile.hh:57
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:46
logging.hh
gem5::StaticInst::isCall
bool isCall() const
Definition: static_inst.hh:161
gem5::ProfileNode::children
ChildList children
Definition: profile.hh:119
gem5::BaseStackTrace::trace
virtual void trace(ThreadContext *tc, bool is_call)=0
gem5::FunctionProfile::trace
std::unique_ptr< BaseStackTrace > trace
Definition: profile.hh:138
gem5::ProfileNode::ChildList
std::map< Addr, ProfileNode * > ChildList
Definition: profile.hh:118
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::BaseStackTrace
Definition: profile.hh:51
gem5::BaseStackTrace::BaseStackTrace
BaseStackTrace()
Definition: profile.hh:65
gem5::BaseStackTrace::dump
void dump()
Definition: profile.cc:44
gem5::BaseStackTrace::dprintf
void dprintf()
Definition: profile.hh:92
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:152
gem5::BaseStackTrace::getSymbol
void getSymbol(std::string &symbol, Addr addr, const loader::SymbolTable *symtab)
Definition: profile.hh:105
gem5::FunctionProfile::symtab
const loader::SymbolTable & symtab
Definition: profile.hh:135
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Sun Jul 30 2023 01:56:53 for gem5 by doxygen 1.8.17