profile.hh revision 2235
11689SN/A/*
29444SAndreas.Sandberg@ARM.com * Copyright (c) 2005 The Regents of The University of Michigan
37854SAli.Saidi@ARM.com * All rights reserved.
47854SAli.Saidi@ARM.com *
57854SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without
67854SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are
77854SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright
87854SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer;
97854SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright
107854SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the
117854SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution;
127854SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its
137854SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from
142329SN/A * this software without specific prior written permission.
151689SN/A *
161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271689SN/A */
281689SN/A
291689SN/A#ifndef __CPU_PROFILE_HH__
301689SN/A#define __CPU_PROFILE_HH__
311689SN/A
321689SN/A#include <map>
331689SN/A
341689SN/A#include "cpu/static_inst.hh"
351689SN/A#include "sim/host.hh"
361689SN/A#include "arch/stacktrace.hh"
371689SN/A
381689SN/Aclass ExecContext;
392665Ssaidi@eecs.umich.edu
402665Ssaidi@eecs.umich.educlass ProfileNode
412935Sksewell@umich.edu{
421689SN/A  private:
431689SN/A    friend class FunctionProfile;
441060SN/A
451060SN/A    typedef std::map<Addr, ProfileNode *> ChildList;
463773Sgblack@eecs.umich.edu    ChildList children;
476329Sgblack@eecs.umich.edu
486658Snate@binkert.org  public:
491717SN/A    Counter count;
508232Snate@binkert.org
518232Snate@binkert.org  public:
525529Snate@binkert.org    ProfileNode();
531060SN/A
546221Snate@binkert.org    void dump(const std::string &symbol, uint64_t id,
556221Snate@binkert.org              const SymbolTable *symtab, std::ostream &os) const;
561061SN/A    void clear();
575529Snate@binkert.org};
584329Sktlim@umich.edu
594329Sktlim@umich.educlass Callback;
602292SN/Aclass FunctionProfile
612292SN/A{
622292SN/A  private:
632292SN/A    Callback *reset;
645529Snate@binkert.org    const SymbolTable *symtab;
652361SN/A    ProfileNode top;
661060SN/A    std::map<Addr, Counter> pc_count;
672292SN/A    StackTrace trace;
688907Slukefahr@umich.edu
692292SN/A  public:
702292SN/A    FunctionProfile(const SymbolTable *symtab);
712292SN/A    ~FunctionProfile();
722292SN/A
732292SN/A    ProfileNode *consume(ExecContext *xc, StaticInstPtr inst);
742292SN/A    ProfileNode *consume(const std::vector<Addr> &stack);
752292SN/A    void clear();
761060SN/A    void dump(ExecContext *xc, std::ostream &out) const;
771060SN/A    void sample(ProfileNode *node, Addr pc);
781061SN/A};
791060SN/A
802292SN/Ainline ProfileNode *
811062SN/AFunctionProfile::consume(ExecContext *xc, StaticInstPtr inst)
821062SN/A{
838240Snate@binkert.org    if (!trace.trace(xc, inst))
841062SN/A        return NULL;
851062SN/A    trace.dprintf();
861062SN/A    return consume(trace.getstack());
878240Snate@binkert.org}
881062SN/A
891062SN/A#endif // __CPU_PROFILE_HH__
901062SN/A