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.
| 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 <string> 30 31#include "base/bitfield.hh" 32#include "base/callback.hh" 33#include "base/statistics.hh" 34#include "base/trace.hh" 35#include "base/loader/symtab.hh" 36#include "cpu/base.hh" 37#include "cpu/exec_context.hh" 38#include "cpu/profile.hh" 39 40using namespace std; 41 42ProfileNode::ProfileNode() 43 : count(0) 44{ } 45 46void 47ProfileNode::dump(const string &symbol, uint64_t id, const SymbolTable *symtab, 48 ostream &os) const 49{ 50 ccprintf(os, "%#x %s %d ", id, symbol, count); 51 ChildList::const_iterator i, end = children.end(); 52 for (i = children.begin(); i != end; ++i) { 53 const ProfileNode *node = i->second; 54 ccprintf(os, "%#x ", (intptr_t)node); 55 } 56 57 ccprintf(os, "\n"); 58 59 for (i = children.begin(); i != end; ++i) { 60 Addr addr = i->first; 61 string symbol; 62 if (addr == 1) 63 symbol = "user"; 64 else if (addr == 2) 65 symbol = "console"; 66 else if (addr == 3) 67 symbol = "unknown"; 68 else if (!symtab->findSymbol(addr, symbol)) 69 panic("could not find symbol for address %#x\n", addr); 70 71 const ProfileNode *node = i->second; 72 node->dump(symbol, (intptr_t)node, symtab, os); 73 } 74} 75 76void 77ProfileNode::clear() 78{ 79 count = 0; 80 ChildList::iterator i, end = children.end(); 81 for (i = children.begin(); i != end; ++i) 82 i->second->clear(); 83} 84 85FunctionProfile::FunctionProfile(const SymbolTable *_symtab) 86 : reset(0), symtab(_symtab) 87{ 88 reset = new MakeCallback<FunctionProfile, &FunctionProfile::clear>(this); 89 Stats::registerResetCallback(reset); 90} 91 92FunctionProfile::~FunctionProfile() 93{ 94 if (reset) 95 delete reset; 96} 97 98ProfileNode * 99FunctionProfile::consume(const vector<Addr> &stack) 100{ 101 ProfileNode *current = ⊤ 102 for (int i = 0, size = stack.size(); i < size; ++i) { 103 ProfileNode *&ptr = current->children[stack[size - i - 1]]; 104 if (ptr == NULL) 105 ptr = new ProfileNode; 106 107 current = ptr; 108 } 109 110 return current; 111} 112 113void 114FunctionProfile::clear() 115{ 116 top.clear(); 117 pc_count.clear(); 118} 119 120void 121FunctionProfile::dump(ExecContext *xc, ostream &os) const 122{ 123 ccprintf(os, ">>>PC data\n"); 124 map<Addr, Counter>::const_iterator i, end = pc_count.end(); 125 for (i = pc_count.begin(); i != end; ++i) { 126 Addr pc = i->first; 127 Counter count = i->second; 128 129 std::string symbol; 130 if (pc == 1) 131 ccprintf(os, "user %d\n", count); 132 else if (symtab->findSymbol(pc, symbol) && !symbol.empty()) 133 ccprintf(os, "%s %d\n", symbol, count); 134 else 135 ccprintf(os, "%#x %d\n", pc, count); 136 } 137 138 ccprintf(os, ">>>function data\n"); 139 top.dump("top", 0, symtab, os); 140} 141 142void 143FunctionProfile::sample(ProfileNode *node, Addr pc) 144{ 145 node->count++; 146 147 Addr symaddr; 148 if (symtab->findNearestAddr(pc, symaddr)) { 149 pc_count[symaddr]++; 150 } else { 151 // record PC even if we don't have a symbol to avoid 152 // silently biasing the histogram 153 pc_count[pc]++; 154 } 155}
| 29 */ 30 31#include <string> 32 33#include "base/bitfield.hh" 34#include "base/callback.hh" 35#include "base/statistics.hh" 36#include "base/trace.hh" 37#include "base/loader/symtab.hh" 38#include "cpu/base.hh" 39#include "cpu/exec_context.hh" 40#include "cpu/profile.hh" 41 42using namespace std; 43 44ProfileNode::ProfileNode() 45 : count(0) 46{ } 47 48void 49ProfileNode::dump(const string &symbol, uint64_t id, const SymbolTable *symtab, 50 ostream &os) const 51{ 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); 57 } 58 59 ccprintf(os, "\n"); 60 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 (!symtab->findSymbol(addr, symbol)) 71 panic("could not find symbol for address %#x\n", addr); 72 73 const ProfileNode *node = i->second; 74 node->dump(symbol, (intptr_t)node, symtab, os); 75 } 76} 77 78void 79ProfileNode::clear() 80{ 81 count = 0; 82 ChildList::iterator i, end = children.end(); 83 for (i = children.begin(); i != end; ++i) 84 i->second->clear(); 85} 86 87FunctionProfile::FunctionProfile(const SymbolTable *_symtab) 88 : reset(0), symtab(_symtab) 89{ 90 reset = new MakeCallback<FunctionProfile, &FunctionProfile::clear>(this); 91 Stats::registerResetCallback(reset); 92} 93 94FunctionProfile::~FunctionProfile() 95{ 96 if (reset) 97 delete reset; 98} 99 100ProfileNode * 101FunctionProfile::consume(const vector<Addr> &stack) 102{ 103 ProfileNode *current = ⊤ 104 for (int i = 0, size = stack.size(); i < size; ++i) { 105 ProfileNode *&ptr = current->children[stack[size - i - 1]]; 106 if (ptr == NULL) 107 ptr = new ProfileNode; 108 109 current = ptr; 110 } 111 112 return current; 113} 114 115void 116FunctionProfile::clear() 117{ 118 top.clear(); 119 pc_count.clear(); 120} 121 122void 123FunctionProfile::dump(ExecContext *xc, ostream &os) const 124{ 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) { 128 Addr pc = i->first; 129 Counter count = i->second; 130 131 std::string symbol; 132 if (pc == 1) 133 ccprintf(os, "user %d\n", count); 134 else if (symtab->findSymbol(pc, symbol) && !symbol.empty()) 135 ccprintf(os, "%s %d\n", symbol, count); 136 else 137 ccprintf(os, "%#x %d\n", pc, count); 138 } 139 140 ccprintf(os, ">>>function data\n"); 141 top.dump("top", 0, symtab, os); 142} 143 144void 145FunctionProfile::sample(ProfileNode *node, Addr pc) 146{ 147 node->count++; 148 149 Addr symaddr; 150 if (symtab->findNearestAddr(pc, symaddr)) { 151 pc_count[symaddr]++; 152 } else { 153 // record PC even if we don't have a symbol to avoid 154 // silently biasing the histogram 155 pc_count[pc]++; 156 } 157}
|