gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
40namespace gem5
41{
42
43class ThreadContext;
44class FunctionProfile;
45
46namespace 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:
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,
143
146 void clear();
147 void dump(std::ostream &out) const;
148 void sample(ProfileNode *node, Addr pc);
149};
150
151inline 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__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
std::vector< Addr > stack
Definition profile.hh:58
const std::vector< Addr > & getstack() const
Definition profile.hh:90
ThreadContext * tc
Definition profile.hh:57
virtual void trace(ThreadContext *tc, bool is_call)=0
bool trace(ThreadContext *tc, const StaticInstPtr &inst)
Definition profile.hh:78
bool valid() const
Definition profile.hh:75
virtual ~BaseStackTrace()
Definition profile.hh:66
void getSymbol(std::string &symbol, Addr addr, const loader::SymbolTable *symtab)
Definition profile.hh:105
virtual bool tryGetSymbol(std::string &symbol, Addr addr, const loader::SymbolTable *symtab)
Definition profile.cc:60
const loader::SymbolTable & symtab
Definition profile.hh:135
ProfileNode * consume(ThreadContext *tc, const StaticInstPtr &inst)
Definition profile.hh:152
std::map< Addr, Counter > pc_count
Definition profile.hh:137
FunctionProfile(std::unique_ptr< BaseStackTrace > _trace, const loader::SymbolTable &symtab)
Definition profile.cc:99
std::unique_ptr< BaseStackTrace > trace
Definition profile.hh:138
void sample(ProfileNode *node, Addr pc)
Definition profile.cc:148
std::map< Addr, ProfileNode * > ChildList
Definition profile.hh:118
ChildList children
Definition profile.hh:119
bool isReturn() const
bool isCall() const
ThreadContext is the external interface to all thread state for anything outside of the CPU.
STL vector class.
Definition stl.hh:37
#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
Bitfield< 4 > pc
Bitfield< 17, 16 > stack
Definition misc.hh:602
Bitfield< 17 > os
Definition misc.hh:838
Bitfield< 3 > addr
Definition types.hh:84
double Counter
All counters are of 64-bit values.
Definition types.hh:46
void dump()
Dump all statistics data to the registered outputs.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0