Profiler.hh revision 7055
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org */
286145Snate@binkert.org
296145Snate@binkert.org/*
306284Snate@binkert.org   This file has been modified by Kevin Moore and Dan Nussbaum of the
316284Snate@binkert.org   Scalable Systems Research Group at Sun Microsystems Laboratories
326284Snate@binkert.org   (http://research.sun.com/scalable/) to support the Adaptive
336284Snate@binkert.org   Transactional Memory Test Platform (ATMTP).
346145Snate@binkert.org
356284Snate@binkert.org   Please send email to atmtp-interest@sun.com with feedback, questions, or
366284Snate@binkert.org   to request future announcements about ATMTP.
376145Snate@binkert.org
386284Snate@binkert.org   ----------------------------------------------------------------------
396145Snate@binkert.org
406284Snate@binkert.org   File modification date: 2008-02-23
416145Snate@binkert.org
426284Snate@binkert.org   ----------------------------------------------------------------------
436145Snate@binkert.org*/
446145Snate@binkert.org
457048Snate@binkert.org#ifndef __MEM_RUBY_PROFILER_PROFILER_HH__
467048Snate@binkert.org#define __MEM_RUBY_PROFILER_PROFILER_HH__
476145Snate@binkert.org
487055Snate@binkert.org#include <iostream>
497055Snate@binkert.org#include <string>
507055Snate@binkert.org
516154Snate@binkert.org#include "mem/protocol/AccessModeType.hh"
526154Snate@binkert.org#include "mem/protocol/AccessType.hh"
537048Snate@binkert.org#include "mem/protocol/CacheRequestType.hh"
547048Snate@binkert.org#include "mem/protocol/GenericMachineType.hh"
557048Snate@binkert.org#include "mem/protocol/GenericRequestType.hh"
566154Snate@binkert.org#include "mem/protocol/PrefetchBit.hh"
576154Snate@binkert.org#include "mem/ruby/common/Address.hh"
587048Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
597048Snate@binkert.org#include "mem/ruby/common/Global.hh"
607048Snate@binkert.org#include "mem/ruby/common/Histogram.hh"
616154Snate@binkert.org#include "mem/ruby/common/Set.hh"
627048Snate@binkert.org#include "mem/ruby/libruby.hh"
637048Snate@binkert.org#include "mem/ruby/system/MachineID.hh"
646285Snate@binkert.org#include "mem/ruby/system/MemoryControl.hh"
657048Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
666876Ssteve.reinhardt@amd.com#include "params/RubyProfiler.hh"
676876Ssteve.reinhardt@amd.com#include "sim/sim_object.hh"
686876Ssteve.reinhardt@amd.com
696145Snate@binkert.orgclass CacheMsg;
706145Snate@binkert.orgclass AddressProfiler;
716145Snate@binkert.org
726145Snate@binkert.orgtemplate <class KEY_TYPE, class VALUE_TYPE> class Map;
736145Snate@binkert.org
747048Snate@binkert.orgclass Profiler : public SimObject, public Consumer
757048Snate@binkert.org{
767048Snate@binkert.org  public:
776876Ssteve.reinhardt@amd.com    typedef RubyProfilerParams Params;
787048Snate@binkert.org    Profiler(const Params *);
797048Snate@binkert.org    ~Profiler();
806145Snate@binkert.org
817048Snate@binkert.org    void wakeup();
826145Snate@binkert.org
837055Snate@binkert.org    void setPeriodicStatsFile(const std::string& filename);
847048Snate@binkert.org    void setPeriodicStatsInterval(integer_t period);
856145Snate@binkert.org
867055Snate@binkert.org    void printStats(std::ostream& out, bool short_stats=false);
877055Snate@binkert.org    void printShortStats(std::ostream& out) { printStats(out, true); }
887055Snate@binkert.org    void printTraceStats(std::ostream& out) const;
897048Snate@binkert.org    void clearStats();
907055Snate@binkert.org    void printConfig(std::ostream& out) const;
917055Snate@binkert.org    void printResourceUsage(std::ostream& out) const;
926145Snate@binkert.org
937048Snate@binkert.org    AddressProfiler* getAddressProfiler() { return m_address_profiler_ptr; }
947048Snate@binkert.org    AddressProfiler* getInstructionProfiler() { return m_inst_profiler_ptr; }
956145Snate@binkert.org
967048Snate@binkert.org    void addAddressTraceSample(const CacheMsg& msg, NodeID id);
976145Snate@binkert.org
987055Snate@binkert.org    void profileRequest(const std::string& requestStr);
997048Snate@binkert.org    void profileSharing(const Address& addr, AccessType type,
1007048Snate@binkert.org                        NodeID requestor, const Set& sharers,
1017048Snate@binkert.org                        const Set& owner);
1026145Snate@binkert.org
1037048Snate@binkert.org    void profileMulticastRetry(const Address& addr, int count);
1046145Snate@binkert.org
1057048Snate@binkert.org    void profileFilterAction(int action);
1066145Snate@binkert.org
1077048Snate@binkert.org    void profileConflictingRequests(const Address& addr);
1086145Snate@binkert.org
1097048Snate@binkert.org    void
1107048Snate@binkert.org    profileOutstandingRequest(int outstanding)
1117048Snate@binkert.org    {
1127048Snate@binkert.org        m_outstanding_requests.add(outstanding);
1137048Snate@binkert.org    }
1146145Snate@binkert.org
1157048Snate@binkert.org    void
1167048Snate@binkert.org    profileOutstandingPersistentRequest(int outstanding)
1177048Snate@binkert.org    {
1187048Snate@binkert.org        m_outstanding_persistent_requests.add(outstanding);
1197048Snate@binkert.org    }
1206145Snate@binkert.org
1217048Snate@binkert.org    void
1227048Snate@binkert.org    profileAverageLatencyEstimate(int latency)
1237048Snate@binkert.org    {
1247048Snate@binkert.org        m_average_latency_estimate.add(latency);
1257048Snate@binkert.org    }
1266145Snate@binkert.org
1277048Snate@binkert.org    void recordPrediction(bool wasGood, bool wasPredicted);
1286145Snate@binkert.org
1297048Snate@binkert.org    void startTransaction(int cpu);
1307048Snate@binkert.org    void endTransaction(int cpu);
1317048Snate@binkert.org    void profilePFWait(Time waitTime);
1326145Snate@binkert.org
1337048Snate@binkert.org    void controllerBusy(MachineID machID);
1347048Snate@binkert.org    void bankBusy();
1357048Snate@binkert.org    void missLatency(Time t, RubyRequestType type);
1367048Snate@binkert.org    void swPrefetchLatency(Time t, CacheRequestType type,
1377048Snate@binkert.org                           GenericMachineType respondingMach);
1387048Snate@binkert.org    void sequencerRequests(int num) { m_sequencer_requests.add(num); }
1396145Snate@binkert.org
1407055Snate@binkert.org    void profileTransition(const std::string& component, NodeID version,
1417055Snate@binkert.org        Address addr, const std::string& state, const std::string& event,
1427055Snate@binkert.org        const std::string& next_state, const std::string& note);
1437048Snate@binkert.org    void profileMsgDelay(int virtualNetwork, int delayCycles);
1446145Snate@binkert.org
1457055Snate@binkert.org    void print(std::ostream& out) const;
1466285Snate@binkert.org
1477048Snate@binkert.org    void rubyWatch(int proc);
1487048Snate@binkert.org    bool watchAddress(Address addr);
1496145Snate@binkert.org
1507048Snate@binkert.org    // return Ruby's start time
1517048Snate@binkert.org    Time
1527048Snate@binkert.org    getRubyStartTime()
1537048Snate@binkert.org    {
1547048Snate@binkert.org        return m_ruby_start;
1557048Snate@binkert.org    }
1566145Snate@binkert.org
1577048Snate@binkert.org    // added by SS
1587048Snate@binkert.org    bool getHotLines() { return m_hot_lines; }
1597048Snate@binkert.org    bool getAllInstructions() { return m_all_instructions; }
1606145Snate@binkert.org
1617048Snate@binkert.org  private:
1627048Snate@binkert.org    // Private copy constructor and assignment operator
1637048Snate@binkert.org    Profiler(const Profiler& obj);
1647048Snate@binkert.org    Profiler& operator=(const Profiler& obj);
1656145Snate@binkert.org
1667048Snate@binkert.org    AddressProfiler* m_address_profiler_ptr;
1677048Snate@binkert.org    AddressProfiler* m_inst_profiler_ptr;
1686145Snate@binkert.org
1697048Snate@binkert.org    Vector<int64> m_instructions_executed_at_start;
1707048Snate@binkert.org    Vector<int64> m_cycles_executed_at_start;
1716145Snate@binkert.org
1727055Snate@binkert.org    std::ostream* m_periodic_output_file_ptr;
1737048Snate@binkert.org    integer_t m_stats_period;
1746145Snate@binkert.org
1757048Snate@binkert.org    Time m_ruby_start;
1767048Snate@binkert.org    time_t m_real_time_start_time;
1776145Snate@binkert.org
1787048Snate@binkert.org    Vector <Vector<integer_t> > m_busyControllerCount;
1797048Snate@binkert.org    integer_t m_busyBankCount;
1807048Snate@binkert.org    Histogram m_multicast_retry_histogram;
1816145Snate@binkert.org
1827048Snate@binkert.org    Histogram m_filter_action_histogram;
1837048Snate@binkert.org    Histogram m_tbeProfile;
1846145Snate@binkert.org
1857048Snate@binkert.org    Histogram m_sequencer_requests;
1867048Snate@binkert.org    Histogram m_read_sharing_histogram;
1877048Snate@binkert.org    Histogram m_write_sharing_histogram;
1887048Snate@binkert.org    Histogram m_all_sharing_histogram;
1897048Snate@binkert.org    int64 m_cache_to_cache;
1907048Snate@binkert.org    int64 m_memory_to_cache;
1916145Snate@binkert.org
1927048Snate@binkert.org    Histogram m_prefetchWaitHistogram;
1936145Snate@binkert.org
1947048Snate@binkert.org    Vector<Histogram> m_missLatencyHistograms;
1957048Snate@binkert.org    Vector<Histogram> m_machLatencyHistograms;
1967048Snate@binkert.org    Histogram m_allMissLatencyHistogram;
1976145Snate@binkert.org
1987048Snate@binkert.org    Histogram m_allSWPrefetchLatencyHistogram;
1997048Snate@binkert.org    Histogram m_SWPrefetchL2MissLatencyHistogram;
2007048Snate@binkert.org    Vector<Histogram> m_SWPrefetchLatencyHistograms;
2017048Snate@binkert.org    Vector<Histogram> m_SWPrefetchMachLatencyHistograms;
2026145Snate@binkert.org
2037048Snate@binkert.org    Histogram m_delayedCyclesHistogram;
2047048Snate@binkert.org    Histogram m_delayedCyclesNonPFHistogram;
2057048Snate@binkert.org    Vector<Histogram> m_delayedCyclesVCHistograms;
2066145Snate@binkert.org
2077048Snate@binkert.org    Histogram m_outstanding_requests;
2087048Snate@binkert.org    Histogram m_outstanding_persistent_requests;
2096145Snate@binkert.org
2107048Snate@binkert.org    Histogram m_average_latency_estimate;
2116145Snate@binkert.org
2127048Snate@binkert.org    Map<Address, int>* m_watch_address_list_ptr;
2137048Snate@binkert.org    // counts all initiated cache request including PUTs
2147048Snate@binkert.org    int m_requests;
2157055Snate@binkert.org    Map <std::string, int>* m_requestProfileMap_ptr;
2166896SBrad.Beckmann@amd.com
2177048Snate@binkert.org    //added by SS
2187048Snate@binkert.org    bool m_hot_lines;
2197048Snate@binkert.org    bool m_all_instructions;
2207048Snate@binkert.org
2217048Snate@binkert.org    int m_num_of_sequencers;
2226145Snate@binkert.org};
2236145Snate@binkert.org
2247055Snate@binkert.orginline std::ostream&
2257055Snate@binkert.orgoperator<<(std::ostream& out, const Profiler& obj)
2266145Snate@binkert.org{
2277048Snate@binkert.org    obj.print(out);
2287055Snate@binkert.org    out << std::flush;
2297048Snate@binkert.org    return out;
2306145Snate@binkert.org}
2316145Snate@binkert.org
2327048Snate@binkert.org#endif // __MEM_RUBY_PROFILER_PROFILER_HH__
2336145Snate@binkert.org
2346145Snate@binkert.org
235