gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
profile.cc
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 #include "cpu/profile.hh"
30 
31 #include <string>
32 
33 #include "base/bitfield.hh"
34 #include "base/callback.hh"
35 #include "base/loader/symtab.hh"
36 #include "base/statistics.hh"
37 #include "base/trace.hh"
38 #include "cpu/base.hh"
39 #include "cpu/thread_context.hh"
40 
41 using namespace std;
42 
44  : count(0)
45 { }
46 
47 void
48 ProfileNode::dump(const string &symbol, uint64_t id,
49  const Loader::SymbolTable *symtab, ostream &os) const
50 {
51  ccprintf(os, "%#x %s %d ", id, symbol, count);
52  ChildList::const_iterator i, end = children.end();
53  for (i = children.begin(); i != end; ++i) {
54  const ProfileNode *node = i->second;
55  ccprintf(os, "%#x ", (intptr_t)node);
56  }
57 
58  ccprintf(os, "\n");
59 
61  for (i = children.begin(); i != end; ++i) {
62  Addr addr = i->first;
63  string symbol;
64  if (addr == 1)
65  symbol = "user";
66  else if (addr == 2)
67  symbol = "console";
68  else if (addr == 3)
69  symbol = "unknown";
70  else if ((it = symtab->find(addr)) != symtab->end())
71  symbol = it->name;
72  else
73  panic("could not find symbol for address %#x\n", addr);
74 
75  const ProfileNode *node = i->second;
76  node->dump(symbol, (intptr_t)node, symtab, os);
77  }
78 }
79 
80 void
82 {
83  count = 0;
84  ChildList::iterator i, end = children.end();
85  for (i = children.begin(); i != end; ++i)
86  i->second->clear();
87 }
88 
90  : reset(0), symtab(_symtab)
91 {
94 }
95 
97 {
98  if (reset)
99  delete reset;
100 }
101 
102 ProfileNode *
104 {
105  ProfileNode *current = &top;
106  for (int i = 0, size = stack.size(); i < size; ++i) {
107  ProfileNode *&ptr = current->children[stack[size - i - 1]];
108  if (ptr == NULL)
109  ptr = new ProfileNode;
110 
111  current = ptr;
112  }
113 
114  return current;
115 }
116 
117 void
119 {
120  top.clear();
121  pc_count.clear();
122 }
123 
124 void
126 {
127  ccprintf(os, ">>>PC data\n");
128  map<Addr, Counter>::const_iterator i, end = pc_count.end();
129  for (i = pc_count.begin(); i != end; ++i) {
130  Addr pc = i->first;
131  Counter count = i->second;
132 
134  if (pc == 1) {
135  ccprintf(os, "user %d\n", count);
136  } else if ((it = symtab->find(pc)) != symtab->end() &&
137  !it->name.empty()) {
138  ccprintf(os, "%s %d\n", it->name, count);
139  } else {
140  ccprintf(os, "%#x %d\n", pc, count);
141  }
142  }
143 
144  ccprintf(os, ">>>function data\n");
145  top.dump("top", 0, symtab, os);
146 }
147 
148 void
150 {
151  node->count++;
152 
153  auto it = symtab->findNearest(pc);
154  if (it != symtab->end()) {
155  pc_count[it->address]++;
156  } else {
157  // record PC even if we don't have a symbol to avoid
158  // silently biasing the histogram
159  pc_count[pc]++;
160  }
161 }
count
Definition: misc.hh:703
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
const Loader::SymbolTable * symtab
Definition: profile.hh:65
Counter count
Definition: profile.hh:50
Definition: test.h:61
void sample(ProfileNode *node, Addr pc)
Definition: profile.cc:149
Bitfield< 7 > i
const_iterator findNearest(Addr addr, Addr &nextaddr) const
Find the nearest symbol equal to or less than the supplied address (e.g., the label for the enclosing...
Definition: symtab.hh:209
std::map< Addr, Counter > pc_count
Definition: profile.hh:67
ChildList children
Definition: profile.hh:47
ip6_addr_t addr
Definition: inet.hh:330
void reset()
Definition: statistics.cc:569
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
void clear()
Definition: profile.cc:81
const_iterator end() const
Definition: symtab.hh:126
ProfileNode top
Definition: profile.hh:66
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Declaration of Statistics objects.
Bitfield< 17 > os
Definition: misc.hh:803
FunctionProfile(const Loader::SymbolTable *symtab)
Definition: profile.cc:89
ProfileNode()
Definition: profile.cc:43
Bitfield< 4 > pc
void clear()
Definition: profile.cc:118
void dump(ThreadContext *tc, std::ostream &out) const
Definition: profile.cc:125
void registerResetCallback(Callback *cb)
Register a callback that should be called whenever statistics are reset.
Definition: statistics.cc:537
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
Callback * reset
Definition: profile.hh:64
int64_t Counter
Statistics counter type.
Definition: types.hh:56
Bitfield< 17, 16 > stack
Definition: misc.hh:587
SymbolVector::const_iterator const_iterator
Definition: symtab.hh:123
void dump(const std::string &symbol, uint64_t id, const Loader::SymbolTable *symtab, std::ostream &os) const
Definition: profile.cc:48
const_iterator find(Addr address) const
Definition: symtab.hh:181
Helper template class to turn a simple class member function into a callback.
Definition: callback.hh:62
ProfileNode * consume(ThreadContext *tc, const StaticInstPtr &inst)
Definition: profile.hh:82

Generated on Mon Jun 8 2020 15:45:09 for gem5 by doxygen 1.8.13