gem5
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
cpu
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
* Authors: Nathan Binkert
29
*/
30
31
#include "
cpu/profile.hh
"
32
33
#include <string>
34
35
#include "
base/bitfield.hh
"
36
#include "
base/callback.hh
"
37
#include "
base/loader/symtab.hh
"
38
#include "
base/statistics.hh
"
39
#include "
base/trace.hh
"
40
#include "
cpu/base.hh
"
41
#include "
cpu/thread_context.hh
"
42
43
using namespace
std;
44
45
ProfileNode::ProfileNode
()
46
:
count
(0)
47
{ }
48
49
void
50
ProfileNode::dump
(
const
string
&symbol, uint64_t
id
,
const
SymbolTable
*symtab,
51
ostream &
os
)
const
52
{
53
ccprintf
(os,
"%#x %s %d "
,
id
, symbol,
count
);
54
ChildList::const_iterator
i
, end =
children
.end();
55
for
(i =
children
.begin(); i != end; ++
i
) {
56
const
ProfileNode
*node = i->second;
57
ccprintf
(os,
"%#x "
, (intptr_t)node);
58
}
59
60
ccprintf
(os,
"\n"
);
61
62
for
(i =
children
.begin(); i != end; ++
i
) {
63
Addr
addr
= i->first;
64
string
symbol;
65
if
(addr == 1)
66
symbol =
"user"
;
67
else
if
(addr == 2)
68
symbol =
"console"
;
69
else
if
(addr == 3)
70
symbol =
"unknown"
;
71
else
if
(!symtab->
findSymbol
(addr, symbol))
72
panic
(
"could not find symbol for address %#x\n"
, addr);
73
74
const
ProfileNode
*node = i->second;
75
node->
dump
(symbol, (intptr_t)node, symtab, os);
76
}
77
}
78
79
void
80
ProfileNode::clear
()
81
{
82
count
= 0;
83
ChildList::iterator
i
, end =
children
.end();
84
for
(i =
children
.begin(); i != end; ++
i
)
85
i->second->clear();
86
}
87
88
FunctionProfile::FunctionProfile
(
const
SymbolTable
*_symtab)
89
:
reset
(0), symtab(_symtab)
90
{
91
reset
=
new
MakeCallback<FunctionProfile, &FunctionProfile::clear>
(
this
);
92
Stats::registerResetCallback
(
reset
);
93
}
94
95
FunctionProfile::~FunctionProfile
()
96
{
97
if
(
reset
)
98
delete
reset
;
99
}
100
101
ProfileNode
*
102
FunctionProfile::consume
(
const
vector<Addr>
&
stack
)
103
{
104
ProfileNode
*current = &
top
;
105
for
(
int
i
= 0,
size
= stack.size();
i
<
size
; ++
i
) {
106
ProfileNode
*&ptr = current->
children
[stack[size -
i
- 1]];
107
if
(ptr == NULL)
108
ptr =
new
ProfileNode
;
109
110
current = ptr;
111
}
112
113
return
current;
114
}
115
116
void
117
FunctionProfile::clear
()
118
{
119
top
.
clear
();
120
pc_count
.clear();
121
}
122
123
void
124
FunctionProfile::dump
(
ThreadContext
*tc, ostream &
os
)
const
125
{
126
ccprintf
(os,
">>>PC data\n"
);
127
map<Addr, Counter>::const_iterator
i
, end =
pc_count
.end();
128
for
(i =
pc_count
.begin(); i != end; ++
i
) {
129
Addr
pc
= i->first;
130
Counter
count
= i->second;
131
132
std::string symbol;
133
if
(pc == 1)
134
ccprintf
(os,
"user %d\n"
, count);
135
else
if
(
symtab
->
findSymbol
(pc, symbol) && !symbol.empty())
136
ccprintf
(os,
"%s %d\n"
, symbol, count);
137
else
138
ccprintf
(os,
"%#x %d\n"
, pc, count);
139
}
140
141
ccprintf
(os,
">>>function data\n"
);
142
top
.
dump
(
"top"
, 0,
symtab
, os);
143
}
144
145
void
146
FunctionProfile::sample
(
ProfileNode
*node,
Addr
pc
)
147
{
148
node->
count
++;
149
150
Addr
symaddr;
151
if
(
symtab
->
findNearestAddr
(pc, symaddr)) {
152
pc_count
[symaddr]++;
153
}
else
{
154
// record PC even if we don't have a symbol to avoid
155
// silently biasing the histogram
156
pc_count
[
pc
]++;
157
}
158
}
X86ISA::count
count
Definition:
misc.hh:704
ccprintf
void ccprintf(cp::Print &print)
Definition:
cprintf.hh:130
ProfileNode::count
Counter count
Definition:
profile.hh:52
reset
cbk_rst func reset
Definition:
gpu_nomali.cc:101
FunctionProfile::dump
void dump(ThreadContext *tc, std::ostream &out) const
Definition:
profile.cc:124
FunctionProfile::FunctionProfile
FunctionProfile(const SymbolTable *symtab)
Definition:
profile.cc:88
FunctionProfile::sample
void sample(ProfileNode *node, Addr pc)
Definition:
profile.cc:146
ArmISA::i
Bitfield< 7 > i
Definition:
miscregs.hh:1378
profile.hh
panic
#define panic(...)
Definition:
misc.hh:153
FunctionProfile::pc_count
std::map< Addr, Counter > pc_count
Definition:
profile.hh:69
ProfileNode::children
ChildList children
Definition:
profile.hh:49
addr
ip6_addr_t addr
Definition:
inet.hh:335
base.hh
FunctionProfile::symtab
const SymbolTable * symtab
Definition:
profile.hh:67
SymbolTable
Definition:
symtab.hh:42
ProfileNode::clear
void clear()
Definition:
profile.cc:80
thread_context.hh
FunctionProfile::top
ProfileNode top
Definition:
profile.hh:68
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Definition:
thread_context.hh:93
statistics.hh
Declaration of Statistics objects.
X86ISA::os
Bitfield< 17 > os
Definition:
misc.hh:804
std::vector< Addr >
trace.hh
ProfileNode::ProfileNode
ProfileNode()
Definition:
profile.cc:45
FunctionProfile::clear
void clear()
Definition:
profile.cc:117
callback.hh
bitfield.hh
Stats::registerResetCallback
void registerResetCallback(Callback *cb)
Register a callback that should be called whenever statistics are reset.
Definition:
statistics.cc:494
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition:
types.hh:142
FunctionProfile::reset
Callback * reset
Definition:
profile.hh:66
Counter
int64_t Counter
Statistics counter type.
Definition:
types.hh:58
ProfileNode
Definition:
profile.hh:43
X86ISA::stack
Bitfield< 17, 16 > stack
Definition:
misc.hh:588
symtab.hh
X86ISA::size
int size()
Definition:
pagetable.hh:146
FunctionProfile::~FunctionProfile
~FunctionProfile()
Definition:
profile.cc:95
SymbolTable::findSymbol
bool findSymbol(Addr address, std::string &symbol) const
Definition:
symtab.hh:84
pc
IntReg pc
Definition:
remote_gdb.hh:91
MakeCallback
Helper template class to turn a simple class member function into a callback.
Definition:
callback.hh:64
FunctionProfile::consume
ProfileNode * consume(ThreadContext *tc, const StaticInstPtr &inst)
Definition:
profile.hh:84
ProfileNode::dump
void dump(const std::string &symbol, uint64_t id, const SymbolTable *symtab, std::ostream &os) const
Definition:
profile.cc:50
SymbolTable::findNearestAddr
bool findNearestAddr(Addr addr, Addr &symaddr, Addr &nextaddr) const
Definition:
symtab.hh:147
Generated on Fri Jun 9 2017 13:03:44 for gem5 by
doxygen
1.8.6