Profiler.cc revision 6876
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/*
306145Snate@binkert.org   This file has been modified by Kevin Moore and Dan Nussbaum of the
316145Snate@binkert.org   Scalable Systems Research Group at Sun Microsystems Laboratories
326145Snate@binkert.org   (http://research.sun.com/scalable/) to support the Adaptive
336145Snate@binkert.org   Transactional Memory Test Platform (ATMTP).
346145Snate@binkert.org
356145Snate@binkert.org   Please send email to atmtp-interest@sun.com with feedback, questions, or
366145Snate@binkert.org   to request future announcements about ATMTP.
376145Snate@binkert.org
386145Snate@binkert.org   ----------------------------------------------------------------------
396145Snate@binkert.org
406145Snate@binkert.org   File modification date: 2008-02-23
416145Snate@binkert.org
426145Snate@binkert.org   ----------------------------------------------------------------------
436145Snate@binkert.org*/
446145Snate@binkert.org
456145Snate@binkert.org/*
466284Snate@binkert.org * Profiler.cc
476145Snate@binkert.org *
486284Snate@binkert.org * Description: See Profiler.hh
496145Snate@binkert.org *
506145Snate@binkert.org * $Id$
516145Snate@binkert.org *
526145Snate@binkert.org */
536145Snate@binkert.org
546154Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh"
556154Snate@binkert.org#include "mem/ruby/profiler/AddressProfiler.hh"
566154Snate@binkert.org#include "mem/ruby/system/System.hh"
576154Snate@binkert.org#include "mem/ruby/network/Network.hh"
586154Snate@binkert.org#include "mem/gems_common/PrioHeap.hh"
596154Snate@binkert.org#include "mem/protocol/CacheMsg.hh"
606154Snate@binkert.org#include "mem/protocol/Protocol.hh"
616154Snate@binkert.org#include "mem/gems_common/util.hh"
626154Snate@binkert.org#include "mem/gems_common/Map.hh"
636154Snate@binkert.org#include "mem/ruby/common/Debug.hh"
646154Snate@binkert.org#include "mem/protocol/MachineType.hh"
656145Snate@binkert.org
666876Ssteve.reinhardt@amd.com#include "mem/ruby/system/System.hh"
676876Ssteve.reinhardt@amd.com
686145Snate@binkert.org// Allows use of times() library call, which determines virtual runtime
696145Snate@binkert.org#include <sys/times.h>
706145Snate@binkert.org
716145Snate@binkert.orgextern std::ostream * debug_cout_ptr;
726145Snate@binkert.org
736145Snate@binkert.orgstatic double process_memory_total();
746145Snate@binkert.orgstatic double process_memory_resident();
756145Snate@binkert.org
766876Ssteve.reinhardt@amd.comProfiler::Profiler(const Params *p)
776876Ssteve.reinhardt@amd.com    : SimObject(p)
786145Snate@binkert.org{
796145Snate@binkert.org  m_requestProfileMap_ptr = new Map<string, int>;
806145Snate@binkert.org
816285Snate@binkert.org  m_inst_profiler_ptr = NULL;
826285Snate@binkert.org  m_address_profiler_ptr = NULL;
836285Snate@binkert.org
846145Snate@binkert.org  m_real_time_start_time = time(NULL); // Not reset in clearStats()
856145Snate@binkert.org  m_stats_period = 1000000; // Default
866145Snate@binkert.org  m_periodic_output_file_ptr = &cerr;
876145Snate@binkert.org
886876Ssteve.reinhardt@amd.com  m_hot_lines = p->hot_lines;
896876Ssteve.reinhardt@amd.com  m_all_instructions = p->all_instructions;
906876Ssteve.reinhardt@amd.com
916876Ssteve.reinhardt@amd.com  RubySystem::m_profiler_ptr = this;
926145Snate@binkert.org}
936145Snate@binkert.org
946145Snate@binkert.orgProfiler::~Profiler()
956145Snate@binkert.org{
966145Snate@binkert.org  if (m_periodic_output_file_ptr != &cerr) {
976145Snate@binkert.org    delete m_periodic_output_file_ptr;
986145Snate@binkert.org  }
996145Snate@binkert.org  delete m_requestProfileMap_ptr;
1006145Snate@binkert.org}
1016145Snate@binkert.org
1026285Snate@binkert.orgvoid Profiler::init(const vector<string> & argv, vector<string> memory_control_names)
1036285Snate@binkert.org{
1046285Snate@binkert.org  // added by SS
1056285Snate@binkert.org  vector<string>::iterator it;
1066285Snate@binkert.org  memory_control_profiler* mcp;
1076285Snate@binkert.org  m_memory_control_names = memory_control_names;
1086285Snate@binkert.org//  printf ( "Here in Profiler::init \n");
1096285Snate@binkert.org  for ( it=memory_control_names.begin() ; it < memory_control_names.end(); it++ ){
1106285Snate@binkert.org//    printf ( "Here in Profiler::init memory control name %s \n", (*it).c_str());
1116285Snate@binkert.org    mcp = new memory_control_profiler;
1126285Snate@binkert.org    mcp->m_memReq = 0;
1136285Snate@binkert.org    mcp->m_memBankBusy = 0;
1146285Snate@binkert.org    mcp->m_memBusBusy = 0;
1156285Snate@binkert.org    mcp->m_memReadWriteBusy = 0;
1166285Snate@binkert.org    mcp->m_memDataBusBusy = 0;
1176285Snate@binkert.org    mcp->m_memTfawBusy = 0;
1186285Snate@binkert.org    mcp->m_memRefresh = 0;
1196285Snate@binkert.org    mcp->m_memRead = 0;
1206285Snate@binkert.org    mcp->m_memWrite = 0;
1216285Snate@binkert.org    mcp->m_memWaitCycles = 0;
1226285Snate@binkert.org    mcp->m_memInputQ = 0;
1236285Snate@binkert.org    mcp->m_memBankQ = 0;
1246285Snate@binkert.org    mcp->m_memArbWait = 0;
1256285Snate@binkert.org    mcp->m_memRandBusy = 0;
1266285Snate@binkert.org    mcp->m_memNotOld = 0;
1276285Snate@binkert.org
1286285Snate@binkert.org    mcp->m_banks_per_rank = RubySystem::getMemoryControl((*it).c_str())->getBanksPerRank();
1296285Snate@binkert.org    mcp->m_ranks_per_dimm = RubySystem::getMemoryControl((*it).c_str())->getRanksPerDimm();
1306285Snate@binkert.org    mcp->m_dimms_per_channel = RubySystem::getMemoryControl((*it).c_str())->getDimmsPerChannel();
1316285Snate@binkert.org
1326285Snate@binkert.org    int totalBanks = mcp->m_banks_per_rank
1336285Snate@binkert.org                 * mcp->m_ranks_per_dimm
1346285Snate@binkert.org                 * mcp->m_dimms_per_channel;
1356285Snate@binkert.org
1366285Snate@binkert.org    mcp->m_memBankCount.setSize(totalBanks);
1376285Snate@binkert.org
1386285Snate@binkert.org    m_memory_control_profilers [(*it).c_str()] = mcp;
1396285Snate@binkert.org  }
1406285Snate@binkert.org
1416285Snate@binkert.org  clearStats();
1426285Snate@binkert.org  m_hot_lines = false;
1436285Snate@binkert.org  m_all_instructions = false;
1446285Snate@binkert.org
1456285Snate@binkert.org  m_address_profiler_ptr = new AddressProfiler;
1466285Snate@binkert.org  m_address_profiler_ptr -> setHotLines(m_hot_lines);
1476285Snate@binkert.org  m_address_profiler_ptr -> setAllInstructions(m_all_instructions);
1486285Snate@binkert.org
1496285Snate@binkert.org  if (m_all_instructions) {
1506285Snate@binkert.org    m_inst_profiler_ptr = new AddressProfiler;
1516285Snate@binkert.org    m_inst_profiler_ptr -> setHotLines(m_hot_lines);
1526285Snate@binkert.org    m_inst_profiler_ptr -> setAllInstructions(m_all_instructions);
1536285Snate@binkert.org  }
1546285Snate@binkert.org}
1556285Snate@binkert.org
1566145Snate@binkert.orgvoid Profiler::wakeup()
1576145Snate@binkert.org{
1586145Snate@binkert.org  // FIXME - avoid the repeated code
1596145Snate@binkert.org
1606145Snate@binkert.org  Vector<integer_t> perProcCycleCount;
1616285Snate@binkert.org  perProcCycleCount.setSize(RubySystem::getNumberOfSequencers());
1626145Snate@binkert.org
1636285Snate@binkert.org  for(int i=0; i < RubySystem::getNumberOfSequencers(); i++) {
1646285Snate@binkert.org    perProcCycleCount[i] = g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1;
1656145Snate@binkert.org    // The +1 allows us to avoid division by zero
1666145Snate@binkert.org  }
1676145Snate@binkert.org
1686145Snate@binkert.org  integer_t total_misses = m_perProcTotalMisses.sum();
1696285Snate@binkert.org  integer_t simics_cycles_executed = perProcCycleCount.sum();
1706145Snate@binkert.org  integer_t transactions_started = m_perProcStartTransaction.sum();
1716145Snate@binkert.org  integer_t transactions_ended = m_perProcEndTransaction.sum();
1726145Snate@binkert.org
1736145Snate@binkert.org  (*m_periodic_output_file_ptr) << "ruby_cycles: " << g_eventQueue_ptr->getTime()-m_ruby_start << endl;
1746145Snate@binkert.org  (*m_periodic_output_file_ptr) << "total_misses: " << total_misses << " " << m_perProcTotalMisses << endl;
1756285Snate@binkert.org  (*m_periodic_output_file_ptr) << "simics_cycles_executed: " << simics_cycles_executed << " " << perProcCycleCount << endl;
1766145Snate@binkert.org  (*m_periodic_output_file_ptr) << "transactions_started: " << transactions_started << " " << m_perProcStartTransaction << endl;
1776145Snate@binkert.org  (*m_periodic_output_file_ptr) << "transactions_ended: " << transactions_ended << " " << m_perProcEndTransaction << endl;
1786145Snate@binkert.org  (*m_periodic_output_file_ptr) << "mbytes_resident: " << process_memory_resident() << endl;
1796145Snate@binkert.org  (*m_periodic_output_file_ptr) << "mbytes_total: " << process_memory_total() << endl;
1806145Snate@binkert.org  if (process_memory_total() > 0) {
1816145Snate@binkert.org    (*m_periodic_output_file_ptr) << "resident_ratio: " << process_memory_resident()/process_memory_total() << endl;
1826145Snate@binkert.org  }
1836145Snate@binkert.org  (*m_periodic_output_file_ptr) << "miss_latency: " << m_allMissLatencyHistogram << endl;
1846145Snate@binkert.org
1856145Snate@binkert.org  *m_periodic_output_file_ptr << endl;
1866145Snate@binkert.org
1876285Snate@binkert.org  if (m_all_instructions) {
1886145Snate@binkert.org    m_inst_profiler_ptr->printStats(*m_periodic_output_file_ptr);
1896145Snate@binkert.org  }
1906145Snate@binkert.org
1916145Snate@binkert.org  //g_system_ptr->getNetwork()->printStats(*m_periodic_output_file_ptr);
1926145Snate@binkert.org  g_eventQueue_ptr->scheduleEvent(this, m_stats_period);
1936145Snate@binkert.org}
1946145Snate@binkert.org
1956145Snate@binkert.orgvoid Profiler::setPeriodicStatsFile(const string& filename)
1966145Snate@binkert.org{
1976145Snate@binkert.org  cout << "Recording periodic statistics to file '" << filename << "' every "
1986145Snate@binkert.org       << m_stats_period << " Ruby cycles" << endl;
1996145Snate@binkert.org
2006145Snate@binkert.org  if (m_periodic_output_file_ptr != &cerr) {
2016145Snate@binkert.org    delete m_periodic_output_file_ptr;
2026145Snate@binkert.org  }
2036145Snate@binkert.org
2046145Snate@binkert.org  m_periodic_output_file_ptr = new ofstream(filename.c_str());
2056145Snate@binkert.org  g_eventQueue_ptr->scheduleEvent(this, 1);
2066145Snate@binkert.org}
2076145Snate@binkert.org
2086145Snate@binkert.orgvoid Profiler::setPeriodicStatsInterval(integer_t period)
2096145Snate@binkert.org{
2106145Snate@binkert.org  cout << "Recording periodic statistics every " << m_stats_period << " Ruby cycles" << endl;
2116145Snate@binkert.org  m_stats_period = period;
2126145Snate@binkert.org  g_eventQueue_ptr->scheduleEvent(this, 1);
2136145Snate@binkert.org}
2146145Snate@binkert.org
2156145Snate@binkert.orgvoid Profiler::printConfig(ostream& out) const
2166145Snate@binkert.org{
2176145Snate@binkert.org  out << endl;
2186145Snate@binkert.org  out << "Profiler Configuration" << endl;
2196145Snate@binkert.org  out << "----------------------" << endl;
2206145Snate@binkert.org  out << "periodic_stats_period: " << m_stats_period << endl;
2216145Snate@binkert.org}
2226145Snate@binkert.org
2236145Snate@binkert.orgvoid Profiler::print(ostream& out) const
2246145Snate@binkert.org{
2256145Snate@binkert.org  out << "[Profiler]";
2266145Snate@binkert.org}
2276145Snate@binkert.org
2286145Snate@binkert.orgvoid Profiler::printStats(ostream& out, bool short_stats)
2296145Snate@binkert.org{
2306145Snate@binkert.org  out << endl;
2316145Snate@binkert.org  if (short_stats) {
2326145Snate@binkert.org    out << "SHORT ";
2336145Snate@binkert.org  }
2346145Snate@binkert.org  out << "Profiler Stats" << endl;
2356145Snate@binkert.org  out << "--------------" << endl;
2366145Snate@binkert.org
2376145Snate@binkert.org  time_t real_time_current = time(NULL);
2386145Snate@binkert.org  double seconds = difftime(real_time_current, m_real_time_start_time);
2396145Snate@binkert.org  double minutes = seconds/60.0;
2406145Snate@binkert.org  double hours = minutes/60.0;
2416145Snate@binkert.org  double days = hours/24.0;
2426145Snate@binkert.org  Time ruby_cycles = g_eventQueue_ptr->getTime()-m_ruby_start;
2436145Snate@binkert.org
2446145Snate@binkert.org  if (!short_stats) {
2456145Snate@binkert.org    out << "Elapsed_time_in_seconds: " << seconds << endl;
2466145Snate@binkert.org    out << "Elapsed_time_in_minutes: " << minutes << endl;
2476145Snate@binkert.org    out << "Elapsed_time_in_hours: " << hours << endl;
2486145Snate@binkert.org    out << "Elapsed_time_in_days: " << days << endl;
2496145Snate@binkert.org    out << endl;
2506145Snate@binkert.org  }
2516145Snate@binkert.org
2526145Snate@binkert.org  // print the virtual runtimes as well
2536145Snate@binkert.org  struct tms vtime;
2546145Snate@binkert.org  times(&vtime);
2556145Snate@binkert.org  seconds = (vtime.tms_utime + vtime.tms_stime) / 100.0;
2566145Snate@binkert.org  minutes = seconds / 60.0;
2576145Snate@binkert.org  hours = minutes / 60.0;
2586145Snate@binkert.org  days = hours / 24.0;
2596145Snate@binkert.org  out << "Virtual_time_in_seconds: " << seconds << endl;
2606145Snate@binkert.org  out << "Virtual_time_in_minutes: " << minutes << endl;
2616145Snate@binkert.org  out << "Virtual_time_in_hours:   " << hours << endl;
2626433Sdrh5@cs.wisc.edu  out << "Virtual_time_in_days:    " << days << endl;
2636145Snate@binkert.org  out << endl;
2646145Snate@binkert.org
2656145Snate@binkert.org  out << "Ruby_current_time: " << g_eventQueue_ptr->getTime() << endl;
2666145Snate@binkert.org  out << "Ruby_start_time: " << m_ruby_start << endl;
2676145Snate@binkert.org  out << "Ruby_cycles: " << ruby_cycles << endl;
2686145Snate@binkert.org  out << endl;
2696145Snate@binkert.org
2706145Snate@binkert.org  if (!short_stats) {
2716145Snate@binkert.org    out << "mbytes_resident: " << process_memory_resident() << endl;
2726145Snate@binkert.org    out << "mbytes_total: " << process_memory_total() << endl;
2736145Snate@binkert.org    if (process_memory_total() > 0) {
2746145Snate@binkert.org      out << "resident_ratio: " << process_memory_resident()/process_memory_total() << endl;
2756145Snate@binkert.org    }
2766145Snate@binkert.org    out << endl;
2776145Snate@binkert.org
2786145Snate@binkert.org  }
2796145Snate@binkert.org
2806145Snate@binkert.org  Vector<integer_t> perProcCycleCount;
2816145Snate@binkert.org  Vector<double> perProcCyclesPerTrans;
2826145Snate@binkert.org  Vector<double> perProcMissesPerTrans;
2836145Snate@binkert.org
2846433Sdrh5@cs.wisc.edu
2856285Snate@binkert.org  perProcCycleCount.setSize(RubySystem::getNumberOfSequencers());
2866285Snate@binkert.org  perProcCyclesPerTrans.setSize(RubySystem::getNumberOfSequencers());
2876285Snate@binkert.org  perProcMissesPerTrans.setSize(RubySystem::getNumberOfSequencers());
2886145Snate@binkert.org
2896285Snate@binkert.org  for(int i=0; i < RubySystem::getNumberOfSequencers(); i++) {
2906285Snate@binkert.org    perProcCycleCount[i] = g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1;
2916145Snate@binkert.org    // The +1 allows us to avoid division by zero
2926145Snate@binkert.org
2936145Snate@binkert.org    int trans = m_perProcEndTransaction[i];
2946145Snate@binkert.org    if (trans == 0) {
2956145Snate@binkert.org      perProcCyclesPerTrans[i] = 0;
2966145Snate@binkert.org      perProcMissesPerTrans[i] = 0;
2976145Snate@binkert.org    } else {
2986145Snate@binkert.org      perProcCyclesPerTrans[i] = ruby_cycles / double(trans);
2996145Snate@binkert.org      perProcMissesPerTrans[i] = m_perProcTotalMisses[i] / double(trans);
3006145Snate@binkert.org    }
3016145Snate@binkert.org  }
3026145Snate@binkert.org
3036145Snate@binkert.org  integer_t total_misses = m_perProcTotalMisses.sum();
3046145Snate@binkert.org  integer_t user_misses = m_perProcUserMisses.sum();
3056145Snate@binkert.org  integer_t supervisor_misses = m_perProcSupervisorMisses.sum();
3066285Snate@binkert.org  integer_t simics_cycles_executed = perProcCycleCount.sum();
3076145Snate@binkert.org  integer_t transactions_started = m_perProcStartTransaction.sum();
3086145Snate@binkert.org  integer_t transactions_ended = m_perProcEndTransaction.sum();
3096145Snate@binkert.org
3106285Snate@binkert.org  double cycles_per_transaction = (transactions_ended != 0) ? (RubySystem::getNumberOfSequencers() * double(ruby_cycles)) / double(transactions_ended) : 0;
3116145Snate@binkert.org  double misses_per_transaction = (transactions_ended != 0) ? double(total_misses) / double(transactions_ended) : 0;
3126145Snate@binkert.org
3136145Snate@binkert.org  out << "Total_misses: " << total_misses << endl;
3146145Snate@binkert.org  out << "total_misses: " << total_misses << " " << m_perProcTotalMisses << endl;
3156145Snate@binkert.org  out << "user_misses: " << user_misses << " " << m_perProcUserMisses << endl;
3166145Snate@binkert.org  out << "supervisor_misses: " << supervisor_misses << " " << m_perProcSupervisorMisses << endl;
3176145Snate@binkert.org  out << endl;
3186285Snate@binkert.org  out << "ruby_cycles_executed: " << simics_cycles_executed << " " << perProcCycleCount << endl;
3196145Snate@binkert.org  out << endl;
3206145Snate@binkert.org  out << "transactions_started: " << transactions_started << " " << m_perProcStartTransaction << endl;
3216145Snate@binkert.org  out << "transactions_ended: " << transactions_ended << " " << m_perProcEndTransaction << endl;
3226145Snate@binkert.org  out << "cycles_per_transaction: " << cycles_per_transaction  << " " << perProcCyclesPerTrans << endl;
3236145Snate@binkert.org  out << "misses_per_transaction: " << misses_per_transaction << " " << perProcMissesPerTrans << endl;
3246145Snate@binkert.org
3256145Snate@binkert.org  out << endl;
3266145Snate@binkert.org
3276145Snate@binkert.org  out << endl;
3286145Snate@binkert.org
3296285Snate@binkert.org  vector<string>::iterator it;
3306285Snate@binkert.org
3316285Snate@binkert.org  for ( it=m_memory_control_names.begin() ; it < m_memory_control_names.end(); it++ ){
3326285Snate@binkert.org    long long int m_memReq = m_memory_control_profilers[(*it).c_str()] -> m_memReq;
3336285Snate@binkert.org    long long int m_memRefresh = m_memory_control_profilers[(*it).c_str()] -> m_memRefresh;
3346285Snate@binkert.org    long long int m_memInputQ = m_memory_control_profilers[(*it).c_str()] -> m_memInputQ;
3356285Snate@binkert.org    long long int m_memBankQ = m_memory_control_profilers[(*it).c_str()] -> m_memBankQ;
3366285Snate@binkert.org    long long int m_memWaitCycles = m_memory_control_profilers[(*it).c_str()] -> m_memWaitCycles;
3376285Snate@binkert.org    long long int m_memRead = m_memory_control_profilers[(*it).c_str()] -> m_memRead;
3386285Snate@binkert.org    long long int m_memWrite = m_memory_control_profilers[(*it).c_str()] -> m_memWrite;
3396285Snate@binkert.org    long long int m_memBankBusy = m_memory_control_profilers[(*it).c_str()] -> m_memBankBusy;
3406285Snate@binkert.org    long long int m_memRandBusy = m_memory_control_profilers[(*it).c_str()] -> m_memRandBusy;
3416285Snate@binkert.org    long long int m_memNotOld = m_memory_control_profilers[(*it).c_str()] -> m_memNotOld;
3426285Snate@binkert.org    long long int m_memArbWait = m_memory_control_profilers[(*it).c_str()] -> m_memArbWait;
3436285Snate@binkert.org    long long int m_memBusBusy = m_memory_control_profilers[(*it).c_str()] -> m_memBusBusy;
3446285Snate@binkert.org    long long int m_memTfawBusy = m_memory_control_profilers[(*it).c_str()] -> m_memTfawBusy;
3456285Snate@binkert.org    long long int m_memReadWriteBusy = m_memory_control_profilers[(*it).c_str()] -> m_memReadWriteBusy;
3466285Snate@binkert.org    long long int m_memDataBusBusy = m_memory_control_profilers[(*it).c_str()] -> m_memDataBusBusy;
3476285Snate@binkert.org    Vector<long long int> m_memBankCount = m_memory_control_profilers[(*it).c_str()] -> m_memBankCount;
3486285Snate@binkert.org
3496285Snate@binkert.org    if (m_memReq || m_memRefresh) {    // if there's a memory controller at all
3506285Snate@binkert.org      long long int total_stalls = m_memInputQ + m_memBankQ + m_memWaitCycles;
3516285Snate@binkert.org      double stallsPerReq = total_stalls * 1.0 / m_memReq;
3526433Sdrh5@cs.wisc.edu      out << "Memory control " << (*it) << ":" << endl;
3536285Snate@binkert.org      out << "  memory_total_requests: " << m_memReq << endl;  // does not include refreshes
3546285Snate@binkert.org      out << "  memory_reads: " << m_memRead << endl;
3556285Snate@binkert.org      out << "  memory_writes: " << m_memWrite << endl;
3566285Snate@binkert.org      out << "  memory_refreshes: " << m_memRefresh << endl;
3576285Snate@binkert.org      out << "  memory_total_request_delays: " << total_stalls << endl;
3586285Snate@binkert.org      out << "  memory_delays_per_request: " << stallsPerReq << endl;
3596285Snate@binkert.org      out << "  memory_delays_in_input_queue: " << m_memInputQ << endl;
3606285Snate@binkert.org      out << "  memory_delays_behind_head_of_bank_queue: " << m_memBankQ << endl;
3616285Snate@binkert.org      out << "  memory_delays_stalled_at_head_of_bank_queue: " << m_memWaitCycles << endl;
3626285Snate@binkert.org      // Note:  The following "memory stalls" entries are a breakdown of the
3636285Snate@binkert.org      // cycles which already showed up in m_memWaitCycles.  The order is
3646285Snate@binkert.org      // significant; it is the priority of attributing the cycles.
3656285Snate@binkert.org      // For example, bank_busy is before arbitration because if the bank was
3666285Snate@binkert.org      // busy, we didn't even check arbitration.
3676285Snate@binkert.org      // Note:  "not old enough" means that since we grouped waiting heads-of-queues
3686285Snate@binkert.org      // into batches to avoid starvation, a request in a newer batch
3696285Snate@binkert.org      // didn't try to arbitrate yet because there are older requests waiting.
3706285Snate@binkert.org      out << "  memory_stalls_for_bank_busy: " << m_memBankBusy << endl;
3716285Snate@binkert.org      out << "  memory_stalls_for_random_busy: " << m_memRandBusy << endl;
3726285Snate@binkert.org      out << "  memory_stalls_for_anti_starvation: " << m_memNotOld << endl;
3736285Snate@binkert.org      out << "  memory_stalls_for_arbitration: " << m_memArbWait << endl;
3746285Snate@binkert.org      out << "  memory_stalls_for_bus: " << m_memBusBusy << endl;
3756285Snate@binkert.org      out << "  memory_stalls_for_tfaw: " << m_memTfawBusy << endl;
3766285Snate@binkert.org      out << "  memory_stalls_for_read_write_turnaround: " << m_memReadWriteBusy << endl;
3776285Snate@binkert.org      out << "  memory_stalls_for_read_read_turnaround: " << m_memDataBusBusy << endl;
3786285Snate@binkert.org      out << "  accesses_per_bank: ";
3796285Snate@binkert.org      for (int bank=0; bank < m_memBankCount.size(); bank++) {
3806285Snate@binkert.org        out << m_memBankCount[bank] << "  ";
3816285Snate@binkert.org        //if ((bank % 8) == 7) out << "                     " << endl;
3826285Snate@binkert.org      }
3836285Snate@binkert.org      out << endl;
3846285Snate@binkert.org      out << endl;
3856145Snate@binkert.org    }
3866145Snate@binkert.org  }
3876145Snate@binkert.org  if (!short_stats) {
3886145Snate@binkert.org    out << "Busy Controller Counts:" << endl;
3896145Snate@binkert.org    for(int i=0; i < MachineType_NUM; i++) {
3906145Snate@binkert.org      for(int j=0; j < MachineType_base_count((MachineType)i); j++) {
3916145Snate@binkert.org        MachineID machID;
3926145Snate@binkert.org        machID.type = (MachineType)i;
3936145Snate@binkert.org        machID.num = j;
3946145Snate@binkert.org        out << machID << ":" << m_busyControllerCount[i][j] << "  ";
3956145Snate@binkert.org        if ((j+1)%8 == 0) {
3966145Snate@binkert.org          out << endl;
3976145Snate@binkert.org        }
3986145Snate@binkert.org      }
3996145Snate@binkert.org      out << endl;
4006145Snate@binkert.org    }
4016145Snate@binkert.org    out << endl;
4026145Snate@binkert.org
4036145Snate@binkert.org    out << "Busy Bank Count:" << m_busyBankCount << endl;
4046145Snate@binkert.org    out << endl;
4056145Snate@binkert.org
4066145Snate@binkert.org    out << "sequencer_requests_outstanding: " << m_sequencer_requests << endl;
4076145Snate@binkert.org    out << endl;
4086145Snate@binkert.org  }
4096145Snate@binkert.org
4106145Snate@binkert.org  if (!short_stats) {
4116145Snate@binkert.org    out << "All Non-Zero Cycle Demand Cache Accesses" << endl;
4126145Snate@binkert.org    out << "----------------------------------------" << endl;
4136145Snate@binkert.org    out << "miss_latency: " << m_allMissLatencyHistogram << endl;
4146145Snate@binkert.org    for(int i=0; i<m_missLatencyHistograms.size(); i++) {
4156145Snate@binkert.org      if (m_missLatencyHistograms[i].size() > 0) {
4166285Snate@binkert.org        out << "miss_latency_" << RubyRequestType(i) << ": " << m_missLatencyHistograms[i] << endl;
4176145Snate@binkert.org      }
4186145Snate@binkert.org    }
4196145Snate@binkert.org    for(int i=0; i<m_machLatencyHistograms.size(); i++) {
4206145Snate@binkert.org      if (m_machLatencyHistograms[i].size() > 0) {
4216145Snate@binkert.org        out << "miss_latency_" << GenericMachineType(i) << ": " << m_machLatencyHistograms[i] << endl;
4226145Snate@binkert.org      }
4236145Snate@binkert.org    }
4246145Snate@binkert.org
4256145Snate@binkert.org    out << endl;
4266145Snate@binkert.org
4276145Snate@binkert.org    out << "All Non-Zero Cycle SW Prefetch Requests" << endl;
4286145Snate@binkert.org    out << "------------------------------------" << endl;
4296145Snate@binkert.org    out << "prefetch_latency: " << m_allSWPrefetchLatencyHistogram << endl;
4306145Snate@binkert.org    for(int i=0; i<m_SWPrefetchLatencyHistograms.size(); i++) {
4316145Snate@binkert.org      if (m_SWPrefetchLatencyHistograms[i].size() > 0) {
4326145Snate@binkert.org        out << "prefetch_latency_" << CacheRequestType(i) << ": " << m_SWPrefetchLatencyHistograms[i] << endl;
4336145Snate@binkert.org      }
4346145Snate@binkert.org    }
4356145Snate@binkert.org    for(int i=0; i<m_SWPrefetchMachLatencyHistograms.size(); i++) {
4366145Snate@binkert.org      if (m_SWPrefetchMachLatencyHistograms[i].size() > 0) {
4376145Snate@binkert.org        out << "prefetch_latency_" << GenericMachineType(i) << ": " << m_SWPrefetchMachLatencyHistograms[i] << endl;
4386145Snate@binkert.org      }
4396145Snate@binkert.org    }
4406145Snate@binkert.org    out << "prefetch_latency_L2Miss:" << m_SWPrefetchL2MissLatencyHistogram << endl;
4416145Snate@binkert.org
4426145Snate@binkert.org    if (m_all_sharing_histogram.size() > 0) {
4436145Snate@binkert.org      out << "all_sharing: " << m_all_sharing_histogram << endl;
4446145Snate@binkert.org      out << "read_sharing: " << m_read_sharing_histogram << endl;
4456145Snate@binkert.org      out << "write_sharing: " << m_write_sharing_histogram << endl;
4466145Snate@binkert.org
4476145Snate@binkert.org      out << "all_sharing_percent: "; m_all_sharing_histogram.printPercent(out); out << endl;
4486145Snate@binkert.org      out << "read_sharing_percent: "; m_read_sharing_histogram.printPercent(out); out << endl;
4496145Snate@binkert.org      out << "write_sharing_percent: "; m_write_sharing_histogram.printPercent(out); out << endl;
4506145Snate@binkert.org
4516145Snate@binkert.org      int64 total_miss = m_cache_to_cache +  m_memory_to_cache;
4526145Snate@binkert.org      out << "all_misses: " << total_miss << endl;
4536145Snate@binkert.org      out << "cache_to_cache_misses: " << m_cache_to_cache << endl;
4546145Snate@binkert.org      out << "memory_to_cache_misses: " << m_memory_to_cache << endl;
4556145Snate@binkert.org      out << "cache_to_cache_percent: " << 100.0 * (double(m_cache_to_cache) / double(total_miss)) << endl;
4566145Snate@binkert.org      out << "memory_to_cache_percent: " << 100.0 * (double(m_memory_to_cache) / double(total_miss)) << endl;
4576145Snate@binkert.org      out << endl;
4586145Snate@binkert.org    }
4596145Snate@binkert.org
4606145Snate@binkert.org    if (m_outstanding_requests.size() > 0) {
4616145Snate@binkert.org      out << "outstanding_requests: "; m_outstanding_requests.printPercent(out); out << endl;
4626145Snate@binkert.org      out << endl;
4636145Snate@binkert.org    }
4646145Snate@binkert.org  }
4656145Snate@binkert.org
4666145Snate@binkert.org  if (!short_stats) {
4676148Ssanchezd@stanford.edu    out << "Request vs. RubySystem State Profile" << endl;
4686145Snate@binkert.org    out << "--------------------------------" << endl;
4696145Snate@binkert.org    out << endl;
4706145Snate@binkert.org
4716145Snate@binkert.org    Vector<string> requestProfileKeys = m_requestProfileMap_ptr->keys();
4726145Snate@binkert.org    requestProfileKeys.sortVector();
4736145Snate@binkert.org
4746145Snate@binkert.org    for(int i=0; i<requestProfileKeys.size(); i++) {
4756145Snate@binkert.org      int temp_int = m_requestProfileMap_ptr->lookup(requestProfileKeys[i]);
4766145Snate@binkert.org      double percent = (100.0*double(temp_int))/double(m_requests);
4776145Snate@binkert.org      while (requestProfileKeys[i] != "") {
4786145Snate@binkert.org        out << setw(10) << string_split(requestProfileKeys[i], ':');
4796145Snate@binkert.org      }
4806145Snate@binkert.org      out << setw(11) << temp_int;
4816145Snate@binkert.org      out << setw(14) << percent << endl;
4826145Snate@binkert.org    }
4836145Snate@binkert.org    out << endl;
4846145Snate@binkert.org
4856145Snate@binkert.org    out << "filter_action: " << m_filter_action_histogram << endl;
4866145Snate@binkert.org
4876285Snate@binkert.org    if (!m_all_instructions) {
4886145Snate@binkert.org      m_address_profiler_ptr->printStats(out);
4896145Snate@binkert.org    }
4906145Snate@binkert.org
4916285Snate@binkert.org    if (m_all_instructions) {
4926145Snate@binkert.org      m_inst_profiler_ptr->printStats(out);
4936145Snate@binkert.org    }
4946145Snate@binkert.org
4956145Snate@binkert.org    out << endl;
4966145Snate@binkert.org    out << "Message Delayed Cycles" << endl;
4976145Snate@binkert.org    out << "----------------------" << endl;
4986145Snate@binkert.org    out << "Total_delay_cycles: " <<   m_delayedCyclesHistogram << endl;
4996145Snate@binkert.org    out << "Total_nonPF_delay_cycles: " << m_delayedCyclesNonPFHistogram << endl;
5006145Snate@binkert.org    for (int i = 0; i < m_delayedCyclesVCHistograms.size(); i++) {
5016145Snate@binkert.org      out << "  virtual_network_" << i << "_delay_cycles: " << m_delayedCyclesVCHistograms[i] << endl;
5026145Snate@binkert.org    }
5036145Snate@binkert.org
5046145Snate@binkert.org    printResourceUsage(out);
5056145Snate@binkert.org  }
5066145Snate@binkert.org
5076145Snate@binkert.org}
5086145Snate@binkert.org
5096145Snate@binkert.orgvoid Profiler::printResourceUsage(ostream& out) const
5106145Snate@binkert.org{
5116145Snate@binkert.org  out << endl;
5126145Snate@binkert.org  out << "Resource Usage" << endl;
5136145Snate@binkert.org  out << "--------------" << endl;
5146145Snate@binkert.org
5156145Snate@binkert.org  integer_t pagesize = getpagesize(); // page size in bytes
5166145Snate@binkert.org  out << "page_size: " << pagesize << endl;
5176145Snate@binkert.org
5186145Snate@binkert.org  rusage usage;
5196145Snate@binkert.org  getrusage (RUSAGE_SELF, &usage);
5206145Snate@binkert.org
5216145Snate@binkert.org  out << "user_time: " << usage.ru_utime.tv_sec << endl;
5226145Snate@binkert.org  out << "system_time: " << usage.ru_stime.tv_sec << endl;
5236145Snate@binkert.org  out << "page_reclaims: " << usage.ru_minflt << endl;
5246145Snate@binkert.org  out << "page_faults: " << usage.ru_majflt << endl;
5256145Snate@binkert.org  out << "swaps: " << usage.ru_nswap << endl;
5266145Snate@binkert.org  out << "block_inputs: " << usage.ru_inblock << endl;
5276145Snate@binkert.org  out << "block_outputs: " << usage.ru_oublock << endl;
5286145Snate@binkert.org}
5296145Snate@binkert.org
5306145Snate@binkert.orgvoid Profiler::clearStats()
5316145Snate@binkert.org{
5326145Snate@binkert.org  m_ruby_start = g_eventQueue_ptr->getTime();
5336145Snate@binkert.org
5346285Snate@binkert.org  m_cycles_executed_at_start.setSize(RubySystem::getNumberOfSequencers());
5356285Snate@binkert.org  for (int i=0; i < RubySystem::getNumberOfSequencers(); i++) {
5366145Snate@binkert.org    if (g_system_ptr == NULL) {
5376145Snate@binkert.org      m_cycles_executed_at_start[i] = 0;
5386145Snate@binkert.org    } else {
5396285Snate@binkert.org      m_cycles_executed_at_start[i] = g_system_ptr->getCycleCount(i);
5406145Snate@binkert.org    }
5416145Snate@binkert.org  }
5426145Snate@binkert.org
5436285Snate@binkert.org  m_perProcTotalMisses.setSize(RubySystem::getNumberOfSequencers());
5446285Snate@binkert.org  m_perProcUserMisses.setSize(RubySystem::getNumberOfSequencers());
5456285Snate@binkert.org  m_perProcSupervisorMisses.setSize(RubySystem::getNumberOfSequencers());
5466285Snate@binkert.org  m_perProcStartTransaction.setSize(RubySystem::getNumberOfSequencers());
5476285Snate@binkert.org  m_perProcEndTransaction.setSize(RubySystem::getNumberOfSequencers());
5486145Snate@binkert.org
5496285Snate@binkert.org  for(int i=0; i < RubySystem::getNumberOfSequencers(); i++) {
5506145Snate@binkert.org    m_perProcTotalMisses[i] = 0;
5516145Snate@binkert.org    m_perProcUserMisses[i] = 0;
5526145Snate@binkert.org    m_perProcSupervisorMisses[i] = 0;
5536145Snate@binkert.org    m_perProcStartTransaction[i] = 0;
5546145Snate@binkert.org    m_perProcEndTransaction[i] = 0;
5556145Snate@binkert.org  }
5566145Snate@binkert.org
5576145Snate@binkert.org  m_busyControllerCount.setSize(MachineType_NUM); // all machines
5586145Snate@binkert.org  for(int i=0; i < MachineType_NUM; i++) {
5596145Snate@binkert.org    m_busyControllerCount[i].setSize(MachineType_base_count((MachineType)i));
5606145Snate@binkert.org    for(int j=0; j < MachineType_base_count((MachineType)i); j++) {
5616145Snate@binkert.org      m_busyControllerCount[i][j] = 0;
5626145Snate@binkert.org    }
5636145Snate@binkert.org  }
5646145Snate@binkert.org  m_busyBankCount = 0;
5656145Snate@binkert.org
5666145Snate@binkert.org  m_delayedCyclesHistogram.clear();
5676145Snate@binkert.org  m_delayedCyclesNonPFHistogram.clear();
5686285Snate@binkert.org  m_delayedCyclesVCHistograms.setSize(RubySystem::getNetwork()->getNumberOfVirtualNetworks());
5696285Snate@binkert.org  for (int i = 0; i < RubySystem::getNetwork()->getNumberOfVirtualNetworks(); i++) {
5706145Snate@binkert.org    m_delayedCyclesVCHistograms[i].clear();
5716145Snate@binkert.org  }
5726145Snate@binkert.org
5736433Sdrh5@cs.wisc.edu  m_missLatencyHistograms.setSize(RubyRequestType_NUM);
5746145Snate@binkert.org  for(int i=0; i<m_missLatencyHistograms.size(); i++) {
5756145Snate@binkert.org    m_missLatencyHistograms[i].clear(200);
5766145Snate@binkert.org  }
5776145Snate@binkert.org  m_machLatencyHistograms.setSize(GenericMachineType_NUM+1);
5786145Snate@binkert.org  for(int i=0; i<m_machLatencyHistograms.size(); i++) {
5796145Snate@binkert.org    m_machLatencyHistograms[i].clear(200);
5806145Snate@binkert.org  }
5816145Snate@binkert.org  m_allMissLatencyHistogram.clear(200);
5826145Snate@binkert.org
5836145Snate@binkert.org  m_SWPrefetchLatencyHistograms.setSize(CacheRequestType_NUM);
5846145Snate@binkert.org  for(int i=0; i<m_SWPrefetchLatencyHistograms.size(); i++) {
5856145Snate@binkert.org    m_SWPrefetchLatencyHistograms[i].clear(200);
5866145Snate@binkert.org  }
5876145Snate@binkert.org  m_SWPrefetchMachLatencyHistograms.setSize(GenericMachineType_NUM+1);
5886145Snate@binkert.org  for(int i=0; i<m_SWPrefetchMachLatencyHistograms.size(); i++) {
5896145Snate@binkert.org    m_SWPrefetchMachLatencyHistograms[i].clear(200);
5906145Snate@binkert.org  }
5916145Snate@binkert.org  m_allSWPrefetchLatencyHistogram.clear(200);
5926145Snate@binkert.org
5936145Snate@binkert.org  m_sequencer_requests.clear();
5946145Snate@binkert.org  m_read_sharing_histogram.clear();
5956145Snate@binkert.org  m_write_sharing_histogram.clear();
5966145Snate@binkert.org  m_all_sharing_histogram.clear();
5976145Snate@binkert.org  m_cache_to_cache = 0;
5986145Snate@binkert.org  m_memory_to_cache = 0;
5996145Snate@binkert.org
6006145Snate@binkert.org  // clear HashMaps
6016145Snate@binkert.org  m_requestProfileMap_ptr->clear();
6026145Snate@binkert.org
6036145Snate@binkert.org  // count requests profiled
6046145Snate@binkert.org  m_requests = 0;
6056145Snate@binkert.org
6066145Snate@binkert.org  m_outstanding_requests.clear();
6076145Snate@binkert.org  m_outstanding_persistent_requests.clear();
6086145Snate@binkert.org
6096285Snate@binkert.org//added by SS
6106285Snate@binkert.org  vector<string>::iterator it;
6116145Snate@binkert.org
6126285Snate@binkert.org  for ( it=m_memory_control_names.begin() ; it < m_memory_control_names.end(); it++ ){
6136285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memReq = 0;
6146285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memBankBusy = 0;
6156285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memBusBusy = 0;
6166285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memTfawBusy = 0;
6176285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memReadWriteBusy = 0;
6186285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memDataBusBusy = 0;
6196285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memRefresh = 0;
6206285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memRead = 0;
6216285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memWrite = 0;
6226285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memWaitCycles = 0;
6236285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memInputQ = 0;
6246285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memBankQ = 0;
6256285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memArbWait = 0;
6266285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memRandBusy = 0;
6276285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memNotOld = 0;
6286285Snate@binkert.org
6296285Snate@binkert.org    for (int bank=0; bank < m_memory_control_profilers[(*it).c_str()] -> m_memBankCount.size(); bank++) {
6306285Snate@binkert.org        m_memory_control_profilers[(*it).c_str()] -> m_memBankCount[bank] = 0;
6316285Snate@binkert.org    }
6326285Snate@binkert.org  }
6336145Snate@binkert.org  // Flush the prefetches through the system - used so that there are no outstanding requests after stats are cleared
6346145Snate@binkert.org  //g_eventQueue_ptr->triggerAllEvents();
6356145Snate@binkert.org
6366145Snate@binkert.org  // update the start time
6376145Snate@binkert.org  m_ruby_start = g_eventQueue_ptr->getTime();
6386145Snate@binkert.org}
6396145Snate@binkert.org
6406145Snate@binkert.orgvoid Profiler::addAddressTraceSample(const CacheMsg& msg, NodeID id)
6416145Snate@binkert.org{
6426145Snate@binkert.org  if (msg.getType() != CacheRequestType_IFETCH) {
6436145Snate@binkert.org
6446145Snate@binkert.org    // Note: The following line should be commented out if you want to
6456145Snate@binkert.org    // use the special profiling that is part of the GS320 protocol
6466145Snate@binkert.org
6476372Sdrh5@cs.wisc.edu    // NOTE: Unless PROFILE_HOT_LINES is enabled, nothing will be profiled by the AddressProfiler
6486285Snate@binkert.org    m_address_profiler_ptr->addTraceSample(msg.getLineAddress(), msg.getProgramCounter(), msg.getType(), msg.getAccessMode(), id, false);
6496145Snate@binkert.org  }
6506145Snate@binkert.org}
6516145Snate@binkert.org
6526145Snate@binkert.orgvoid Profiler::profileSharing(const Address& addr, AccessType type, NodeID requestor, const Set& sharers, const Set& owner)
6536145Snate@binkert.org{
6546145Snate@binkert.org  Set set_contacted(owner);
6556145Snate@binkert.org  if (type == AccessType_Write) {
6566145Snate@binkert.org    set_contacted.addSet(sharers);
6576145Snate@binkert.org  }
6586145Snate@binkert.org  set_contacted.remove(requestor);
6596145Snate@binkert.org  int number_contacted = set_contacted.count();
6606145Snate@binkert.org
6616145Snate@binkert.org  if (type == AccessType_Write) {
6626145Snate@binkert.org    m_write_sharing_histogram.add(number_contacted);
6636145Snate@binkert.org  } else {
6646145Snate@binkert.org    m_read_sharing_histogram.add(number_contacted);
6656145Snate@binkert.org  }
6666145Snate@binkert.org  m_all_sharing_histogram.add(number_contacted);
6676145Snate@binkert.org
6686145Snate@binkert.org  if (number_contacted == 0) {
6696145Snate@binkert.org    m_memory_to_cache++;
6706145Snate@binkert.org  } else {
6716145Snate@binkert.org    m_cache_to_cache++;
6726145Snate@binkert.org  }
6736145Snate@binkert.org
6746145Snate@binkert.org}
6756145Snate@binkert.org
6766145Snate@binkert.orgvoid Profiler::profileMsgDelay(int virtualNetwork, int delayCycles) {
6776145Snate@binkert.org  assert(virtualNetwork < m_delayedCyclesVCHistograms.size());
6786145Snate@binkert.org  m_delayedCyclesHistogram.add(delayCycles);
6796145Snate@binkert.org  m_delayedCyclesVCHistograms[virtualNetwork].add(delayCycles);
6806145Snate@binkert.org  if (virtualNetwork != 0) {
6816145Snate@binkert.org    m_delayedCyclesNonPFHistogram.add(delayCycles);
6826145Snate@binkert.org  }
6836145Snate@binkert.org}
6846145Snate@binkert.org
6856145Snate@binkert.org// profiles original cache requests including PUTs
6866145Snate@binkert.orgvoid Profiler::profileRequest(const string& requestStr)
6876145Snate@binkert.org{
6886145Snate@binkert.org  m_requests++;
6896145Snate@binkert.org
6906145Snate@binkert.org  if (m_requestProfileMap_ptr->exist(requestStr)) {
6916145Snate@binkert.org    (m_requestProfileMap_ptr->lookup(requestStr))++;
6926145Snate@binkert.org  } else {
6936145Snate@binkert.org    m_requestProfileMap_ptr->add(requestStr, 1);
6946145Snate@binkert.org  }
6956145Snate@binkert.org}
6966145Snate@binkert.org
6976145Snate@binkert.orgvoid Profiler::startTransaction(int cpu)
6986145Snate@binkert.org{
6996145Snate@binkert.org  m_perProcStartTransaction[cpu]++;
7006145Snate@binkert.org}
7016145Snate@binkert.org
7026145Snate@binkert.orgvoid Profiler::endTransaction(int cpu)
7036145Snate@binkert.org{
7046145Snate@binkert.org  m_perProcEndTransaction[cpu]++;
7056145Snate@binkert.org}
7066145Snate@binkert.org
7076145Snate@binkert.orgvoid Profiler::controllerBusy(MachineID machID)
7086145Snate@binkert.org{
7096145Snate@binkert.org  m_busyControllerCount[(int)machID.type][(int)machID.num]++;
7106145Snate@binkert.org}
7116145Snate@binkert.org
7126145Snate@binkert.orgvoid Profiler::profilePFWait(Time waitTime)
7136145Snate@binkert.org{
7146145Snate@binkert.org  m_prefetchWaitHistogram.add(waitTime);
7156145Snate@binkert.org}
7166145Snate@binkert.org
7176145Snate@binkert.orgvoid Profiler::bankBusy()
7186145Snate@binkert.org{
7196145Snate@binkert.org  m_busyBankCount++;
7206145Snate@binkert.org}
7216145Snate@binkert.org
7226145Snate@binkert.org// non-zero cycle demand request
7236285Snate@binkert.orgvoid Profiler::missLatency(Time t, RubyRequestType type)
7246145Snate@binkert.org{
7256145Snate@binkert.org  m_allMissLatencyHistogram.add(t);
7266145Snate@binkert.org  m_missLatencyHistograms[type].add(t);
7276145Snate@binkert.org}
7286145Snate@binkert.org
7296145Snate@binkert.org// non-zero cycle prefetch request
7306145Snate@binkert.orgvoid Profiler::swPrefetchLatency(Time t, CacheRequestType type, GenericMachineType respondingMach)
7316145Snate@binkert.org{
7326145Snate@binkert.org  m_allSWPrefetchLatencyHistogram.add(t);
7336145Snate@binkert.org  m_SWPrefetchLatencyHistograms[type].add(t);
7346145Snate@binkert.org  m_SWPrefetchMachLatencyHistograms[respondingMach].add(t);
7356145Snate@binkert.org  if(respondingMach == GenericMachineType_Directory || respondingMach == GenericMachineType_NUM) {
7366145Snate@binkert.org    m_SWPrefetchL2MissLatencyHistogram.add(t);
7376145Snate@binkert.org  }
7386145Snate@binkert.org}
7396145Snate@binkert.org
7406285Snate@binkert.orgvoid Profiler::profileTransition(const string& component, NodeID version, Address addr,
7416145Snate@binkert.org                                 const string& state, const string& event,
7426145Snate@binkert.org                                 const string& next_state, const string& note)
7436145Snate@binkert.org{
7446145Snate@binkert.org  const int EVENT_SPACES = 20;
7456145Snate@binkert.org  const int ID_SPACES = 3;
7466145Snate@binkert.org  const int TIME_SPACES = 7;
7476145Snate@binkert.org  const int COMP_SPACES = 10;
7486145Snate@binkert.org  const int STATE_SPACES = 6;
7496145Snate@binkert.org
7506145Snate@binkert.org  if ((g_debug_ptr->getDebugTime() > 0) &&
7516145Snate@binkert.org      (g_eventQueue_ptr->getTime() >= g_debug_ptr->getDebugTime())) {
7526145Snate@binkert.org    (* debug_cout_ptr).flags(ios::right);
7536145Snate@binkert.org    (* debug_cout_ptr) << setw(TIME_SPACES) << g_eventQueue_ptr->getTime() << " ";
7546145Snate@binkert.org    (* debug_cout_ptr) << setw(ID_SPACES) << version << " ";
7556145Snate@binkert.org    (* debug_cout_ptr) << setw(COMP_SPACES) << component;
7566145Snate@binkert.org    (* debug_cout_ptr) << setw(EVENT_SPACES) << event << " ";
7576145Snate@binkert.org
7586285Snate@binkert.org    (* debug_cout_ptr).flags(ios::right);
7596285Snate@binkert.org    (* debug_cout_ptr) << setw(STATE_SPACES) << state;
7606285Snate@binkert.org    (* debug_cout_ptr) << ">";
7616285Snate@binkert.org    (* debug_cout_ptr).flags(ios::left);
7626285Snate@binkert.org    (* debug_cout_ptr) << setw(STATE_SPACES) << next_state;
7636285Snate@binkert.org
7646145Snate@binkert.org    (* debug_cout_ptr) << " " << addr << " " << note;
7656145Snate@binkert.org
7666145Snate@binkert.org    (* debug_cout_ptr) << endl;
7676145Snate@binkert.org  }
7686145Snate@binkert.org}
7696145Snate@binkert.org
7706145Snate@binkert.org// Helper function
7716145Snate@binkert.orgstatic double process_memory_total()
7726145Snate@binkert.org{
7736145Snate@binkert.org  const double MULTIPLIER = 4096.0/(1024.0*1024.0); // 4kB page size, 1024*1024 bytes per MB,
7746145Snate@binkert.org  ifstream proc_file;
7756145Snate@binkert.org  proc_file.open("/proc/self/statm");
7766145Snate@binkert.org  int total_size_in_pages = 0;
7776145Snate@binkert.org  int res_size_in_pages = 0;
7786145Snate@binkert.org  proc_file >> total_size_in_pages;
7796145Snate@binkert.org  proc_file >> res_size_in_pages;
7806145Snate@binkert.org  return double(total_size_in_pages)*MULTIPLIER; // size in megabytes
7816145Snate@binkert.org}
7826145Snate@binkert.org
7836145Snate@binkert.orgstatic double process_memory_resident()
7846145Snate@binkert.org{
7856145Snate@binkert.org  const double MULTIPLIER = 4096.0/(1024.0*1024.0); // 4kB page size, 1024*1024 bytes per MB,
7866145Snate@binkert.org  ifstream proc_file;
7876145Snate@binkert.org  proc_file.open("/proc/self/statm");
7886145Snate@binkert.org  int total_size_in_pages = 0;
7896145Snate@binkert.org  int res_size_in_pages = 0;
7906145Snate@binkert.org  proc_file >> total_size_in_pages;
7916145Snate@binkert.org  proc_file >> res_size_in_pages;
7926145Snate@binkert.org  return double(res_size_in_pages)*MULTIPLIER; // size in megabytes
7936145Snate@binkert.org}
7946145Snate@binkert.org
7956285Snate@binkert.orgvoid Profiler::rubyWatch(int id){
7966288Snate@binkert.org    //int rn_g1 = 0;//SIMICS_get_register_number(id, "g1");
7976285Snate@binkert.org  uint64 tr = 0;//SIMICS_read_register(id, rn_g1);
7986285Snate@binkert.org    Address watch_address = Address(tr);
7996285Snate@binkert.org    const int ID_SPACES = 3;
8006285Snate@binkert.org    const int TIME_SPACES = 7;
8016285Snate@binkert.org
8026285Snate@binkert.org    (* debug_cout_ptr).flags(ios::right);
8036285Snate@binkert.org    (* debug_cout_ptr) << setw(TIME_SPACES) << g_eventQueue_ptr->getTime() << " ";
8046285Snate@binkert.org    (* debug_cout_ptr) << setw(ID_SPACES) << id << " "
8056285Snate@binkert.org                       << "RUBY WATCH "
8066285Snate@binkert.org                       << watch_address
8076285Snate@binkert.org                       << endl;
8086285Snate@binkert.org
8096285Snate@binkert.org    if(!m_watch_address_list_ptr->exist(watch_address)){
8106285Snate@binkert.org      m_watch_address_list_ptr->add(watch_address, 1);
8116285Snate@binkert.org    }
8126285Snate@binkert.org}
8136285Snate@binkert.org
8146285Snate@binkert.orgbool Profiler::watchAddress(Address addr){
8156285Snate@binkert.org    if (m_watch_address_list_ptr->exist(addr))
8166285Snate@binkert.org      return true;
8176285Snate@binkert.org    else
8186285Snate@binkert.org      return false;
8196285Snate@binkert.org}
8206285Snate@binkert.org
8216433Sdrh5@cs.wisc.eduint64 Profiler::getTotalTransactionsExecuted() const {
8226433Sdrh5@cs.wisc.edu  return m_perProcEndTransaction.sum();
8236433Sdrh5@cs.wisc.edu}
8246433Sdrh5@cs.wisc.edu
8256285Snate@binkert.org// For MemoryControl:
8266285Snate@binkert.orgvoid Profiler::profileMemReq(string name, int bank) {
8276285Snate@binkert.org//  printf("name is %s", name.c_str());
8286285Snate@binkert.org  assert(m_memory_control_profilers.count(name) == 1);
8296285Snate@binkert.org  m_memory_control_profilers[name] -> m_memReq++;
8306285Snate@binkert.org  m_memory_control_profilers[name] -> m_memBankCount[bank]++;
8316285Snate@binkert.org}
8326285Snate@binkert.orgvoid Profiler::profileMemBankBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memBankBusy++; }
8336285Snate@binkert.orgvoid Profiler::profileMemBusBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memBusBusy++; }
8346285Snate@binkert.orgvoid Profiler::profileMemReadWriteBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memReadWriteBusy++; }
8356285Snate@binkert.orgvoid Profiler::profileMemDataBusBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memDataBusBusy++; }
8366285Snate@binkert.orgvoid Profiler::profileMemTfawBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memTfawBusy++; }
8376285Snate@binkert.orgvoid Profiler::profileMemRefresh(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memRefresh++; }
8386285Snate@binkert.orgvoid Profiler::profileMemRead(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memRead++; }
8396285Snate@binkert.orgvoid Profiler::profileMemWrite(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memWrite++; }
8406285Snate@binkert.orgvoid Profiler::profileMemWaitCycles(string name, int cycles) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memWaitCycles += cycles; }
8416285Snate@binkert.orgvoid Profiler::profileMemInputQ(string name, int cycles) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memInputQ += cycles; }
8426285Snate@binkert.orgvoid Profiler::profileMemBankQ(string name, int cycles) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memBankQ += cycles; }
8436285Snate@binkert.orgvoid Profiler::profileMemArbWait(string name, int cycles) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memArbWait += cycles; }
8446285Snate@binkert.orgvoid Profiler::profileMemRandBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memRandBusy++; }
8456285Snate@binkert.orgvoid Profiler::profileMemNotOld(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memNotOld++; }
8466285Snate@binkert.org
8476876Ssteve.reinhardt@amd.com
8486876Ssteve.reinhardt@amd.comProfiler *
8496876Ssteve.reinhardt@amd.comRubyProfilerParams::create()
8506876Ssteve.reinhardt@amd.com{
8516876Ssteve.reinhardt@amd.com    return new Profiler(this);
8526876Ssteve.reinhardt@amd.com}
853