Profiler.hh revision 7454
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>
507454Snate@binkert.org#include <vector>
517055Snate@binkert.org
526154Snate@binkert.org#include "mem/protocol/AccessModeType.hh"
536154Snate@binkert.org#include "mem/protocol/AccessType.hh"
547048Snate@binkert.org#include "mem/protocol/CacheRequestType.hh"
557048Snate@binkert.org#include "mem/protocol/GenericMachineType.hh"
567048Snate@binkert.org#include "mem/protocol/GenericRequestType.hh"
576154Snate@binkert.org#include "mem/protocol/PrefetchBit.hh"
586154Snate@binkert.org#include "mem/ruby/common/Address.hh"
597048Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
607048Snate@binkert.org#include "mem/ruby/common/Global.hh"
617048Snate@binkert.org#include "mem/ruby/common/Histogram.hh"
626154Snate@binkert.org#include "mem/ruby/common/Set.hh"
637048Snate@binkert.org#include "mem/ruby/libruby.hh"
647048Snate@binkert.org#include "mem/ruby/system/MachineID.hh"
656285Snate@binkert.org#include "mem/ruby/system/MemoryControl.hh"
667048Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
676876Ssteve.reinhardt@amd.com#include "params/RubyProfiler.hh"
686876Ssteve.reinhardt@amd.com#include "sim/sim_object.hh"
696876Ssteve.reinhardt@amd.com
706145Snate@binkert.orgclass CacheMsg;
716145Snate@binkert.orgclass AddressProfiler;
726145Snate@binkert.org
736145Snate@binkert.orgtemplate <class KEY_TYPE, class VALUE_TYPE> class Map;
746145Snate@binkert.org
757048Snate@binkert.orgclass Profiler : public SimObject, public Consumer
767048Snate@binkert.org{
777048Snate@binkert.org  public:
786876Ssteve.reinhardt@amd.com    typedef RubyProfilerParams Params;
797048Snate@binkert.org    Profiler(const Params *);
807048Snate@binkert.org    ~Profiler();
816145Snate@binkert.org
827048Snate@binkert.org    void wakeup();
836145Snate@binkert.org
847055Snate@binkert.org    void setPeriodicStatsFile(const std::string& filename);
857048Snate@binkert.org    void setPeriodicStatsInterval(integer_t period);
866145Snate@binkert.org
877055Snate@binkert.org    void printStats(std::ostream& out, bool short_stats=false);
887055Snate@binkert.org    void printShortStats(std::ostream& out) { printStats(out, true); }
897055Snate@binkert.org    void printTraceStats(std::ostream& out) const;
907048Snate@binkert.org    void clearStats();
917055Snate@binkert.org    void printConfig(std::ostream& out) const;
927055Snate@binkert.org    void printResourceUsage(std::ostream& out) const;
936145Snate@binkert.org
947048Snate@binkert.org    AddressProfiler* getAddressProfiler() { return m_address_profiler_ptr; }
957048Snate@binkert.org    AddressProfiler* getInstructionProfiler() { return m_inst_profiler_ptr; }
966145Snate@binkert.org
977048Snate@binkert.org    void addAddressTraceSample(const CacheMsg& msg, NodeID id);
986145Snate@binkert.org
997055Snate@binkert.org    void profileRequest(const std::string& requestStr);
1007048Snate@binkert.org    void profileSharing(const Address& addr, AccessType type,
1017048Snate@binkert.org                        NodeID requestor, const Set& sharers,
1027048Snate@binkert.org                        const Set& owner);
1036145Snate@binkert.org
1047048Snate@binkert.org    void profileMulticastRetry(const Address& addr, int count);
1056145Snate@binkert.org
1067048Snate@binkert.org    void profileFilterAction(int action);
1076145Snate@binkert.org
1087048Snate@binkert.org    void profileConflictingRequests(const Address& addr);
1096145Snate@binkert.org
1107048Snate@binkert.org    void
1117048Snate@binkert.org    profileOutstandingRequest(int outstanding)
1127048Snate@binkert.org    {
1137048Snate@binkert.org        m_outstanding_requests.add(outstanding);
1147048Snate@binkert.org    }
1156145Snate@binkert.org
1167048Snate@binkert.org    void
1177048Snate@binkert.org    profileOutstandingPersistentRequest(int outstanding)
1187048Snate@binkert.org    {
1197048Snate@binkert.org        m_outstanding_persistent_requests.add(outstanding);
1207048Snate@binkert.org    }
1216145Snate@binkert.org
1227048Snate@binkert.org    void
1237048Snate@binkert.org    profileAverageLatencyEstimate(int latency)
1247048Snate@binkert.org    {
1257048Snate@binkert.org        m_average_latency_estimate.add(latency);
1267048Snate@binkert.org    }
1276145Snate@binkert.org
1287048Snate@binkert.org    void recordPrediction(bool wasGood, bool wasPredicted);
1296145Snate@binkert.org
1307048Snate@binkert.org    void startTransaction(int cpu);
1317048Snate@binkert.org    void endTransaction(int cpu);
1327048Snate@binkert.org    void profilePFWait(Time waitTime);
1336145Snate@binkert.org
1347048Snate@binkert.org    void controllerBusy(MachineID machID);
1357048Snate@binkert.org    void bankBusy();
1367048Snate@binkert.org    void missLatency(Time t, RubyRequestType type);
1377048Snate@binkert.org    void swPrefetchLatency(Time t, CacheRequestType type,
1387048Snate@binkert.org                           GenericMachineType respondingMach);
1397048Snate@binkert.org    void sequencerRequests(int num) { m_sequencer_requests.add(num); }
1406145Snate@binkert.org
1417055Snate@binkert.org    void profileTransition(const std::string& component, NodeID version,
1427055Snate@binkert.org        Address addr, const std::string& state, const std::string& event,
1437055Snate@binkert.org        const std::string& next_state, const std::string& note);
1447048Snate@binkert.org    void profileMsgDelay(int virtualNetwork, int delayCycles);
1456145Snate@binkert.org
1467055Snate@binkert.org    void print(std::ostream& out) const;
1476285Snate@binkert.org
1487048Snate@binkert.org    void rubyWatch(int proc);
1497048Snate@binkert.org    bool watchAddress(Address addr);
1506145Snate@binkert.org
1517048Snate@binkert.org    // return Ruby's start time
1527048Snate@binkert.org    Time
1537048Snate@binkert.org    getRubyStartTime()
1547048Snate@binkert.org    {
1557048Snate@binkert.org        return m_ruby_start;
1567048Snate@binkert.org    }
1576145Snate@binkert.org
1587048Snate@binkert.org    // added by SS
1597048Snate@binkert.org    bool getHotLines() { return m_hot_lines; }
1607048Snate@binkert.org    bool getAllInstructions() { return m_all_instructions; }
1616145Snate@binkert.org
1627048Snate@binkert.org  private:
1637048Snate@binkert.org    // Private copy constructor and assignment operator
1647048Snate@binkert.org    Profiler(const Profiler& obj);
1657048Snate@binkert.org    Profiler& operator=(const Profiler& obj);
1666145Snate@binkert.org
1677048Snate@binkert.org    AddressProfiler* m_address_profiler_ptr;
1687048Snate@binkert.org    AddressProfiler* m_inst_profiler_ptr;
1696145Snate@binkert.org
1707454Snate@binkert.org    std::vector<int64> m_instructions_executed_at_start;
1717454Snate@binkert.org    std::vector<int64> m_cycles_executed_at_start;
1726145Snate@binkert.org
1737055Snate@binkert.org    std::ostream* m_periodic_output_file_ptr;
1747048Snate@binkert.org    integer_t m_stats_period;
1756145Snate@binkert.org
1767048Snate@binkert.org    Time m_ruby_start;
1777048Snate@binkert.org    time_t m_real_time_start_time;
1786145Snate@binkert.org
1797454Snate@binkert.org    std::vector<std::vector<integer_t> > m_busyControllerCount;
1807048Snate@binkert.org    integer_t m_busyBankCount;
1817048Snate@binkert.org    Histogram m_multicast_retry_histogram;
1826145Snate@binkert.org
1837048Snate@binkert.org    Histogram m_filter_action_histogram;
1847048Snate@binkert.org    Histogram m_tbeProfile;
1856145Snate@binkert.org
1867048Snate@binkert.org    Histogram m_sequencer_requests;
1877048Snate@binkert.org    Histogram m_read_sharing_histogram;
1887048Snate@binkert.org    Histogram m_write_sharing_histogram;
1897048Snate@binkert.org    Histogram m_all_sharing_histogram;
1907048Snate@binkert.org    int64 m_cache_to_cache;
1917048Snate@binkert.org    int64 m_memory_to_cache;
1926145Snate@binkert.org
1937048Snate@binkert.org    Histogram m_prefetchWaitHistogram;
1946145Snate@binkert.org
1957454Snate@binkert.org    std::vector<Histogram> m_missLatencyHistograms;
1967454Snate@binkert.org    std::vector<Histogram> m_machLatencyHistograms;
1977048Snate@binkert.org    Histogram m_allMissLatencyHistogram;
1986145Snate@binkert.org
1997048Snate@binkert.org    Histogram m_allSWPrefetchLatencyHistogram;
2007048Snate@binkert.org    Histogram m_SWPrefetchL2MissLatencyHistogram;
2017454Snate@binkert.org    std::vector<Histogram> m_SWPrefetchLatencyHistograms;
2027454Snate@binkert.org    std::vector<Histogram> m_SWPrefetchMachLatencyHistograms;
2036145Snate@binkert.org
2047048Snate@binkert.org    Histogram m_delayedCyclesHistogram;
2057048Snate@binkert.org    Histogram m_delayedCyclesNonPFHistogram;
2067454Snate@binkert.org    std::vector<Histogram> m_delayedCyclesVCHistograms;
2076145Snate@binkert.org
2087048Snate@binkert.org    Histogram m_outstanding_requests;
2097048Snate@binkert.org    Histogram m_outstanding_persistent_requests;
2106145Snate@binkert.org
2117048Snate@binkert.org    Histogram m_average_latency_estimate;
2126145Snate@binkert.org
2137048Snate@binkert.org    Map<Address, int>* m_watch_address_list_ptr;
2147048Snate@binkert.org    // counts all initiated cache request including PUTs
2157048Snate@binkert.org    int m_requests;
2167055Snate@binkert.org    Map <std::string, int>* m_requestProfileMap_ptr;
2176896SBrad.Beckmann@amd.com
2187048Snate@binkert.org    //added by SS
2197048Snate@binkert.org    bool m_hot_lines;
2207048Snate@binkert.org    bool m_all_instructions;
2217048Snate@binkert.org
2227048Snate@binkert.org    int m_num_of_sequencers;
2236145Snate@binkert.org};
2246145Snate@binkert.org
2257055Snate@binkert.orginline std::ostream&
2267055Snate@binkert.orgoperator<<(std::ostream& out, const Profiler& obj)
2276145Snate@binkert.org{
2287048Snate@binkert.org    obj.print(out);
2297055Snate@binkert.org    out << std::flush;
2307048Snate@binkert.org    return out;
2316145Snate@binkert.org}
2326145Snate@binkert.org
2337048Snate@binkert.org#endif // __MEM_RUBY_PROFILER_PROFILER_HH__
2346145Snate@binkert.org
2356145Snate@binkert.org
236