profile.hh revision 2235
16876Ssteve.reinhardt@amd.com/* 210089Sandreas.hansson@arm.com * Copyright (c) 2005 The Regents of The University of Michigan 38922Swilliam.wang@arm.com * All rights reserved. 48922Swilliam.wang@arm.com * 58922Swilliam.wang@arm.com * Redistribution and use in source and binary forms, with or without 68922Swilliam.wang@arm.com * modification, are permitted provided that the following conditions are 78922Swilliam.wang@arm.com * met: redistributions of source code must retain the above copyright 88922Swilliam.wang@arm.com * notice, this list of conditions and the following disclaimer; 98922Swilliam.wang@arm.com * redistributions in binary form must reproduce the above copyright 108922Swilliam.wang@arm.com * notice, this list of conditions and the following disclaimer in the 118922Swilliam.wang@arm.com * documentation and/or other materials provided with the distribution; 128922Swilliam.wang@arm.com * neither the name of the copyright holders nor the names of its 138922Swilliam.wang@arm.com * contributors may be used to endorse or promote products derived from 1411266SBrad.Beckmann@amd.com * this software without specific prior written permission. 158717Snilay@cs.wisc.edu * 166876Ssteve.reinhardt@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176876Ssteve.reinhardt@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186876Ssteve.reinhardt@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196876Ssteve.reinhardt@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206876Ssteve.reinhardt@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216876Ssteve.reinhardt@amd.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226876Ssteve.reinhardt@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236876Ssteve.reinhardt@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246876Ssteve.reinhardt@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256876Ssteve.reinhardt@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266876Ssteve.reinhardt@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276876Ssteve.reinhardt@amd.com */ 286876Ssteve.reinhardt@amd.com 296876Ssteve.reinhardt@amd.com#ifndef __CPU_PROFILE_HH__ 306876Ssteve.reinhardt@amd.com#define __CPU_PROFILE_HH__ 316876Ssteve.reinhardt@amd.com 326876Ssteve.reinhardt@amd.com#include <map> 336876Ssteve.reinhardt@amd.com 346876Ssteve.reinhardt@amd.com#include "cpu/static_inst.hh" 356876Ssteve.reinhardt@amd.com#include "sim/host.hh" 366876Ssteve.reinhardt@amd.com#include "arch/stacktrace.hh" 376876Ssteve.reinhardt@amd.com 386876Ssteve.reinhardt@amd.comclass ExecContext; 396876Ssteve.reinhardt@amd.com 406876Ssteve.reinhardt@amd.comclass ProfileNode 416876Ssteve.reinhardt@amd.com{ 427039Snate@binkert.org private: 437039Snate@binkert.org friend class FunctionProfile; 446285Snate@binkert.org 457039Snate@binkert.org typedef std::map<Addr, ProfileNode *> ChildList; 466285Snate@binkert.org ChildList children; 476285Snate@binkert.org 486922SBrad.Beckmann@amd.com public: 4912395Sswapnilster@gmail.com Counter count; 5010301Snilay@cs.wisc.edu 5111108Sdavid.hashe@amd.com public: 528229Snate@binkert.org ProfileNode(); 537039Snate@binkert.org 546876Ssteve.reinhardt@amd.com void dump(const std::string &symbol, uint64_t id, 556876Ssteve.reinhardt@amd.com const SymbolTable *symtab, std::ostream &os) const; 566876Ssteve.reinhardt@amd.com void clear(); 576876Ssteve.reinhardt@amd.com}; 587039Snate@binkert.org 597039Snate@binkert.orgclass Callback; 607039Snate@binkert.orgclass FunctionProfile 6110090Snilay@cs.wisc.edu{ 6210090Snilay@cs.wisc.edu private: 6310090Snilay@cs.wisc.edu Callback *reset; 6410713Sandreas.hansson@arm.com const SymbolTable *symtab; 6510713Sandreas.hansson@arm.com ProfileNode top; 6610090Snilay@cs.wisc.edu std::map<Addr, Counter> pc_count; 6710090Snilay@cs.wisc.edu StackTrace trace; 6810090Snilay@cs.wisc.edu 6910090Snilay@cs.wisc.edu public: 7010090Snilay@cs.wisc.edu FunctionProfile(const SymbolTable *symtab); 7110090Snilay@cs.wisc.edu ~FunctionProfile(); 7210090Snilay@cs.wisc.edu 7310090Snilay@cs.wisc.edu ProfileNode *consume(ExecContext *xc, StaticInstPtr inst); 7410090Snilay@cs.wisc.edu ProfileNode *consume(const std::vector<Addr> &stack); 7510090Snilay@cs.wisc.edu void clear(); 766882SBrad.Beckmann@amd.com void dump(ExecContext *xc, std::ostream &out) const; 777039Snate@binkert.org void sample(ProfileNode *node, Addr pc); 7810713Sandreas.hansson@arm.com}; 7910525Snilay@cs.wisc.edu 8011266SBrad.Beckmann@amd.cominline ProfileNode * 816882SBrad.Beckmann@amd.comFunctionProfile::consume(ExecContext *xc, StaticInstPtr inst) 826882SBrad.Beckmann@amd.com{ 8310090Snilay@cs.wisc.edu if (!trace.trace(xc, inst)) 8411266SBrad.Beckmann@amd.com return NULL; 8511266SBrad.Beckmann@amd.com trace.dprintf(); 866882SBrad.Beckmann@amd.com return consume(trace.getstack()); 8711025Snilay@cs.wisc.edu} 886882SBrad.Beckmann@amd.com 896882SBrad.Beckmann@amd.com#endif // __CPU_PROFILE_HH__ 9010089Sandreas.hansson@arm.com