79ae22ca1054d7f4cdb3556564a3754ba0937d10
2 * Copyright (c) 2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Nathan Binkert
33 #include "base/loader/symtab.hh"
34 #include "base/bitfield.hh"
35 #include "base/callback.hh"
36 #include "base/statistics.hh"
37 #include "base/trace.hh"
38 #include "cpu/base.hh"
39 #include "cpu/profile.hh"
40 #include "cpu/thread_context.hh"
44 ProfileNode::ProfileNode()
49 ProfileNode::dump(const string
&symbol
, uint64_t id
, const SymbolTable
*symtab
,
52 ccprintf(os
, "%#x %s %d ", id
, symbol
, count
);
53 ChildList::const_iterator i
, end
= children
.end();
54 for (i
= children
.begin(); i
!= end
; ++i
) {
55 const ProfileNode
*node
= i
->second
;
56 ccprintf(os
, "%#x ", (intptr_t)node
);
61 for (i
= children
.begin(); i
!= end
; ++i
) {
70 else if (!symtab
->findSymbol(addr
, symbol
))
71 panic("could not find symbol for address %#x\n", addr
);
73 const ProfileNode
*node
= i
->second
;
74 node
->dump(symbol
, (intptr_t)node
, symtab
, os
);
82 ChildList::iterator i
, end
= children
.end();
83 for (i
= children
.begin(); i
!= end
; ++i
)
87 FunctionProfile::FunctionProfile(const SymbolTable
*_symtab
)
88 : reset(0), symtab(_symtab
)
90 reset
= new MakeCallback
<FunctionProfile
, &FunctionProfile::clear
>(this);
91 Stats::registerResetCallback(reset
);
94 FunctionProfile::~FunctionProfile()
101 FunctionProfile::consume(const vector
<Addr
> &stack
)
103 ProfileNode
*current
= &top
;
104 for (int i
= 0, size
= stack
.size(); i
< size
; ++i
) {
105 ProfileNode
*&ptr
= current
->children
[stack
[size
- i
- 1]];
107 ptr
= new ProfileNode
;
116 FunctionProfile::clear()
123 FunctionProfile::dump(ThreadContext
*tc
, ostream
&os
) const
125 ccprintf(os
, ">>>PC data\n");
126 map
<Addr
, Counter
>::const_iterator i
, end
= pc_count
.end();
127 for (i
= pc_count
.begin(); i
!= end
; ++i
) {
129 Counter count
= i
->second
;
133 ccprintf(os
, "user %d\n", count
);
134 else if (symtab
->findSymbol(pc
, symbol
) && !symbol
.empty())
135 ccprintf(os
, "%s %d\n", symbol
, count
);
137 ccprintf(os
, "%#x %d\n", pc
, count
);
140 ccprintf(os
, ">>>function data\n");
141 top
.dump("top", 0, symtab
, os
);
145 FunctionProfile::sample(ProfileNode
*node
, Addr pc
)
150 if (symtab
->findNearestAddr(pc
, symaddr
)) {
153 // record PC even if we don't have a symbol to avoid
154 // silently biasing the histogram