Profiler.cc revision 6433
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
666145Snate@binkert.org// Allows use of times() library call, which determines virtual runtime
676145Snate@binkert.org#include <sys/times.h>
686145Snate@binkert.org
696145Snate@binkert.orgextern std::ostream * debug_cout_ptr;
706145Snate@binkert.org
716145Snate@binkert.orgstatic double process_memory_total();
726145Snate@binkert.orgstatic double process_memory_resident();
736145Snate@binkert.org
746285Snate@binkert.orgProfiler::Profiler(const string & name)
756145Snate@binkert.org{
766285Snate@binkert.org  m_name = name;
776145Snate@binkert.org  m_requestProfileMap_ptr = new Map<string, int>;
786145Snate@binkert.org
796285Snate@binkert.org  m_inst_profiler_ptr = NULL;
806285Snate@binkert.org  m_address_profiler_ptr = NULL;
816285Snate@binkert.org
826145Snate@binkert.org  m_real_time_start_time = time(NULL); // Not reset in clearStats()
836145Snate@binkert.org  m_stats_period = 1000000; // Default
846145Snate@binkert.org  m_periodic_output_file_ptr = &cerr;
856145Snate@binkert.org
866145Snate@binkert.org}
876145Snate@binkert.org
886145Snate@binkert.orgProfiler::~Profiler()
896145Snate@binkert.org{
906145Snate@binkert.org  if (m_periodic_output_file_ptr != &cerr) {
916145Snate@binkert.org    delete m_periodic_output_file_ptr;
926145Snate@binkert.org  }
936145Snate@binkert.org  delete m_requestProfileMap_ptr;
946145Snate@binkert.org}
956145Snate@binkert.org
966285Snate@binkert.orgvoid Profiler::init(const vector<string> & argv, vector<string> memory_control_names)
976285Snate@binkert.org{
986285Snate@binkert.org  // added by SS
996285Snate@binkert.org  vector<string>::iterator it;
1006285Snate@binkert.org  memory_control_profiler* mcp;
1016285Snate@binkert.org  m_memory_control_names = memory_control_names;
1026285Snate@binkert.org//  printf ( "Here in Profiler::init \n");
1036285Snate@binkert.org  for ( it=memory_control_names.begin() ; it < memory_control_names.end(); it++ ){
1046285Snate@binkert.org//    printf ( "Here in Profiler::init memory control name %s \n", (*it).c_str());
1056285Snate@binkert.org    mcp = new memory_control_profiler;
1066285Snate@binkert.org    mcp->m_memReq = 0;
1076285Snate@binkert.org    mcp->m_memBankBusy = 0;
1086285Snate@binkert.org    mcp->m_memBusBusy = 0;
1096285Snate@binkert.org    mcp->m_memReadWriteBusy = 0;
1106285Snate@binkert.org    mcp->m_memDataBusBusy = 0;
1116285Snate@binkert.org    mcp->m_memTfawBusy = 0;
1126285Snate@binkert.org    mcp->m_memRefresh = 0;
1136285Snate@binkert.org    mcp->m_memRead = 0;
1146285Snate@binkert.org    mcp->m_memWrite = 0;
1156285Snate@binkert.org    mcp->m_memWaitCycles = 0;
1166285Snate@binkert.org    mcp->m_memInputQ = 0;
1176285Snate@binkert.org    mcp->m_memBankQ = 0;
1186285Snate@binkert.org    mcp->m_memArbWait = 0;
1196285Snate@binkert.org    mcp->m_memRandBusy = 0;
1206285Snate@binkert.org    mcp->m_memNotOld = 0;
1216285Snate@binkert.org
1226285Snate@binkert.org    mcp->m_banks_per_rank = RubySystem::getMemoryControl((*it).c_str())->getBanksPerRank();
1236285Snate@binkert.org    mcp->m_ranks_per_dimm = RubySystem::getMemoryControl((*it).c_str())->getRanksPerDimm();
1246285Snate@binkert.org    mcp->m_dimms_per_channel = RubySystem::getMemoryControl((*it).c_str())->getDimmsPerChannel();
1256285Snate@binkert.org
1266285Snate@binkert.org    int totalBanks = mcp->m_banks_per_rank
1276285Snate@binkert.org                 * mcp->m_ranks_per_dimm
1286285Snate@binkert.org                 * mcp->m_dimms_per_channel;
1296285Snate@binkert.org
1306285Snate@binkert.org    mcp->m_memBankCount.setSize(totalBanks);
1316285Snate@binkert.org
1326285Snate@binkert.org    m_memory_control_profilers [(*it).c_str()] = mcp;
1336285Snate@binkert.org  }
1346285Snate@binkert.org
1356285Snate@binkert.org  clearStats();
1366285Snate@binkert.org  m_hot_lines = false;
1376285Snate@binkert.org  m_all_instructions = false;
1386285Snate@binkert.org
1396285Snate@binkert.org  for (size_t i=0; i<argv.size(); i+=2) {
1406285Snate@binkert.org    if ( argv[i] == "hot_lines") {
1416285Snate@binkert.org      m_hot_lines = (argv[i+1]=="true");
1426285Snate@binkert.org    } else if ( argv[i] == "all_instructions") {
1436285Snate@binkert.org      m_all_instructions = (argv[i+1]=="true");
1446285Snate@binkert.org    }else {
1456285Snate@binkert.org      cerr << "WARNING: Profiler: Unkown configuration parameter: " << argv[i] << endl;
1466285Snate@binkert.org      assert(false);
1476285Snate@binkert.org    }
1486285Snate@binkert.org  }
1496285Snate@binkert.org
1506285Snate@binkert.org  m_address_profiler_ptr = new AddressProfiler;
1516285Snate@binkert.org  m_address_profiler_ptr -> setHotLines(m_hot_lines);
1526285Snate@binkert.org  m_address_profiler_ptr -> setAllInstructions(m_all_instructions);
1536285Snate@binkert.org
1546285Snate@binkert.org  if (m_all_instructions) {
1556285Snate@binkert.org    m_inst_profiler_ptr = new AddressProfiler;
1566285Snate@binkert.org    m_inst_profiler_ptr -> setHotLines(m_hot_lines);
1576285Snate@binkert.org    m_inst_profiler_ptr -> setAllInstructions(m_all_instructions);
1586285Snate@binkert.org  }
1596285Snate@binkert.org}
1606285Snate@binkert.org
1616145Snate@binkert.orgvoid Profiler::wakeup()
1626145Snate@binkert.org{
1636145Snate@binkert.org  // FIXME - avoid the repeated code
1646145Snate@binkert.org
1656145Snate@binkert.org  Vector<integer_t> perProcCycleCount;
1666285Snate@binkert.org  perProcCycleCount.setSize(RubySystem::getNumberOfSequencers());
1676145Snate@binkert.org
1686285Snate@binkert.org  for(int i=0; i < RubySystem::getNumberOfSequencers(); i++) {
1696285Snate@binkert.org    perProcCycleCount[i] = g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1;
1706145Snate@binkert.org    // The +1 allows us to avoid division by zero
1716145Snate@binkert.org  }
1726145Snate@binkert.org
1736145Snate@binkert.org  integer_t total_misses = m_perProcTotalMisses.sum();
1746285Snate@binkert.org  integer_t simics_cycles_executed = perProcCycleCount.sum();
1756145Snate@binkert.org  integer_t transactions_started = m_perProcStartTransaction.sum();
1766145Snate@binkert.org  integer_t transactions_ended = m_perProcEndTransaction.sum();
1776145Snate@binkert.org
1786145Snate@binkert.org  (*m_periodic_output_file_ptr) << "ruby_cycles: " << g_eventQueue_ptr->getTime()-m_ruby_start << endl;
1796145Snate@binkert.org  (*m_periodic_output_file_ptr) << "total_misses: " << total_misses << " " << m_perProcTotalMisses << endl;
1806285Snate@binkert.org  (*m_periodic_output_file_ptr) << "simics_cycles_executed: " << simics_cycles_executed << " " << perProcCycleCount << endl;
1816145Snate@binkert.org  (*m_periodic_output_file_ptr) << "transactions_started: " << transactions_started << " " << m_perProcStartTransaction << endl;
1826145Snate@binkert.org  (*m_periodic_output_file_ptr) << "transactions_ended: " << transactions_ended << " " << m_perProcEndTransaction << endl;
1836145Snate@binkert.org  (*m_periodic_output_file_ptr) << "mbytes_resident: " << process_memory_resident() << endl;
1846145Snate@binkert.org  (*m_periodic_output_file_ptr) << "mbytes_total: " << process_memory_total() << endl;
1856145Snate@binkert.org  if (process_memory_total() > 0) {
1866145Snate@binkert.org    (*m_periodic_output_file_ptr) << "resident_ratio: " << process_memory_resident()/process_memory_total() << endl;
1876145Snate@binkert.org  }
1886145Snate@binkert.org  (*m_periodic_output_file_ptr) << "miss_latency: " << m_allMissLatencyHistogram << endl;
1896145Snate@binkert.org
1906145Snate@binkert.org  *m_periodic_output_file_ptr << endl;
1916145Snate@binkert.org
1926285Snate@binkert.org  if (m_all_instructions) {
1936145Snate@binkert.org    m_inst_profiler_ptr->printStats(*m_periodic_output_file_ptr);
1946145Snate@binkert.org  }
1956145Snate@binkert.org
1966145Snate@binkert.org  //g_system_ptr->getNetwork()->printStats(*m_periodic_output_file_ptr);
1976145Snate@binkert.org  g_eventQueue_ptr->scheduleEvent(this, m_stats_period);
1986145Snate@binkert.org}
1996145Snate@binkert.org
2006145Snate@binkert.orgvoid Profiler::setPeriodicStatsFile(const string& filename)
2016145Snate@binkert.org{
2026145Snate@binkert.org  cout << "Recording periodic statistics to file '" << filename << "' every "
2036145Snate@binkert.org       << m_stats_period << " Ruby cycles" << endl;
2046145Snate@binkert.org
2056145Snate@binkert.org  if (m_periodic_output_file_ptr != &cerr) {
2066145Snate@binkert.org    delete m_periodic_output_file_ptr;
2076145Snate@binkert.org  }
2086145Snate@binkert.org
2096145Snate@binkert.org  m_periodic_output_file_ptr = new ofstream(filename.c_str());
2106145Snate@binkert.org  g_eventQueue_ptr->scheduleEvent(this, 1);
2116145Snate@binkert.org}
2126145Snate@binkert.org
2136145Snate@binkert.orgvoid Profiler::setPeriodicStatsInterval(integer_t period)
2146145Snate@binkert.org{
2156145Snate@binkert.org  cout << "Recording periodic statistics every " << m_stats_period << " Ruby cycles" << endl;
2166145Snate@binkert.org  m_stats_period = period;
2176145Snate@binkert.org  g_eventQueue_ptr->scheduleEvent(this, 1);
2186145Snate@binkert.org}
2196145Snate@binkert.org
2206145Snate@binkert.orgvoid Profiler::printConfig(ostream& out) const
2216145Snate@binkert.org{
2226145Snate@binkert.org  out << endl;
2236145Snate@binkert.org  out << "Profiler Configuration" << endl;
2246145Snate@binkert.org  out << "----------------------" << endl;
2256145Snate@binkert.org  out << "periodic_stats_period: " << m_stats_period << endl;
2266145Snate@binkert.org}
2276145Snate@binkert.org
2286145Snate@binkert.orgvoid Profiler::print(ostream& out) const
2296145Snate@binkert.org{
2306145Snate@binkert.org  out << "[Profiler]";
2316145Snate@binkert.org}
2326145Snate@binkert.org
2336145Snate@binkert.orgvoid Profiler::printStats(ostream& out, bool short_stats)
2346145Snate@binkert.org{
2356145Snate@binkert.org  out << endl;
2366145Snate@binkert.org  if (short_stats) {
2376145Snate@binkert.org    out << "SHORT ";
2386145Snate@binkert.org  }
2396145Snate@binkert.org  out << "Profiler Stats" << endl;
2406145Snate@binkert.org  out << "--------------" << endl;
2416145Snate@binkert.org
2426145Snate@binkert.org  time_t real_time_current = time(NULL);
2436145Snate@binkert.org  double seconds = difftime(real_time_current, m_real_time_start_time);
2446145Snate@binkert.org  double minutes = seconds/60.0;
2456145Snate@binkert.org  double hours = minutes/60.0;
2466145Snate@binkert.org  double days = hours/24.0;
2476145Snate@binkert.org  Time ruby_cycles = g_eventQueue_ptr->getTime()-m_ruby_start;
2486145Snate@binkert.org
2496145Snate@binkert.org  if (!short_stats) {
2506145Snate@binkert.org    out << "Elapsed_time_in_seconds: " << seconds << endl;
2516145Snate@binkert.org    out << "Elapsed_time_in_minutes: " << minutes << endl;
2526145Snate@binkert.org    out << "Elapsed_time_in_hours: " << hours << endl;
2536145Snate@binkert.org    out << "Elapsed_time_in_days: " << days << endl;
2546145Snate@binkert.org    out << endl;
2556145Snate@binkert.org  }
2566145Snate@binkert.org
2576145Snate@binkert.org  // print the virtual runtimes as well
2586145Snate@binkert.org  struct tms vtime;
2596145Snate@binkert.org  times(&vtime);
2606145Snate@binkert.org  seconds = (vtime.tms_utime + vtime.tms_stime) / 100.0;
2616145Snate@binkert.org  minutes = seconds / 60.0;
2626145Snate@binkert.org  hours = minutes / 60.0;
2636145Snate@binkert.org  days = hours / 24.0;
2646145Snate@binkert.org  out << "Virtual_time_in_seconds: " << seconds << endl;
2656145Snate@binkert.org  out << "Virtual_time_in_minutes: " << minutes << endl;
2666145Snate@binkert.org  out << "Virtual_time_in_hours:   " << hours << endl;
2676433Sdrh5@cs.wisc.edu  out << "Virtual_time_in_days:    " << days << endl;
2686145Snate@binkert.org  out << endl;
2696145Snate@binkert.org
2706145Snate@binkert.org  out << "Ruby_current_time: " << g_eventQueue_ptr->getTime() << endl;
2716145Snate@binkert.org  out << "Ruby_start_time: " << m_ruby_start << endl;
2726145Snate@binkert.org  out << "Ruby_cycles: " << ruby_cycles << endl;
2736145Snate@binkert.org  out << endl;
2746145Snate@binkert.org
2756145Snate@binkert.org  if (!short_stats) {
2766145Snate@binkert.org    out << "mbytes_resident: " << process_memory_resident() << endl;
2776145Snate@binkert.org    out << "mbytes_total: " << process_memory_total() << endl;
2786145Snate@binkert.org    if (process_memory_total() > 0) {
2796145Snate@binkert.org      out << "resident_ratio: " << process_memory_resident()/process_memory_total() << endl;
2806145Snate@binkert.org    }
2816145Snate@binkert.org    out << endl;
2826145Snate@binkert.org
2836145Snate@binkert.org  }
2846145Snate@binkert.org
2856145Snate@binkert.org  Vector<integer_t> perProcCycleCount;
2866145Snate@binkert.org  Vector<double> perProcCyclesPerTrans;
2876145Snate@binkert.org  Vector<double> perProcMissesPerTrans;
2886145Snate@binkert.org
2896433Sdrh5@cs.wisc.edu
2906285Snate@binkert.org  perProcCycleCount.setSize(RubySystem::getNumberOfSequencers());
2916285Snate@binkert.org  perProcCyclesPerTrans.setSize(RubySystem::getNumberOfSequencers());
2926285Snate@binkert.org  perProcMissesPerTrans.setSize(RubySystem::getNumberOfSequencers());
2936145Snate@binkert.org
2946285Snate@binkert.org  for(int i=0; i < RubySystem::getNumberOfSequencers(); i++) {
2956285Snate@binkert.org    perProcCycleCount[i] = g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1;
2966145Snate@binkert.org    // The +1 allows us to avoid division by zero
2976145Snate@binkert.org
2986145Snate@binkert.org    int trans = m_perProcEndTransaction[i];
2996145Snate@binkert.org    if (trans == 0) {
3006145Snate@binkert.org      perProcCyclesPerTrans[i] = 0;
3016145Snate@binkert.org      perProcMissesPerTrans[i] = 0;
3026145Snate@binkert.org    } else {
3036145Snate@binkert.org      perProcCyclesPerTrans[i] = ruby_cycles / double(trans);
3046145Snate@binkert.org      perProcMissesPerTrans[i] = m_perProcTotalMisses[i] / double(trans);
3056145Snate@binkert.org    }
3066145Snate@binkert.org  }
3076145Snate@binkert.org
3086145Snate@binkert.org  integer_t total_misses = m_perProcTotalMisses.sum();
3096145Snate@binkert.org  integer_t user_misses = m_perProcUserMisses.sum();
3106145Snate@binkert.org  integer_t supervisor_misses = m_perProcSupervisorMisses.sum();
3116285Snate@binkert.org  integer_t simics_cycles_executed = perProcCycleCount.sum();
3126145Snate@binkert.org  integer_t transactions_started = m_perProcStartTransaction.sum();
3136145Snate@binkert.org  integer_t transactions_ended = m_perProcEndTransaction.sum();
3146145Snate@binkert.org
3156285Snate@binkert.org  double cycles_per_transaction = (transactions_ended != 0) ? (RubySystem::getNumberOfSequencers() * double(ruby_cycles)) / double(transactions_ended) : 0;
3166145Snate@binkert.org  double misses_per_transaction = (transactions_ended != 0) ? double(total_misses) / double(transactions_ended) : 0;
3176145Snate@binkert.org
3186145Snate@binkert.org  out << "Total_misses: " << total_misses << endl;
3196145Snate@binkert.org  out << "total_misses: " << total_misses << " " << m_perProcTotalMisses << endl;
3206145Snate@binkert.org  out << "user_misses: " << user_misses << " " << m_perProcUserMisses << endl;
3216145Snate@binkert.org  out << "supervisor_misses: " << supervisor_misses << " " << m_perProcSupervisorMisses << endl;
3226145Snate@binkert.org  out << endl;
3236285Snate@binkert.org  out << "ruby_cycles_executed: " << simics_cycles_executed << " " << perProcCycleCount << endl;
3246145Snate@binkert.org  out << endl;
3256145Snate@binkert.org  out << "transactions_started: " << transactions_started << " " << m_perProcStartTransaction << endl;
3266145Snate@binkert.org  out << "transactions_ended: " << transactions_ended << " " << m_perProcEndTransaction << endl;
3276145Snate@binkert.org  out << "cycles_per_transaction: " << cycles_per_transaction  << " " << perProcCyclesPerTrans << endl;
3286145Snate@binkert.org  out << "misses_per_transaction: " << misses_per_transaction << " " << perProcMissesPerTrans << endl;
3296145Snate@binkert.org
3306145Snate@binkert.org  out << endl;
3316145Snate@binkert.org
3326145Snate@binkert.org  out << endl;
3336145Snate@binkert.org
3346285Snate@binkert.org  vector<string>::iterator it;
3356285Snate@binkert.org
3366285Snate@binkert.org  for ( it=m_memory_control_names.begin() ; it < m_memory_control_names.end(); it++ ){
3376285Snate@binkert.org    long long int m_memReq = m_memory_control_profilers[(*it).c_str()] -> m_memReq;
3386285Snate@binkert.org    long long int m_memRefresh = m_memory_control_profilers[(*it).c_str()] -> m_memRefresh;
3396285Snate@binkert.org    long long int m_memInputQ = m_memory_control_profilers[(*it).c_str()] -> m_memInputQ;
3406285Snate@binkert.org    long long int m_memBankQ = m_memory_control_profilers[(*it).c_str()] -> m_memBankQ;
3416285Snate@binkert.org    long long int m_memWaitCycles = m_memory_control_profilers[(*it).c_str()] -> m_memWaitCycles;
3426285Snate@binkert.org    long long int m_memRead = m_memory_control_profilers[(*it).c_str()] -> m_memRead;
3436285Snate@binkert.org    long long int m_memWrite = m_memory_control_profilers[(*it).c_str()] -> m_memWrite;
3446285Snate@binkert.org    long long int m_memBankBusy = m_memory_control_profilers[(*it).c_str()] -> m_memBankBusy;
3456285Snate@binkert.org    long long int m_memRandBusy = m_memory_control_profilers[(*it).c_str()] -> m_memRandBusy;
3466285Snate@binkert.org    long long int m_memNotOld = m_memory_control_profilers[(*it).c_str()] -> m_memNotOld;
3476285Snate@binkert.org    long long int m_memArbWait = m_memory_control_profilers[(*it).c_str()] -> m_memArbWait;
3486285Snate@binkert.org    long long int m_memBusBusy = m_memory_control_profilers[(*it).c_str()] -> m_memBusBusy;
3496285Snate@binkert.org    long long int m_memTfawBusy = m_memory_control_profilers[(*it).c_str()] -> m_memTfawBusy;
3506285Snate@binkert.org    long long int m_memReadWriteBusy = m_memory_control_profilers[(*it).c_str()] -> m_memReadWriteBusy;
3516285Snate@binkert.org    long long int m_memDataBusBusy = m_memory_control_profilers[(*it).c_str()] -> m_memDataBusBusy;
3526285Snate@binkert.org    Vector<long long int> m_memBankCount = m_memory_control_profilers[(*it).c_str()] -> m_memBankCount;
3536285Snate@binkert.org
3546285Snate@binkert.org    if (m_memReq || m_memRefresh) {    // if there's a memory controller at all
3556285Snate@binkert.org      long long int total_stalls = m_memInputQ + m_memBankQ + m_memWaitCycles;
3566285Snate@binkert.org      double stallsPerReq = total_stalls * 1.0 / m_memReq;
3576433Sdrh5@cs.wisc.edu      out << "Memory control " << (*it) << ":" << endl;
3586285Snate@binkert.org      out << "  memory_total_requests: " << m_memReq << endl;  // does not include refreshes
3596285Snate@binkert.org      out << "  memory_reads: " << m_memRead << endl;
3606285Snate@binkert.org      out << "  memory_writes: " << m_memWrite << endl;
3616285Snate@binkert.org      out << "  memory_refreshes: " << m_memRefresh << endl;
3626285Snate@binkert.org      out << "  memory_total_request_delays: " << total_stalls << endl;
3636285Snate@binkert.org      out << "  memory_delays_per_request: " << stallsPerReq << endl;
3646285Snate@binkert.org      out << "  memory_delays_in_input_queue: " << m_memInputQ << endl;
3656285Snate@binkert.org      out << "  memory_delays_behind_head_of_bank_queue: " << m_memBankQ << endl;
3666285Snate@binkert.org      out << "  memory_delays_stalled_at_head_of_bank_queue: " << m_memWaitCycles << endl;
3676285Snate@binkert.org      // Note:  The following "memory stalls" entries are a breakdown of the
3686285Snate@binkert.org      // cycles which already showed up in m_memWaitCycles.  The order is
3696285Snate@binkert.org      // significant; it is the priority of attributing the cycles.
3706285Snate@binkert.org      // For example, bank_busy is before arbitration because if the bank was
3716285Snate@binkert.org      // busy, we didn't even check arbitration.
3726285Snate@binkert.org      // Note:  "not old enough" means that since we grouped waiting heads-of-queues
3736285Snate@binkert.org      // into batches to avoid starvation, a request in a newer batch
3746285Snate@binkert.org      // didn't try to arbitrate yet because there are older requests waiting.
3756285Snate@binkert.org      out << "  memory_stalls_for_bank_busy: " << m_memBankBusy << endl;
3766285Snate@binkert.org      out << "  memory_stalls_for_random_busy: " << m_memRandBusy << endl;
3776285Snate@binkert.org      out << "  memory_stalls_for_anti_starvation: " << m_memNotOld << endl;
3786285Snate@binkert.org      out << "  memory_stalls_for_arbitration: " << m_memArbWait << endl;
3796285Snate@binkert.org      out << "  memory_stalls_for_bus: " << m_memBusBusy << endl;
3806285Snate@binkert.org      out << "  memory_stalls_for_tfaw: " << m_memTfawBusy << endl;
3816285Snate@binkert.org      out << "  memory_stalls_for_read_write_turnaround: " << m_memReadWriteBusy << endl;
3826285Snate@binkert.org      out << "  memory_stalls_for_read_read_turnaround: " << m_memDataBusBusy << endl;
3836285Snate@binkert.org      out << "  accesses_per_bank: ";
3846285Snate@binkert.org      for (int bank=0; bank < m_memBankCount.size(); bank++) {
3856285Snate@binkert.org        out << m_memBankCount[bank] << "  ";
3866285Snate@binkert.org        //if ((bank % 8) == 7) out << "                     " << endl;
3876285Snate@binkert.org      }
3886285Snate@binkert.org      out << endl;
3896285Snate@binkert.org      out << endl;
3906145Snate@binkert.org    }
3916145Snate@binkert.org  }
3926145Snate@binkert.org  if (!short_stats) {
3936145Snate@binkert.org    out << "Busy Controller Counts:" << endl;
3946145Snate@binkert.org    for(int i=0; i < MachineType_NUM; i++) {
3956145Snate@binkert.org      for(int j=0; j < MachineType_base_count((MachineType)i); j++) {
3966145Snate@binkert.org        MachineID machID;
3976145Snate@binkert.org        machID.type = (MachineType)i;
3986145Snate@binkert.org        machID.num = j;
3996145Snate@binkert.org        out << machID << ":" << m_busyControllerCount[i][j] << "  ";
4006145Snate@binkert.org        if ((j+1)%8 == 0) {
4016145Snate@binkert.org          out << endl;
4026145Snate@binkert.org        }
4036145Snate@binkert.org      }
4046145Snate@binkert.org      out << endl;
4056145Snate@binkert.org    }
4066145Snate@binkert.org    out << endl;
4076145Snate@binkert.org
4086145Snate@binkert.org    out << "Busy Bank Count:" << m_busyBankCount << endl;
4096145Snate@binkert.org    out << endl;
4106145Snate@binkert.org
4116145Snate@binkert.org    out << "sequencer_requests_outstanding: " << m_sequencer_requests << endl;
4126145Snate@binkert.org    out << endl;
4136145Snate@binkert.org  }
4146145Snate@binkert.org
4156145Snate@binkert.org  if (!short_stats) {
4166145Snate@binkert.org    out << "All Non-Zero Cycle Demand Cache Accesses" << endl;
4176145Snate@binkert.org    out << "----------------------------------------" << endl;
4186145Snate@binkert.org    out << "miss_latency: " << m_allMissLatencyHistogram << endl;
4196145Snate@binkert.org    for(int i=0; i<m_missLatencyHistograms.size(); i++) {
4206145Snate@binkert.org      if (m_missLatencyHistograms[i].size() > 0) {
4216285Snate@binkert.org        out << "miss_latency_" << RubyRequestType(i) << ": " << m_missLatencyHistograms[i] << endl;
4226145Snate@binkert.org      }
4236145Snate@binkert.org    }
4246145Snate@binkert.org    for(int i=0; i<m_machLatencyHistograms.size(); i++) {
4256145Snate@binkert.org      if (m_machLatencyHistograms[i].size() > 0) {
4266145Snate@binkert.org        out << "miss_latency_" << GenericMachineType(i) << ": " << m_machLatencyHistograms[i] << endl;
4276145Snate@binkert.org      }
4286145Snate@binkert.org    }
4296145Snate@binkert.org
4306145Snate@binkert.org    out << endl;
4316145Snate@binkert.org
4326145Snate@binkert.org    out << "All Non-Zero Cycle SW Prefetch Requests" << endl;
4336145Snate@binkert.org    out << "------------------------------------" << endl;
4346145Snate@binkert.org    out << "prefetch_latency: " << m_allSWPrefetchLatencyHistogram << endl;
4356145Snate@binkert.org    for(int i=0; i<m_SWPrefetchLatencyHistograms.size(); i++) {
4366145Snate@binkert.org      if (m_SWPrefetchLatencyHistograms[i].size() > 0) {
4376145Snate@binkert.org        out << "prefetch_latency_" << CacheRequestType(i) << ": " << m_SWPrefetchLatencyHistograms[i] << endl;
4386145Snate@binkert.org      }
4396145Snate@binkert.org    }
4406145Snate@binkert.org    for(int i=0; i<m_SWPrefetchMachLatencyHistograms.size(); i++) {
4416145Snate@binkert.org      if (m_SWPrefetchMachLatencyHistograms[i].size() > 0) {
4426145Snate@binkert.org        out << "prefetch_latency_" << GenericMachineType(i) << ": " << m_SWPrefetchMachLatencyHistograms[i] << endl;
4436145Snate@binkert.org      }
4446145Snate@binkert.org    }
4456145Snate@binkert.org    out << "prefetch_latency_L2Miss:" << m_SWPrefetchL2MissLatencyHistogram << endl;
4466145Snate@binkert.org
4476145Snate@binkert.org    if (m_all_sharing_histogram.size() > 0) {
4486145Snate@binkert.org      out << "all_sharing: " << m_all_sharing_histogram << endl;
4496145Snate@binkert.org      out << "read_sharing: " << m_read_sharing_histogram << endl;
4506145Snate@binkert.org      out << "write_sharing: " << m_write_sharing_histogram << endl;
4516145Snate@binkert.org
4526145Snate@binkert.org      out << "all_sharing_percent: "; m_all_sharing_histogram.printPercent(out); out << endl;
4536145Snate@binkert.org      out << "read_sharing_percent: "; m_read_sharing_histogram.printPercent(out); out << endl;
4546145Snate@binkert.org      out << "write_sharing_percent: "; m_write_sharing_histogram.printPercent(out); out << endl;
4556145Snate@binkert.org
4566145Snate@binkert.org      int64 total_miss = m_cache_to_cache +  m_memory_to_cache;
4576145Snate@binkert.org      out << "all_misses: " << total_miss << endl;
4586145Snate@binkert.org      out << "cache_to_cache_misses: " << m_cache_to_cache << endl;
4596145Snate@binkert.org      out << "memory_to_cache_misses: " << m_memory_to_cache << endl;
4606145Snate@binkert.org      out << "cache_to_cache_percent: " << 100.0 * (double(m_cache_to_cache) / double(total_miss)) << endl;
4616145Snate@binkert.org      out << "memory_to_cache_percent: " << 100.0 * (double(m_memory_to_cache) / double(total_miss)) << endl;
4626145Snate@binkert.org      out << endl;
4636145Snate@binkert.org    }
4646145Snate@binkert.org
4656145Snate@binkert.org    if (m_outstanding_requests.size() > 0) {
4666145Snate@binkert.org      out << "outstanding_requests: "; m_outstanding_requests.printPercent(out); out << endl;
4676145Snate@binkert.org      out << endl;
4686145Snate@binkert.org    }
4696145Snate@binkert.org  }
4706145Snate@binkert.org
4716145Snate@binkert.org  if (!short_stats) {
4726148Ssanchezd@stanford.edu    out << "Request vs. RubySystem State Profile" << endl;
4736145Snate@binkert.org    out << "--------------------------------" << endl;
4746145Snate@binkert.org    out << endl;
4756145Snate@binkert.org
4766145Snate@binkert.org    Vector<string> requestProfileKeys = m_requestProfileMap_ptr->keys();
4776145Snate@binkert.org    requestProfileKeys.sortVector();
4786145Snate@binkert.org
4796145Snate@binkert.org    for(int i=0; i<requestProfileKeys.size(); i++) {
4806145Snate@binkert.org      int temp_int = m_requestProfileMap_ptr->lookup(requestProfileKeys[i]);
4816145Snate@binkert.org      double percent = (100.0*double(temp_int))/double(m_requests);
4826145Snate@binkert.org      while (requestProfileKeys[i] != "") {
4836145Snate@binkert.org        out << setw(10) << string_split(requestProfileKeys[i], ':');
4846145Snate@binkert.org      }
4856145Snate@binkert.org      out << setw(11) << temp_int;
4866145Snate@binkert.org      out << setw(14) << percent << endl;
4876145Snate@binkert.org    }
4886145Snate@binkert.org    out << endl;
4896145Snate@binkert.org
4906145Snate@binkert.org    out << "filter_action: " << m_filter_action_histogram << endl;
4916145Snate@binkert.org
4926285Snate@binkert.org    if (!m_all_instructions) {
4936145Snate@binkert.org      m_address_profiler_ptr->printStats(out);
4946145Snate@binkert.org    }
4956145Snate@binkert.org
4966285Snate@binkert.org    if (m_all_instructions) {
4976145Snate@binkert.org      m_inst_profiler_ptr->printStats(out);
4986145Snate@binkert.org    }
4996145Snate@binkert.org
5006145Snate@binkert.org    out << endl;
5016145Snate@binkert.org    out << "Message Delayed Cycles" << endl;
5026145Snate@binkert.org    out << "----------------------" << endl;
5036145Snate@binkert.org    out << "Total_delay_cycles: " <<   m_delayedCyclesHistogram << endl;
5046145Snate@binkert.org    out << "Total_nonPF_delay_cycles: " << m_delayedCyclesNonPFHistogram << endl;
5056145Snate@binkert.org    for (int i = 0; i < m_delayedCyclesVCHistograms.size(); i++) {
5066145Snate@binkert.org      out << "  virtual_network_" << i << "_delay_cycles: " << m_delayedCyclesVCHistograms[i] << endl;
5076145Snate@binkert.org    }
5086145Snate@binkert.org
5096145Snate@binkert.org    printResourceUsage(out);
5106145Snate@binkert.org  }
5116145Snate@binkert.org
5126145Snate@binkert.org}
5136145Snate@binkert.org
5146145Snate@binkert.orgvoid Profiler::printResourceUsage(ostream& out) const
5156145Snate@binkert.org{
5166145Snate@binkert.org  out << endl;
5176145Snate@binkert.org  out << "Resource Usage" << endl;
5186145Snate@binkert.org  out << "--------------" << endl;
5196145Snate@binkert.org
5206145Snate@binkert.org  integer_t pagesize = getpagesize(); // page size in bytes
5216145Snate@binkert.org  out << "page_size: " << pagesize << endl;
5226145Snate@binkert.org
5236145Snate@binkert.org  rusage usage;
5246145Snate@binkert.org  getrusage (RUSAGE_SELF, &usage);
5256145Snate@binkert.org
5266145Snate@binkert.org  out << "user_time: " << usage.ru_utime.tv_sec << endl;
5276145Snate@binkert.org  out << "system_time: " << usage.ru_stime.tv_sec << endl;
5286145Snate@binkert.org  out << "page_reclaims: " << usage.ru_minflt << endl;
5296145Snate@binkert.org  out << "page_faults: " << usage.ru_majflt << endl;
5306145Snate@binkert.org  out << "swaps: " << usage.ru_nswap << endl;
5316145Snate@binkert.org  out << "block_inputs: " << usage.ru_inblock << endl;
5326145Snate@binkert.org  out << "block_outputs: " << usage.ru_oublock << endl;
5336145Snate@binkert.org}
5346145Snate@binkert.org
5356145Snate@binkert.orgvoid Profiler::clearStats()
5366145Snate@binkert.org{
5376145Snate@binkert.org  m_ruby_start = g_eventQueue_ptr->getTime();
5386145Snate@binkert.org
5396285Snate@binkert.org  m_cycles_executed_at_start.setSize(RubySystem::getNumberOfSequencers());
5406285Snate@binkert.org  for (int i=0; i < RubySystem::getNumberOfSequencers(); i++) {
5416145Snate@binkert.org    if (g_system_ptr == NULL) {
5426145Snate@binkert.org      m_cycles_executed_at_start[i] = 0;
5436145Snate@binkert.org    } else {
5446285Snate@binkert.org      m_cycles_executed_at_start[i] = g_system_ptr->getCycleCount(i);
5456145Snate@binkert.org    }
5466145Snate@binkert.org  }
5476145Snate@binkert.org
5486285Snate@binkert.org  m_perProcTotalMisses.setSize(RubySystem::getNumberOfSequencers());
5496285Snate@binkert.org  m_perProcUserMisses.setSize(RubySystem::getNumberOfSequencers());
5506285Snate@binkert.org  m_perProcSupervisorMisses.setSize(RubySystem::getNumberOfSequencers());
5516285Snate@binkert.org  m_perProcStartTransaction.setSize(RubySystem::getNumberOfSequencers());
5526285Snate@binkert.org  m_perProcEndTransaction.setSize(RubySystem::getNumberOfSequencers());
5536145Snate@binkert.org
5546285Snate@binkert.org  for(int i=0; i < RubySystem::getNumberOfSequencers(); i++) {
5556145Snate@binkert.org    m_perProcTotalMisses[i] = 0;
5566145Snate@binkert.org    m_perProcUserMisses[i] = 0;
5576145Snate@binkert.org    m_perProcSupervisorMisses[i] = 0;
5586145Snate@binkert.org    m_perProcStartTransaction[i] = 0;
5596145Snate@binkert.org    m_perProcEndTransaction[i] = 0;
5606145Snate@binkert.org  }
5616145Snate@binkert.org
5626145Snate@binkert.org  m_busyControllerCount.setSize(MachineType_NUM); // all machines
5636145Snate@binkert.org  for(int i=0; i < MachineType_NUM; i++) {
5646145Snate@binkert.org    m_busyControllerCount[i].setSize(MachineType_base_count((MachineType)i));
5656145Snate@binkert.org    for(int j=0; j < MachineType_base_count((MachineType)i); j++) {
5666145Snate@binkert.org      m_busyControllerCount[i][j] = 0;
5676145Snate@binkert.org    }
5686145Snate@binkert.org  }
5696145Snate@binkert.org  m_busyBankCount = 0;
5706145Snate@binkert.org
5716145Snate@binkert.org  m_delayedCyclesHistogram.clear();
5726145Snate@binkert.org  m_delayedCyclesNonPFHistogram.clear();
5736285Snate@binkert.org  m_delayedCyclesVCHistograms.setSize(RubySystem::getNetwork()->getNumberOfVirtualNetworks());
5746285Snate@binkert.org  for (int i = 0; i < RubySystem::getNetwork()->getNumberOfVirtualNetworks(); i++) {
5756145Snate@binkert.org    m_delayedCyclesVCHistograms[i].clear();
5766145Snate@binkert.org  }
5776145Snate@binkert.org
5786433Sdrh5@cs.wisc.edu  m_missLatencyHistograms.setSize(RubyRequestType_NUM);
5796145Snate@binkert.org  for(int i=0; i<m_missLatencyHistograms.size(); i++) {
5806145Snate@binkert.org    m_missLatencyHistograms[i].clear(200);
5816145Snate@binkert.org  }
5826145Snate@binkert.org  m_machLatencyHistograms.setSize(GenericMachineType_NUM+1);
5836145Snate@binkert.org  for(int i=0; i<m_machLatencyHistograms.size(); i++) {
5846145Snate@binkert.org    m_machLatencyHistograms[i].clear(200);
5856145Snate@binkert.org  }
5866145Snate@binkert.org  m_allMissLatencyHistogram.clear(200);
5876145Snate@binkert.org
5886145Snate@binkert.org  m_SWPrefetchLatencyHistograms.setSize(CacheRequestType_NUM);
5896145Snate@binkert.org  for(int i=0; i<m_SWPrefetchLatencyHistograms.size(); i++) {
5906145Snate@binkert.org    m_SWPrefetchLatencyHistograms[i].clear(200);
5916145Snate@binkert.org  }
5926145Snate@binkert.org  m_SWPrefetchMachLatencyHistograms.setSize(GenericMachineType_NUM+1);
5936145Snate@binkert.org  for(int i=0; i<m_SWPrefetchMachLatencyHistograms.size(); i++) {
5946145Snate@binkert.org    m_SWPrefetchMachLatencyHistograms[i].clear(200);
5956145Snate@binkert.org  }
5966145Snate@binkert.org  m_allSWPrefetchLatencyHistogram.clear(200);
5976145Snate@binkert.org
5986145Snate@binkert.org  m_sequencer_requests.clear();
5996145Snate@binkert.org  m_read_sharing_histogram.clear();
6006145Snate@binkert.org  m_write_sharing_histogram.clear();
6016145Snate@binkert.org  m_all_sharing_histogram.clear();
6026145Snate@binkert.org  m_cache_to_cache = 0;
6036145Snate@binkert.org  m_memory_to_cache = 0;
6046145Snate@binkert.org
6056145Snate@binkert.org  // clear HashMaps
6066145Snate@binkert.org  m_requestProfileMap_ptr->clear();
6076145Snate@binkert.org
6086145Snate@binkert.org  // count requests profiled
6096145Snate@binkert.org  m_requests = 0;
6106145Snate@binkert.org
6116145Snate@binkert.org  m_outstanding_requests.clear();
6126145Snate@binkert.org  m_outstanding_persistent_requests.clear();
6136145Snate@binkert.org
6146285Snate@binkert.org//added by SS
6156285Snate@binkert.org  vector<string>::iterator it;
6166145Snate@binkert.org
6176285Snate@binkert.org  for ( it=m_memory_control_names.begin() ; it < m_memory_control_names.end(); it++ ){
6186285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memReq = 0;
6196285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memBankBusy = 0;
6206285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memBusBusy = 0;
6216285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memTfawBusy = 0;
6226285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memReadWriteBusy = 0;
6236285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memDataBusBusy = 0;
6246285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memRefresh = 0;
6256285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memRead = 0;
6266285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memWrite = 0;
6276285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memWaitCycles = 0;
6286285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memInputQ = 0;
6296285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memBankQ = 0;
6306285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memArbWait = 0;
6316285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memRandBusy = 0;
6326285Snate@binkert.org    m_memory_control_profilers[(*it).c_str()] -> m_memNotOld = 0;
6336285Snate@binkert.org
6346285Snate@binkert.org    for (int bank=0; bank < m_memory_control_profilers[(*it).c_str()] -> m_memBankCount.size(); bank++) {
6356285Snate@binkert.org        m_memory_control_profilers[(*it).c_str()] -> m_memBankCount[bank] = 0;
6366285Snate@binkert.org    }
6376285Snate@binkert.org  }
6386145Snate@binkert.org  // Flush the prefetches through the system - used so that there are no outstanding requests after stats are cleared
6396145Snate@binkert.org  //g_eventQueue_ptr->triggerAllEvents();
6406145Snate@binkert.org
6416145Snate@binkert.org  // update the start time
6426145Snate@binkert.org  m_ruby_start = g_eventQueue_ptr->getTime();
6436145Snate@binkert.org}
6446145Snate@binkert.org
6456145Snate@binkert.orgvoid Profiler::addAddressTraceSample(const CacheMsg& msg, NodeID id)
6466145Snate@binkert.org{
6476145Snate@binkert.org  if (msg.getType() != CacheRequestType_IFETCH) {
6486145Snate@binkert.org
6496145Snate@binkert.org    // Note: The following line should be commented out if you want to
6506145Snate@binkert.org    // use the special profiling that is part of the GS320 protocol
6516145Snate@binkert.org
6526372Sdrh5@cs.wisc.edu    // NOTE: Unless PROFILE_HOT_LINES is enabled, nothing will be profiled by the AddressProfiler
6536285Snate@binkert.org    m_address_profiler_ptr->addTraceSample(msg.getLineAddress(), msg.getProgramCounter(), msg.getType(), msg.getAccessMode(), id, false);
6546145Snate@binkert.org  }
6556145Snate@binkert.org}
6566145Snate@binkert.org
6576145Snate@binkert.orgvoid Profiler::profileSharing(const Address& addr, AccessType type, NodeID requestor, const Set& sharers, const Set& owner)
6586145Snate@binkert.org{
6596145Snate@binkert.org  Set set_contacted(owner);
6606145Snate@binkert.org  if (type == AccessType_Write) {
6616145Snate@binkert.org    set_contacted.addSet(sharers);
6626145Snate@binkert.org  }
6636145Snate@binkert.org  set_contacted.remove(requestor);
6646145Snate@binkert.org  int number_contacted = set_contacted.count();
6656145Snate@binkert.org
6666145Snate@binkert.org  if (type == AccessType_Write) {
6676145Snate@binkert.org    m_write_sharing_histogram.add(number_contacted);
6686145Snate@binkert.org  } else {
6696145Snate@binkert.org    m_read_sharing_histogram.add(number_contacted);
6706145Snate@binkert.org  }
6716145Snate@binkert.org  m_all_sharing_histogram.add(number_contacted);
6726145Snate@binkert.org
6736145Snate@binkert.org  if (number_contacted == 0) {
6746145Snate@binkert.org    m_memory_to_cache++;
6756145Snate@binkert.org  } else {
6766145Snate@binkert.org    m_cache_to_cache++;
6776145Snate@binkert.org  }
6786145Snate@binkert.org
6796145Snate@binkert.org}
6806145Snate@binkert.org
6816145Snate@binkert.orgvoid Profiler::profileMsgDelay(int virtualNetwork, int delayCycles) {
6826145Snate@binkert.org  assert(virtualNetwork < m_delayedCyclesVCHistograms.size());
6836145Snate@binkert.org  m_delayedCyclesHistogram.add(delayCycles);
6846145Snate@binkert.org  m_delayedCyclesVCHistograms[virtualNetwork].add(delayCycles);
6856145Snate@binkert.org  if (virtualNetwork != 0) {
6866145Snate@binkert.org    m_delayedCyclesNonPFHistogram.add(delayCycles);
6876145Snate@binkert.org  }
6886145Snate@binkert.org}
6896145Snate@binkert.org
6906145Snate@binkert.org// profiles original cache requests including PUTs
6916145Snate@binkert.orgvoid Profiler::profileRequest(const string& requestStr)
6926145Snate@binkert.org{
6936145Snate@binkert.org  m_requests++;
6946145Snate@binkert.org
6956145Snate@binkert.org  if (m_requestProfileMap_ptr->exist(requestStr)) {
6966145Snate@binkert.org    (m_requestProfileMap_ptr->lookup(requestStr))++;
6976145Snate@binkert.org  } else {
6986145Snate@binkert.org    m_requestProfileMap_ptr->add(requestStr, 1);
6996145Snate@binkert.org  }
7006145Snate@binkert.org}
7016145Snate@binkert.org
7026145Snate@binkert.orgvoid Profiler::startTransaction(int cpu)
7036145Snate@binkert.org{
7046145Snate@binkert.org  m_perProcStartTransaction[cpu]++;
7056145Snate@binkert.org}
7066145Snate@binkert.org
7076145Snate@binkert.orgvoid Profiler::endTransaction(int cpu)
7086145Snate@binkert.org{
7096145Snate@binkert.org  m_perProcEndTransaction[cpu]++;
7106145Snate@binkert.org}
7116145Snate@binkert.org
7126145Snate@binkert.orgvoid Profiler::controllerBusy(MachineID machID)
7136145Snate@binkert.org{
7146145Snate@binkert.org  m_busyControllerCount[(int)machID.type][(int)machID.num]++;
7156145Snate@binkert.org}
7166145Snate@binkert.org
7176145Snate@binkert.orgvoid Profiler::profilePFWait(Time waitTime)
7186145Snate@binkert.org{
7196145Snate@binkert.org  m_prefetchWaitHistogram.add(waitTime);
7206145Snate@binkert.org}
7216145Snate@binkert.org
7226145Snate@binkert.orgvoid Profiler::bankBusy()
7236145Snate@binkert.org{
7246145Snate@binkert.org  m_busyBankCount++;
7256145Snate@binkert.org}
7266145Snate@binkert.org
7276145Snate@binkert.org// non-zero cycle demand request
7286285Snate@binkert.orgvoid Profiler::missLatency(Time t, RubyRequestType type)
7296145Snate@binkert.org{
7306145Snate@binkert.org  m_allMissLatencyHistogram.add(t);
7316145Snate@binkert.org  m_missLatencyHistograms[type].add(t);
7326145Snate@binkert.org}
7336145Snate@binkert.org
7346145Snate@binkert.org// non-zero cycle prefetch request
7356145Snate@binkert.orgvoid Profiler::swPrefetchLatency(Time t, CacheRequestType type, GenericMachineType respondingMach)
7366145Snate@binkert.org{
7376145Snate@binkert.org  m_allSWPrefetchLatencyHistogram.add(t);
7386145Snate@binkert.org  m_SWPrefetchLatencyHistograms[type].add(t);
7396145Snate@binkert.org  m_SWPrefetchMachLatencyHistograms[respondingMach].add(t);
7406145Snate@binkert.org  if(respondingMach == GenericMachineType_Directory || respondingMach == GenericMachineType_NUM) {
7416145Snate@binkert.org    m_SWPrefetchL2MissLatencyHistogram.add(t);
7426145Snate@binkert.org  }
7436145Snate@binkert.org}
7446145Snate@binkert.org
7456285Snate@binkert.orgvoid Profiler::profileTransition(const string& component, NodeID version, Address addr,
7466145Snate@binkert.org                                 const string& state, const string& event,
7476145Snate@binkert.org                                 const string& next_state, const string& note)
7486145Snate@binkert.org{
7496145Snate@binkert.org  const int EVENT_SPACES = 20;
7506145Snate@binkert.org  const int ID_SPACES = 3;
7516145Snate@binkert.org  const int TIME_SPACES = 7;
7526145Snate@binkert.org  const int COMP_SPACES = 10;
7536145Snate@binkert.org  const int STATE_SPACES = 6;
7546145Snate@binkert.org
7556145Snate@binkert.org  if ((g_debug_ptr->getDebugTime() > 0) &&
7566145Snate@binkert.org      (g_eventQueue_ptr->getTime() >= g_debug_ptr->getDebugTime())) {
7576145Snate@binkert.org    (* debug_cout_ptr).flags(ios::right);
7586145Snate@binkert.org    (* debug_cout_ptr) << setw(TIME_SPACES) << g_eventQueue_ptr->getTime() << " ";
7596145Snate@binkert.org    (* debug_cout_ptr) << setw(ID_SPACES) << version << " ";
7606145Snate@binkert.org    (* debug_cout_ptr) << setw(COMP_SPACES) << component;
7616145Snate@binkert.org    (* debug_cout_ptr) << setw(EVENT_SPACES) << event << " ";
7626145Snate@binkert.org
7636285Snate@binkert.org    (* debug_cout_ptr).flags(ios::right);
7646285Snate@binkert.org    (* debug_cout_ptr) << setw(STATE_SPACES) << state;
7656285Snate@binkert.org    (* debug_cout_ptr) << ">";
7666285Snate@binkert.org    (* debug_cout_ptr).flags(ios::left);
7676285Snate@binkert.org    (* debug_cout_ptr) << setw(STATE_SPACES) << next_state;
7686285Snate@binkert.org
7696145Snate@binkert.org    (* debug_cout_ptr) << " " << addr << " " << note;
7706145Snate@binkert.org
7716145Snate@binkert.org    (* debug_cout_ptr) << endl;
7726145Snate@binkert.org  }
7736145Snate@binkert.org}
7746145Snate@binkert.org
7756145Snate@binkert.org// Helper function
7766145Snate@binkert.orgstatic double process_memory_total()
7776145Snate@binkert.org{
7786145Snate@binkert.org  const double MULTIPLIER = 4096.0/(1024.0*1024.0); // 4kB page size, 1024*1024 bytes per MB,
7796145Snate@binkert.org  ifstream proc_file;
7806145Snate@binkert.org  proc_file.open("/proc/self/statm");
7816145Snate@binkert.org  int total_size_in_pages = 0;
7826145Snate@binkert.org  int res_size_in_pages = 0;
7836145Snate@binkert.org  proc_file >> total_size_in_pages;
7846145Snate@binkert.org  proc_file >> res_size_in_pages;
7856145Snate@binkert.org  return double(total_size_in_pages)*MULTIPLIER; // size in megabytes
7866145Snate@binkert.org}
7876145Snate@binkert.org
7886145Snate@binkert.orgstatic double process_memory_resident()
7896145Snate@binkert.org{
7906145Snate@binkert.org  const double MULTIPLIER = 4096.0/(1024.0*1024.0); // 4kB page size, 1024*1024 bytes per MB,
7916145Snate@binkert.org  ifstream proc_file;
7926145Snate@binkert.org  proc_file.open("/proc/self/statm");
7936145Snate@binkert.org  int total_size_in_pages = 0;
7946145Snate@binkert.org  int res_size_in_pages = 0;
7956145Snate@binkert.org  proc_file >> total_size_in_pages;
7966145Snate@binkert.org  proc_file >> res_size_in_pages;
7976145Snate@binkert.org  return double(res_size_in_pages)*MULTIPLIER; // size in megabytes
7986145Snate@binkert.org}
7996145Snate@binkert.org
8006285Snate@binkert.orgvoid Profiler::rubyWatch(int id){
8016288Snate@binkert.org    //int rn_g1 = 0;//SIMICS_get_register_number(id, "g1");
8026285Snate@binkert.org  uint64 tr = 0;//SIMICS_read_register(id, rn_g1);
8036285Snate@binkert.org    Address watch_address = Address(tr);
8046285Snate@binkert.org    const int ID_SPACES = 3;
8056285Snate@binkert.org    const int TIME_SPACES = 7;
8066285Snate@binkert.org
8076285Snate@binkert.org    (* debug_cout_ptr).flags(ios::right);
8086285Snate@binkert.org    (* debug_cout_ptr) << setw(TIME_SPACES) << g_eventQueue_ptr->getTime() << " ";
8096285Snate@binkert.org    (* debug_cout_ptr) << setw(ID_SPACES) << id << " "
8106285Snate@binkert.org                       << "RUBY WATCH "
8116285Snate@binkert.org                       << watch_address
8126285Snate@binkert.org                       << endl;
8136285Snate@binkert.org
8146285Snate@binkert.org    if(!m_watch_address_list_ptr->exist(watch_address)){
8156285Snate@binkert.org      m_watch_address_list_ptr->add(watch_address, 1);
8166285Snate@binkert.org    }
8176285Snate@binkert.org}
8186285Snate@binkert.org
8196285Snate@binkert.orgbool Profiler::watchAddress(Address addr){
8206285Snate@binkert.org    if (m_watch_address_list_ptr->exist(addr))
8216285Snate@binkert.org      return true;
8226285Snate@binkert.org    else
8236285Snate@binkert.org      return false;
8246285Snate@binkert.org}
8256285Snate@binkert.org
8266433Sdrh5@cs.wisc.eduint64 Profiler::getTotalTransactionsExecuted() const {
8276433Sdrh5@cs.wisc.edu  return m_perProcEndTransaction.sum();
8286433Sdrh5@cs.wisc.edu}
8296433Sdrh5@cs.wisc.edu
8306285Snate@binkert.org// For MemoryControl:
8316285Snate@binkert.orgvoid Profiler::profileMemReq(string name, int bank) {
8326285Snate@binkert.org//  printf("name is %s", name.c_str());
8336285Snate@binkert.org  assert(m_memory_control_profilers.count(name) == 1);
8346285Snate@binkert.org  m_memory_control_profilers[name] -> m_memReq++;
8356285Snate@binkert.org  m_memory_control_profilers[name] -> m_memBankCount[bank]++;
8366285Snate@binkert.org}
8376285Snate@binkert.orgvoid Profiler::profileMemBankBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memBankBusy++; }
8386285Snate@binkert.orgvoid Profiler::profileMemBusBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memBusBusy++; }
8396285Snate@binkert.orgvoid Profiler::profileMemReadWriteBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memReadWriteBusy++; }
8406285Snate@binkert.orgvoid Profiler::profileMemDataBusBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memDataBusBusy++; }
8416285Snate@binkert.orgvoid Profiler::profileMemTfawBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memTfawBusy++; }
8426285Snate@binkert.orgvoid Profiler::profileMemRefresh(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memRefresh++; }
8436285Snate@binkert.orgvoid Profiler::profileMemRead(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memRead++; }
8446285Snate@binkert.orgvoid Profiler::profileMemWrite(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memWrite++; }
8456285Snate@binkert.orgvoid Profiler::profileMemWaitCycles(string name, int cycles) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memWaitCycles += cycles; }
8466285Snate@binkert.orgvoid Profiler::profileMemInputQ(string name, int cycles) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memInputQ += cycles; }
8476285Snate@binkert.orgvoid Profiler::profileMemBankQ(string name, int cycles) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memBankQ += cycles; }
8486285Snate@binkert.orgvoid Profiler::profileMemArbWait(string name, int cycles) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memArbWait += cycles; }
8496285Snate@binkert.orgvoid Profiler::profileMemRandBusy(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memRandBusy++; }
8506285Snate@binkert.orgvoid Profiler::profileMemNotOld(string name) {   assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memNotOld++; }
8516285Snate@binkert.org
852