2005-10-19 01:07:42 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 The Regents of The University of Michigan
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Authors: Nathan Binkert
|
2005-10-19 01:07:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CPU_PROFILE_HH__
|
|
|
|
#define __CPU_PROFILE_HH__
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
2006-11-08 06:52:04 +01:00
|
|
|
#include "arch/stacktrace.hh"
|
2011-04-15 19:44:06 +02:00
|
|
|
#include "base/types.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "config/the_isa.hh"
|
2005-10-19 01:07:42 +02:00
|
|
|
#include "cpu/static_inst.hh"
|
|
|
|
|
2006-06-06 23:32:21 +02:00
|
|
|
class ThreadContext;
|
2006-03-08 01:59:12 +01:00
|
|
|
|
2005-10-19 01:07:42 +02:00
|
|
|
class ProfileNode
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
friend class FunctionProfile;
|
|
|
|
|
2005-11-20 23:44:58 +01:00
|
|
|
typedef std::map<Addr, ProfileNode *> ChildList;
|
2005-10-19 01:07:42 +02:00
|
|
|
ChildList children;
|
|
|
|
|
|
|
|
public:
|
2005-11-21 00:32:22 +01:00
|
|
|
Counter count;
|
2005-10-19 01:07:42 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
ProfileNode();
|
|
|
|
|
|
|
|
void dump(const std::string &symbol, uint64_t id,
|
|
|
|
const SymbolTable *symtab, std::ostream &os) const;
|
|
|
|
void clear();
|
|
|
|
};
|
|
|
|
|
2005-11-21 00:33:17 +01:00
|
|
|
class Callback;
|
2005-10-19 01:07:42 +02:00
|
|
|
class FunctionProfile
|
|
|
|
{
|
|
|
|
private:
|
2005-11-21 00:33:17 +01:00
|
|
|
Callback *reset;
|
2005-10-19 01:07:42 +02:00
|
|
|
const SymbolTable *symtab;
|
|
|
|
ProfileNode top;
|
|
|
|
std::map<Addr, Counter> pc_count;
|
2006-11-08 06:52:04 +01:00
|
|
|
TheISA::StackTrace trace;
|
2005-10-19 01:07:42 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
FunctionProfile(const SymbolTable *symtab);
|
|
|
|
~FunctionProfile();
|
|
|
|
|
2006-06-06 23:32:21 +02:00
|
|
|
ProfileNode *consume(ThreadContext *tc, StaticInstPtr inst);
|
2005-11-20 23:44:58 +01:00
|
|
|
ProfileNode *consume(const std::vector<Addr> &stack);
|
2005-10-19 01:07:42 +02:00
|
|
|
void clear();
|
2006-06-06 23:32:21 +02:00
|
|
|
void dump(ThreadContext *tc, std::ostream &out) const;
|
2005-10-19 01:07:42 +02:00
|
|
|
void sample(ProfileNode *node, Addr pc);
|
|
|
|
};
|
|
|
|
|
2005-11-20 23:44:58 +01:00
|
|
|
inline ProfileNode *
|
2006-06-06 23:32:21 +02:00
|
|
|
FunctionProfile::consume(ThreadContext *tc, StaticInstPtr inst)
|
2005-11-20 23:44:58 +01:00
|
|
|
{
|
2006-06-06 23:32:21 +02:00
|
|
|
if (!trace.trace(tc, inst))
|
2005-11-20 23:44:58 +01:00
|
|
|
return NULL;
|
|
|
|
trace.dprintf();
|
|
|
|
return consume(trace.getstack());
|
|
|
|
}
|
|
|
|
|
2005-10-19 01:07:42 +02:00
|
|
|
#endif // __CPU_PROFILE_HH__
|