11917SN/A/* 21917SN/A * Copyright (c) 2005 The Regents of The University of Michigan 31917SN/A * All rights reserved. 41917SN/A * 51917SN/A * Redistribution and use in source and binary forms, with or without 61917SN/A * modification, are permitted provided that the following conditions are 71917SN/A * met: redistributions of source code must retain the above copyright 81917SN/A * notice, this list of conditions and the following disclaimer; 91917SN/A * redistributions in binary form must reproduce the above copyright 101917SN/A * notice, this list of conditions and the following disclaimer in the 111917SN/A * documentation and/or other materials provided with the distribution; 121917SN/A * neither the name of the copyright holders nor the names of its 131917SN/A * contributors may be used to endorse or promote products derived from 141917SN/A * this software without specific prior written permission. 151917SN/A * 161917SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171917SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181917SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191917SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201917SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211917SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221917SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231917SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241917SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251917SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261917SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 291917SN/A */ 301917SN/A 311917SN/A#ifndef __CPU_PROFILE_HH__ 321917SN/A#define __CPU_PROFILE_HH__ 331917SN/A 341917SN/A#include <map> 351917SN/A 363570Sgblack@eecs.umich.edu#include "arch/stacktrace.hh" 378229Snate@binkert.org#include "base/types.hh" 386658Snate@binkert.org#include "config/the_isa.hh" 391917SN/A#include "cpu/static_inst.hh" 401917SN/A 412680Sktlim@umich.educlass ThreadContext; 422235SN/A 431917SN/Aclass ProfileNode 441917SN/A{ 451917SN/A private: 461917SN/A friend class FunctionProfile; 471917SN/A 481977SN/A typedef std::map<Addr, ProfileNode *> ChildList; 491917SN/A ChildList children; 501917SN/A 511917SN/A public: 521980SN/A Counter count; 531917SN/A 541917SN/A public: 551917SN/A ProfileNode(); 561917SN/A 571917SN/A void dump(const std::string &symbol, uint64_t id, 581917SN/A const SymbolTable *symtab, std::ostream &os) const; 591917SN/A void clear(); 601917SN/A}; 611917SN/A 621981SN/Aclass Callback; 631917SN/Aclass FunctionProfile 641917SN/A{ 651917SN/A private: 661981SN/A Callback *reset; 671917SN/A const SymbolTable *symtab; 681917SN/A ProfileNode top; 691917SN/A std::map<Addr, Counter> pc_count; 703570Sgblack@eecs.umich.edu TheISA::StackTrace trace; 711917SN/A 721917SN/A public: 731917SN/A FunctionProfile(const SymbolTable *symtab); 741917SN/A ~FunctionProfile(); 751917SN/A 7610417Sandreas.hansson@arm.com ProfileNode *consume(ThreadContext *tc, const StaticInstPtr &inst); 771977SN/A ProfileNode *consume(const std::vector<Addr> &stack); 781917SN/A void clear(); 792680Sktlim@umich.edu void dump(ThreadContext *tc, std::ostream &out) const; 801917SN/A void sample(ProfileNode *node, Addr pc); 811917SN/A}; 821917SN/A 831977SN/Ainline ProfileNode * 8410417Sandreas.hansson@arm.comFunctionProfile::consume(ThreadContext *tc, const StaticInstPtr &inst) 851977SN/A{ 862680Sktlim@umich.edu if (!trace.trace(tc, inst)) 871977SN/A return NULL; 881977SN/A trace.dprintf(); 891977SN/A return consume(trace.getstack()); 901977SN/A} 911977SN/A 921917SN/A#endif // __CPU_PROFILE_HH__ 93