profile.hh revision 6214
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" 371917SN/A#include "cpu/static_inst.hh" 386214Snate@binkert.org#include "base/types.hh" 391917SN/A 402680Sktlim@umich.educlass ThreadContext; 412235SN/A 421917SN/Aclass ProfileNode 431917SN/A{ 441917SN/A private: 451917SN/A friend class FunctionProfile; 461917SN/A 471977SN/A typedef std::map<Addr, ProfileNode *> ChildList; 481917SN/A ChildList children; 491917SN/A 501917SN/A public: 511980SN/A Counter count; 521917SN/A 531917SN/A public: 541917SN/A ProfileNode(); 551917SN/A 561917SN/A void dump(const std::string &symbol, uint64_t id, 571917SN/A const SymbolTable *symtab, std::ostream &os) const; 581917SN/A void clear(); 591917SN/A}; 601917SN/A 611981SN/Aclass Callback; 621917SN/Aclass FunctionProfile 631917SN/A{ 641917SN/A private: 651981SN/A Callback *reset; 661917SN/A const SymbolTable *symtab; 671917SN/A ProfileNode top; 681917SN/A std::map<Addr, Counter> pc_count; 693570Sgblack@eecs.umich.edu TheISA::StackTrace trace; 701917SN/A 711917SN/A public: 721917SN/A FunctionProfile(const SymbolTable *symtab); 731917SN/A ~FunctionProfile(); 741917SN/A 752680Sktlim@umich.edu ProfileNode *consume(ThreadContext *tc, StaticInstPtr inst); 761977SN/A ProfileNode *consume(const std::vector<Addr> &stack); 771917SN/A void clear(); 782680Sktlim@umich.edu void dump(ThreadContext *tc, std::ostream &out) const; 791917SN/A void sample(ProfileNode *node, Addr pc); 801917SN/A}; 811917SN/A 821977SN/Ainline ProfileNode * 832680Sktlim@umich.eduFunctionProfile::consume(ThreadContext *tc, StaticInstPtr inst) 841977SN/A{ 852680Sktlim@umich.edu if (!trace.trace(tc, inst)) 861977SN/A return NULL; 871977SN/A trace.dprintf(); 881977SN/A return consume(trace.getstack()); 891977SN/A} 901977SN/A 911917SN/A#endif // __CPU_PROFILE_HH__ 92