Profiler.cc revision 8436
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 457002Snate@binkert.org// Allows use of times() library call, which determines virtual runtime 467002Snate@binkert.org#include <sys/resource.h> 477002Snate@binkert.org#include <sys/times.h> 487002Snate@binkert.org 497454Snate@binkert.org#include <algorithm> 507832Snate@binkert.org#include <fstream> 517454Snate@binkert.org 527454Snate@binkert.org#include "base/stl_helpers.hh" 537056Snate@binkert.org#include "base/str.hh" 547048Snate@binkert.org#include "mem/protocol/MachineType.hh" 557048Snate@binkert.org#include "mem/protocol/Protocol.hh" 568229Snate@binkert.org#include "mem/protocol/RubyRequest.hh" 577048Snate@binkert.org#include "mem/ruby/network/Network.hh" 587048Snate@binkert.org#include "mem/ruby/profiler/AddressProfiler.hh" 596154Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh" 606154Snate@binkert.org#include "mem/ruby/system/System.hh" 616876Ssteve.reinhardt@amd.com 627055Snate@binkert.orgusing namespace std; 637454Snate@binkert.orgusing m5::stl_helpers::operator<<; 647055Snate@binkert.org 656145Snate@binkert.orgstatic double process_memory_total(); 666145Snate@binkert.orgstatic double process_memory_resident(); 676145Snate@binkert.org 686876Ssteve.reinhardt@amd.comProfiler::Profiler(const Params *p) 696876Ssteve.reinhardt@amd.com : SimObject(p) 706145Snate@binkert.org{ 717048Snate@binkert.org m_inst_profiler_ptr = NULL; 727048Snate@binkert.org m_address_profiler_ptr = NULL; 736285Snate@binkert.org 747048Snate@binkert.org m_real_time_start_time = time(NULL); // Not reset in clearStats() 757048Snate@binkert.org m_stats_period = 1000000; // Default 767048Snate@binkert.org m_periodic_output_file_ptr = &cerr; 776145Snate@binkert.org 787048Snate@binkert.org m_hot_lines = p->hot_lines; 797048Snate@binkert.org m_all_instructions = p->all_instructions; 806876Ssteve.reinhardt@amd.com 817048Snate@binkert.org m_num_of_sequencers = p->num_of_sequencers; 826896SBrad.Beckmann@amd.com 837048Snate@binkert.org m_hot_lines = false; 847048Snate@binkert.org m_all_instructions = false; 856285Snate@binkert.org 867048Snate@binkert.org m_address_profiler_ptr = new AddressProfiler(m_num_of_sequencers); 877048Snate@binkert.org m_address_profiler_ptr->setHotLines(m_hot_lines); 887048Snate@binkert.org m_address_profiler_ptr->setAllInstructions(m_all_instructions); 896285Snate@binkert.org 907048Snate@binkert.org if (m_all_instructions) { 917048Snate@binkert.org m_inst_profiler_ptr = new AddressProfiler(m_num_of_sequencers); 927048Snate@binkert.org m_inst_profiler_ptr->setHotLines(m_hot_lines); 937048Snate@binkert.org m_inst_profiler_ptr->setAllInstructions(m_all_instructions); 947048Snate@binkert.org } 958436SBrad.Beckmann@amd.com 968436SBrad.Beckmann@amd.com p->ruby_system->registerProfiler(this); 976285Snate@binkert.org} 986285Snate@binkert.org 996889SBrad.Beckmann@amd.comProfiler::~Profiler() 1006889SBrad.Beckmann@amd.com{ 1017048Snate@binkert.org if (m_periodic_output_file_ptr != &cerr) { 1027048Snate@binkert.org delete m_periodic_output_file_ptr; 1037048Snate@binkert.org } 1046889SBrad.Beckmann@amd.com} 1056889SBrad.Beckmann@amd.com 1067048Snate@binkert.orgvoid 1077048Snate@binkert.orgProfiler::wakeup() 1086145Snate@binkert.org{ 1097048Snate@binkert.org // FIXME - avoid the repeated code 1106145Snate@binkert.org 1117454Snate@binkert.org vector<integer_t> perProcCycleCount(m_num_of_sequencers); 1126145Snate@binkert.org 1137048Snate@binkert.org for (int i = 0; i < m_num_of_sequencers; i++) { 1147048Snate@binkert.org perProcCycleCount[i] = 1157048Snate@binkert.org g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1; 1167048Snate@binkert.org // The +1 allows us to avoid division by zero 1177048Snate@binkert.org } 1186145Snate@binkert.org 1197048Snate@binkert.org ostream &out = *m_periodic_output_file_ptr; 1206889SBrad.Beckmann@amd.com 1217048Snate@binkert.org out << "ruby_cycles: " << g_eventQueue_ptr->getTime()-m_ruby_start << endl 1227048Snate@binkert.org << "mbytes_resident: " << process_memory_resident() << endl 1237048Snate@binkert.org << "mbytes_total: " << process_memory_total() << endl; 1246889SBrad.Beckmann@amd.com 1257048Snate@binkert.org if (process_memory_total() > 0) { 1267054Snate@binkert.org out << "resident_ratio: " 1277048Snate@binkert.org << process_memory_resident() / process_memory_total() << endl; 1287048Snate@binkert.org } 1296889SBrad.Beckmann@amd.com 1306145Snate@binkert.org out << "miss_latency: " << m_allMissLatencyHistogram << endl; 1316145Snate@binkert.org 1326145Snate@binkert.org out << endl; 1336145Snate@binkert.org 1347048Snate@binkert.org if (m_all_instructions) { 1357048Snate@binkert.org m_inst_profiler_ptr->printStats(out); 1366145Snate@binkert.org } 1376145Snate@binkert.org 1387048Snate@binkert.org //g_system_ptr->getNetwork()->printStats(out); 1397048Snate@binkert.org g_eventQueue_ptr->scheduleEvent(this, m_stats_period); 1407048Snate@binkert.org} 1417048Snate@binkert.org 1427048Snate@binkert.orgvoid 1437048Snate@binkert.orgProfiler::setPeriodicStatsFile(const string& filename) 1447048Snate@binkert.org{ 1457048Snate@binkert.org cout << "Recording periodic statistics to file '" << filename << "' every " 1467048Snate@binkert.org << m_stats_period << " Ruby cycles" << endl; 1477048Snate@binkert.org 1487048Snate@binkert.org if (m_periodic_output_file_ptr != &cerr) { 1497048Snate@binkert.org delete m_periodic_output_file_ptr; 1506145Snate@binkert.org } 1516145Snate@binkert.org 1527048Snate@binkert.org m_periodic_output_file_ptr = new ofstream(filename.c_str()); 1537048Snate@binkert.org g_eventQueue_ptr->scheduleEvent(this, 1); 1547048Snate@binkert.org} 1557048Snate@binkert.org 1567048Snate@binkert.orgvoid 1577048Snate@binkert.orgProfiler::setPeriodicStatsInterval(integer_t period) 1587048Snate@binkert.org{ 1597054Snate@binkert.org cout << "Recording periodic statistics every " << m_stats_period 1607048Snate@binkert.org << " Ruby cycles" << endl; 1617048Snate@binkert.org 1627048Snate@binkert.org m_stats_period = period; 1637048Snate@binkert.org g_eventQueue_ptr->scheduleEvent(this, 1); 1647048Snate@binkert.org} 1657048Snate@binkert.org 1667048Snate@binkert.orgvoid 1677048Snate@binkert.orgProfiler::printConfig(ostream& out) const 1687048Snate@binkert.org{ 1697048Snate@binkert.org out << endl; 1707048Snate@binkert.org out << "Profiler Configuration" << endl; 1717048Snate@binkert.org out << "----------------------" << endl; 1727048Snate@binkert.org out << "periodic_stats_period: " << m_stats_period << endl; 1737048Snate@binkert.org} 1747048Snate@binkert.org 1757048Snate@binkert.orgvoid 1767048Snate@binkert.orgProfiler::print(ostream& out) const 1777048Snate@binkert.org{ 1787048Snate@binkert.org out << "[Profiler]"; 1797048Snate@binkert.org} 1807048Snate@binkert.org 1817048Snate@binkert.orgvoid 1827048Snate@binkert.orgProfiler::printStats(ostream& out, bool short_stats) 1837048Snate@binkert.org{ 1847048Snate@binkert.org out << endl; 1857048Snate@binkert.org if (short_stats) { 1867048Snate@binkert.org out << "SHORT "; 1877048Snate@binkert.org } 1887048Snate@binkert.org out << "Profiler Stats" << endl; 1897048Snate@binkert.org out << "--------------" << endl; 1907048Snate@binkert.org 1917048Snate@binkert.org time_t real_time_current = time(NULL); 1927048Snate@binkert.org double seconds = difftime(real_time_current, m_real_time_start_time); 1937048Snate@binkert.org double minutes = seconds / 60.0; 1947048Snate@binkert.org double hours = minutes / 60.0; 1957048Snate@binkert.org double days = hours / 24.0; 1967048Snate@binkert.org Time ruby_cycles = g_eventQueue_ptr->getTime()-m_ruby_start; 1977048Snate@binkert.org 1987048Snate@binkert.org if (!short_stats) { 1997048Snate@binkert.org out << "Elapsed_time_in_seconds: " << seconds << endl; 2007048Snate@binkert.org out << "Elapsed_time_in_minutes: " << minutes << endl; 2017048Snate@binkert.org out << "Elapsed_time_in_hours: " << hours << endl; 2027048Snate@binkert.org out << "Elapsed_time_in_days: " << days << endl; 2037048Snate@binkert.org out << endl; 2047048Snate@binkert.org } 2057048Snate@binkert.org 2067048Snate@binkert.org // print the virtual runtimes as well 2077048Snate@binkert.org struct tms vtime; 2087048Snate@binkert.org times(&vtime); 2097048Snate@binkert.org seconds = (vtime.tms_utime + vtime.tms_stime) / 100.0; 2107048Snate@binkert.org minutes = seconds / 60.0; 2117048Snate@binkert.org hours = minutes / 60.0; 2127048Snate@binkert.org days = hours / 24.0; 2137048Snate@binkert.org out << "Virtual_time_in_seconds: " << seconds << endl; 2147048Snate@binkert.org out << "Virtual_time_in_minutes: " << minutes << endl; 2157048Snate@binkert.org out << "Virtual_time_in_hours: " << hours << endl; 2167048Snate@binkert.org out << "Virtual_time_in_days: " << days << endl; 2176145Snate@binkert.org out << endl; 2186145Snate@binkert.org 2197048Snate@binkert.org out << "Ruby_current_time: " << g_eventQueue_ptr->getTime() << endl; 2207048Snate@binkert.org out << "Ruby_start_time: " << m_ruby_start << endl; 2217048Snate@binkert.org out << "Ruby_cycles: " << ruby_cycles << endl; 2226145Snate@binkert.org out << endl; 2236145Snate@binkert.org 2247048Snate@binkert.org if (!short_stats) { 2257048Snate@binkert.org out << "mbytes_resident: " << process_memory_resident() << endl; 2267048Snate@binkert.org out << "mbytes_total: " << process_memory_total() << endl; 2277048Snate@binkert.org if (process_memory_total() > 0) { 2287054Snate@binkert.org out << "resident_ratio: " 2297048Snate@binkert.org << process_memory_resident()/process_memory_total() << endl; 2307048Snate@binkert.org } 2317048Snate@binkert.org out << endl; 2326145Snate@binkert.org } 2336145Snate@binkert.org 2347454Snate@binkert.org vector<integer_t> perProcCycleCount(m_num_of_sequencers); 2357048Snate@binkert.org 2367048Snate@binkert.org for (int i = 0; i < m_num_of_sequencers; i++) { 2377048Snate@binkert.org perProcCycleCount[i] = 2387048Snate@binkert.org g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1; 2397048Snate@binkert.org // The +1 allows us to avoid division by zero 2406145Snate@binkert.org } 2416145Snate@binkert.org 2427048Snate@binkert.org out << "ruby_cycles_executed: " << perProcCycleCount << endl; 2437048Snate@binkert.org 2446145Snate@binkert.org out << endl; 2457048Snate@binkert.org 2467048Snate@binkert.org if (!short_stats) { 2477048Snate@binkert.org out << "Busy Controller Counts:" << endl; 2487048Snate@binkert.org for (int i = 0; i < MachineType_NUM; i++) { 2497048Snate@binkert.org int size = MachineType_base_count((MachineType)i); 2507048Snate@binkert.org for (int j = 0; j < size; j++) { 2517048Snate@binkert.org MachineID machID; 2527048Snate@binkert.org machID.type = (MachineType)i; 2537048Snate@binkert.org machID.num = j; 2547048Snate@binkert.org out << machID << ":" << m_busyControllerCount[i][j] << " "; 2557048Snate@binkert.org if ((j + 1) % 8 == 0) { 2567048Snate@binkert.org out << endl; 2577048Snate@binkert.org } 2587048Snate@binkert.org } 2597048Snate@binkert.org out << endl; 2607048Snate@binkert.org } 2617048Snate@binkert.org out << endl; 2627048Snate@binkert.org 2637048Snate@binkert.org out << "Busy Bank Count:" << m_busyBankCount << endl; 2647048Snate@binkert.org out << endl; 2657048Snate@binkert.org 2667048Snate@binkert.org out << "sequencer_requests_outstanding: " 2677048Snate@binkert.org << m_sequencer_requests << endl; 2687048Snate@binkert.org out << endl; 2696145Snate@binkert.org } 2706145Snate@binkert.org 2717048Snate@binkert.org if (!short_stats) { 2727048Snate@binkert.org out << "All Non-Zero Cycle Demand Cache Accesses" << endl; 2737048Snate@binkert.org out << "----------------------------------------" << endl; 2747048Snate@binkert.org out << "miss_latency: " << m_allMissLatencyHistogram << endl; 2757048Snate@binkert.org for (int i = 0; i < m_missLatencyHistograms.size(); i++) { 2767048Snate@binkert.org if (m_missLatencyHistograms[i].size() > 0) { 2777048Snate@binkert.org out << "miss_latency_" << RubyRequestType(i) << ": " 2787048Snate@binkert.org << m_missLatencyHistograms[i] << endl; 2797048Snate@binkert.org } 2807048Snate@binkert.org } 2817048Snate@binkert.org for (int i = 0; i < m_machLatencyHistograms.size(); i++) { 2827048Snate@binkert.org if (m_machLatencyHistograms[i].size() > 0) { 2837048Snate@binkert.org out << "miss_latency_" << GenericMachineType(i) << ": " 2847048Snate@binkert.org << m_machLatencyHistograms[i] << endl; 2857048Snate@binkert.org } 2867048Snate@binkert.org } 2876145Snate@binkert.org 2887565SBrad.Beckmann@amd.com out << "miss_latency_wCC_issue_to_initial_request: " 2897565SBrad.Beckmann@amd.com << m_wCCIssueToInitialRequestHistogram << endl; 2907565SBrad.Beckmann@amd.com out << "miss_latency_wCC_initial_forward_request: " 2917565SBrad.Beckmann@amd.com << m_wCCInitialRequestToForwardRequestHistogram << endl; 2927565SBrad.Beckmann@amd.com out << "miss_latency_wCC_forward_to_first_response: " 2937565SBrad.Beckmann@amd.com << m_wCCForwardRequestToFirstResponseHistogram << endl; 2947565SBrad.Beckmann@amd.com out << "miss_latency_wCC_first_response_to_completion: " 2957565SBrad.Beckmann@amd.com << m_wCCFirstResponseToCompleteHistogram << endl; 2967565SBrad.Beckmann@amd.com out << "imcomplete_wCC_Times: " << m_wCCIncompleteTimes << endl; 2977565SBrad.Beckmann@amd.com out << "miss_latency_dir_issue_to_initial_request: " 2987565SBrad.Beckmann@amd.com << m_dirIssueToInitialRequestHistogram << endl; 2997565SBrad.Beckmann@amd.com out << "miss_latency_dir_initial_forward_request: " 3007565SBrad.Beckmann@amd.com << m_dirInitialRequestToForwardRequestHistogram << endl; 3017565SBrad.Beckmann@amd.com out << "miss_latency_dir_forward_to_first_response: " 3027565SBrad.Beckmann@amd.com << m_dirForwardRequestToFirstResponseHistogram << endl; 3037565SBrad.Beckmann@amd.com out << "miss_latency_dir_first_response_to_completion: " 3047565SBrad.Beckmann@amd.com << m_dirFirstResponseToCompleteHistogram << endl; 3057565SBrad.Beckmann@amd.com out << "imcomplete_dir_Times: " << m_dirIncompleteTimes << endl; 3067565SBrad.Beckmann@amd.com 3077565SBrad.Beckmann@amd.com for (int i = 0; i < m_missMachLatencyHistograms.size(); i++) { 3087565SBrad.Beckmann@amd.com for (int j = 0; j < m_missMachLatencyHistograms[i].size(); j++) { 3097565SBrad.Beckmann@amd.com if (m_missMachLatencyHistograms[i][j].size() > 0) { 3107565SBrad.Beckmann@amd.com out << "miss_latency_" << RubyRequestType(i) 3117565SBrad.Beckmann@amd.com << "_" << GenericMachineType(j) << ": " 3127565SBrad.Beckmann@amd.com << m_missMachLatencyHistograms[i][j] << endl; 3137565SBrad.Beckmann@amd.com } 3147565SBrad.Beckmann@amd.com } 3157565SBrad.Beckmann@amd.com } 3167565SBrad.Beckmann@amd.com 3177048Snate@binkert.org out << endl; 3187048Snate@binkert.org 3197048Snate@binkert.org out << "All Non-Zero Cycle SW Prefetch Requests" << endl; 3207048Snate@binkert.org out << "------------------------------------" << endl; 3217048Snate@binkert.org out << "prefetch_latency: " << m_allSWPrefetchLatencyHistogram << endl; 3227048Snate@binkert.org for (int i = 0; i < m_SWPrefetchLatencyHistograms.size(); i++) { 3237048Snate@binkert.org if (m_SWPrefetchLatencyHistograms[i].size() > 0) { 3248165Snilay@cs.wisc.edu out << "prefetch_latency_" << RubyRequestType(i) << ": " 3257048Snate@binkert.org << m_SWPrefetchLatencyHistograms[i] << endl; 3267048Snate@binkert.org } 3277048Snate@binkert.org } 3287048Snate@binkert.org for (int i = 0; i < m_SWPrefetchMachLatencyHistograms.size(); i++) { 3297048Snate@binkert.org if (m_SWPrefetchMachLatencyHistograms[i].size() > 0) { 3307048Snate@binkert.org out << "prefetch_latency_" << GenericMachineType(i) << ": " 3317048Snate@binkert.org << m_SWPrefetchMachLatencyHistograms[i] << endl; 3327048Snate@binkert.org } 3337048Snate@binkert.org } 3347048Snate@binkert.org out << "prefetch_latency_L2Miss:" 3357048Snate@binkert.org << m_SWPrefetchL2MissLatencyHistogram << endl; 3367048Snate@binkert.org 3377048Snate@binkert.org if (m_all_sharing_histogram.size() > 0) { 3387048Snate@binkert.org out << "all_sharing: " << m_all_sharing_histogram << endl; 3397048Snate@binkert.org out << "read_sharing: " << m_read_sharing_histogram << endl; 3407048Snate@binkert.org out << "write_sharing: " << m_write_sharing_histogram << endl; 3417048Snate@binkert.org 3427048Snate@binkert.org out << "all_sharing_percent: "; 3437048Snate@binkert.org m_all_sharing_histogram.printPercent(out); 3447048Snate@binkert.org out << endl; 3457048Snate@binkert.org 3467048Snate@binkert.org out << "read_sharing_percent: "; 3477048Snate@binkert.org m_read_sharing_histogram.printPercent(out); 3487048Snate@binkert.org out << endl; 3497048Snate@binkert.org 3507048Snate@binkert.org out << "write_sharing_percent: "; 3517048Snate@binkert.org m_write_sharing_histogram.printPercent(out); 3527048Snate@binkert.org out << endl; 3537048Snate@binkert.org 3547048Snate@binkert.org int64 total_miss = m_cache_to_cache + m_memory_to_cache; 3557048Snate@binkert.org out << "all_misses: " << total_miss << endl; 3567048Snate@binkert.org out << "cache_to_cache_misses: " << m_cache_to_cache << endl; 3577048Snate@binkert.org out << "memory_to_cache_misses: " << m_memory_to_cache << endl; 3587048Snate@binkert.org out << "cache_to_cache_percent: " 3597048Snate@binkert.org << 100.0 * (double(m_cache_to_cache) / double(total_miss)) 3607048Snate@binkert.org << endl; 3617048Snate@binkert.org out << "memory_to_cache_percent: " 3627048Snate@binkert.org << 100.0 * (double(m_memory_to_cache) / double(total_miss)) 3637048Snate@binkert.org << endl; 3647048Snate@binkert.org out << endl; 3657048Snate@binkert.org } 3667048Snate@binkert.org 3677048Snate@binkert.org if (m_outstanding_requests.size() > 0) { 3687048Snate@binkert.org out << "outstanding_requests: "; 3697048Snate@binkert.org m_outstanding_requests.printPercent(out); 3707048Snate@binkert.org out << endl; 3717048Snate@binkert.org out << endl; 3727048Snate@binkert.org } 3737048Snate@binkert.org } 3747048Snate@binkert.org 3757048Snate@binkert.org if (!short_stats) { 3767048Snate@binkert.org out << "Request vs. RubySystem State Profile" << endl; 3777048Snate@binkert.org out << "--------------------------------" << endl; 3787048Snate@binkert.org out << endl; 3797048Snate@binkert.org 3807455Snate@binkert.org map<string, int>::const_iterator i = m_requestProfileMap.begin(); 3817455Snate@binkert.org map<string, int>::const_iterator end = m_requestProfileMap.end(); 3827455Snate@binkert.org for (; i != end; ++i) { 3837455Snate@binkert.org const string &key = i->first; 3847455Snate@binkert.org int count = i->second; 3857048Snate@binkert.org 3867455Snate@binkert.org double percent = (100.0 * double(count)) / double(m_requests); 3877056Snate@binkert.org vector<string> items; 3887455Snate@binkert.org tokenize(items, key, ':'); 3897455Snate@binkert.org vector<string>::iterator j = items.begin(); 3907056Snate@binkert.org vector<string>::iterator end = items.end(); 3917455Snate@binkert.org for (; j != end; ++i) 3927455Snate@binkert.org out << setw(10) << *j; 3937455Snate@binkert.org out << setw(11) << count; 3947048Snate@binkert.org out << setw(14) << percent << endl; 3957048Snate@binkert.org } 3967048Snate@binkert.org out << endl; 3977048Snate@binkert.org 3987048Snate@binkert.org out << "filter_action: " << m_filter_action_histogram << endl; 3997048Snate@binkert.org 4007048Snate@binkert.org if (!m_all_instructions) { 4017048Snate@binkert.org m_address_profiler_ptr->printStats(out); 4027048Snate@binkert.org } 4037048Snate@binkert.org 4047048Snate@binkert.org if (m_all_instructions) { 4057048Snate@binkert.org m_inst_profiler_ptr->printStats(out); 4067048Snate@binkert.org } 4077048Snate@binkert.org 4087048Snate@binkert.org out << endl; 4097048Snate@binkert.org out << "Message Delayed Cycles" << endl; 4107048Snate@binkert.org out << "----------------------" << endl; 4117048Snate@binkert.org out << "Total_delay_cycles: " << m_delayedCyclesHistogram << endl; 4127048Snate@binkert.org out << "Total_nonPF_delay_cycles: " 4137048Snate@binkert.org << m_delayedCyclesNonPFHistogram << endl; 4147048Snate@binkert.org for (int i = 0; i < m_delayedCyclesVCHistograms.size(); i++) { 4157048Snate@binkert.org out << " virtual_network_" << i << "_delay_cycles: " 4167048Snate@binkert.org << m_delayedCyclesVCHistograms[i] << endl; 4177048Snate@binkert.org } 4187048Snate@binkert.org 4197048Snate@binkert.org printResourceUsage(out); 4207048Snate@binkert.org } 4216145Snate@binkert.org} 4226145Snate@binkert.org 4237048Snate@binkert.orgvoid 4247048Snate@binkert.orgProfiler::printResourceUsage(ostream& out) const 4256145Snate@binkert.org{ 4267048Snate@binkert.org out << endl; 4277048Snate@binkert.org out << "Resource Usage" << endl; 4287048Snate@binkert.org out << "--------------" << endl; 4296145Snate@binkert.org 4307048Snate@binkert.org integer_t pagesize = getpagesize(); // page size in bytes 4317048Snate@binkert.org out << "page_size: " << pagesize << endl; 4326145Snate@binkert.org 4337048Snate@binkert.org rusage usage; 4347048Snate@binkert.org getrusage (RUSAGE_SELF, &usage); 4356145Snate@binkert.org 4367048Snate@binkert.org out << "user_time: " << usage.ru_utime.tv_sec << endl; 4377048Snate@binkert.org out << "system_time: " << usage.ru_stime.tv_sec << endl; 4387048Snate@binkert.org out << "page_reclaims: " << usage.ru_minflt << endl; 4397048Snate@binkert.org out << "page_faults: " << usage.ru_majflt << endl; 4407048Snate@binkert.org out << "swaps: " << usage.ru_nswap << endl; 4417048Snate@binkert.org out << "block_inputs: " << usage.ru_inblock << endl; 4427048Snate@binkert.org out << "block_outputs: " << usage.ru_oublock << endl; 4436145Snate@binkert.org} 4446145Snate@binkert.org 4457048Snate@binkert.orgvoid 4467048Snate@binkert.orgProfiler::clearStats() 4476145Snate@binkert.org{ 4487048Snate@binkert.org m_ruby_start = g_eventQueue_ptr->getTime(); 4496145Snate@binkert.org 4507454Snate@binkert.org m_cycles_executed_at_start.resize(m_num_of_sequencers); 4517048Snate@binkert.org for (int i = 0; i < m_num_of_sequencers; i++) { 4527048Snate@binkert.org if (g_system_ptr == NULL) { 4537048Snate@binkert.org m_cycles_executed_at_start[i] = 0; 4547048Snate@binkert.org } else { 4557048Snate@binkert.org m_cycles_executed_at_start[i] = g_system_ptr->getCycleCount(i); 4567048Snate@binkert.org } 4576145Snate@binkert.org } 4586145Snate@binkert.org 4597454Snate@binkert.org m_busyControllerCount.resize(MachineType_NUM); // all machines 4607048Snate@binkert.org for (int i = 0; i < MachineType_NUM; i++) { 4617048Snate@binkert.org int size = MachineType_base_count((MachineType)i); 4627454Snate@binkert.org m_busyControllerCount[i].resize(size); 4637048Snate@binkert.org for (int j = 0; j < size; j++) { 4647048Snate@binkert.org m_busyControllerCount[i][j] = 0; 4657048Snate@binkert.org } 4666145Snate@binkert.org } 4677048Snate@binkert.org m_busyBankCount = 0; 4686145Snate@binkert.org 4697048Snate@binkert.org m_delayedCyclesHistogram.clear(); 4707048Snate@binkert.org m_delayedCyclesNonPFHistogram.clear(); 4717048Snate@binkert.org int size = RubySystem::getNetwork()->getNumberOfVirtualNetworks(); 4727454Snate@binkert.org m_delayedCyclesVCHistograms.resize(size); 4737048Snate@binkert.org for (int i = 0; i < size; i++) { 4747048Snate@binkert.org m_delayedCyclesVCHistograms[i].clear(); 4757048Snate@binkert.org } 4766145Snate@binkert.org 4777454Snate@binkert.org m_missLatencyHistograms.resize(RubyRequestType_NUM); 4787048Snate@binkert.org for (int i = 0; i < m_missLatencyHistograms.size(); i++) { 4797048Snate@binkert.org m_missLatencyHistograms[i].clear(200); 4807048Snate@binkert.org } 4817454Snate@binkert.org m_machLatencyHistograms.resize(GenericMachineType_NUM+1); 4827048Snate@binkert.org for (int i = 0; i < m_machLatencyHistograms.size(); i++) { 4837048Snate@binkert.org m_machLatencyHistograms[i].clear(200); 4847048Snate@binkert.org } 4857565SBrad.Beckmann@amd.com m_missMachLatencyHistograms.resize(RubyRequestType_NUM); 4867565SBrad.Beckmann@amd.com for (int i = 0; i < m_missLatencyHistograms.size(); i++) { 4877565SBrad.Beckmann@amd.com m_missMachLatencyHistograms[i].resize(GenericMachineType_NUM+1); 4887565SBrad.Beckmann@amd.com for (int j = 0; j < m_missMachLatencyHistograms[i].size(); j++) { 4897565SBrad.Beckmann@amd.com m_missMachLatencyHistograms[i][j].clear(200); 4907565SBrad.Beckmann@amd.com } 4917565SBrad.Beckmann@amd.com } 4927048Snate@binkert.org m_allMissLatencyHistogram.clear(200); 4937565SBrad.Beckmann@amd.com m_wCCIssueToInitialRequestHistogram.clear(200); 4947565SBrad.Beckmann@amd.com m_wCCInitialRequestToForwardRequestHistogram.clear(200); 4957565SBrad.Beckmann@amd.com m_wCCForwardRequestToFirstResponseHistogram.clear(200); 4967565SBrad.Beckmann@amd.com m_wCCFirstResponseToCompleteHistogram.clear(200); 4977565SBrad.Beckmann@amd.com m_wCCIncompleteTimes = 0; 4987565SBrad.Beckmann@amd.com m_dirIssueToInitialRequestHistogram.clear(200); 4997565SBrad.Beckmann@amd.com m_dirInitialRequestToForwardRequestHistogram.clear(200); 5007565SBrad.Beckmann@amd.com m_dirForwardRequestToFirstResponseHistogram.clear(200); 5017565SBrad.Beckmann@amd.com m_dirFirstResponseToCompleteHistogram.clear(200); 5027565SBrad.Beckmann@amd.com m_dirIncompleteTimes = 0; 5036145Snate@binkert.org 5048165Snilay@cs.wisc.edu m_SWPrefetchLatencyHistograms.resize(RubyRequestType_NUM); 5057048Snate@binkert.org for (int i = 0; i < m_SWPrefetchLatencyHistograms.size(); i++) { 5067048Snate@binkert.org m_SWPrefetchLatencyHistograms[i].clear(200); 5077048Snate@binkert.org } 5087454Snate@binkert.org m_SWPrefetchMachLatencyHistograms.resize(GenericMachineType_NUM+1); 5097048Snate@binkert.org for (int i = 0; i < m_SWPrefetchMachLatencyHistograms.size(); i++) { 5107048Snate@binkert.org m_SWPrefetchMachLatencyHistograms[i].clear(200); 5117048Snate@binkert.org } 5127048Snate@binkert.org m_allSWPrefetchLatencyHistogram.clear(200); 5136145Snate@binkert.org 5147048Snate@binkert.org m_sequencer_requests.clear(); 5157048Snate@binkert.org m_read_sharing_histogram.clear(); 5167048Snate@binkert.org m_write_sharing_histogram.clear(); 5177048Snate@binkert.org m_all_sharing_histogram.clear(); 5187048Snate@binkert.org m_cache_to_cache = 0; 5197048Snate@binkert.org m_memory_to_cache = 0; 5206145Snate@binkert.org 5217048Snate@binkert.org // clear HashMaps 5227455Snate@binkert.org m_requestProfileMap.clear(); 5236145Snate@binkert.org 5247048Snate@binkert.org // count requests profiled 5257048Snate@binkert.org m_requests = 0; 5266145Snate@binkert.org 5277048Snate@binkert.org m_outstanding_requests.clear(); 5287048Snate@binkert.org m_outstanding_persistent_requests.clear(); 5296145Snate@binkert.org 5307048Snate@binkert.org // Flush the prefetches through the system - used so that there 5317048Snate@binkert.org // are no outstanding requests after stats are cleared 5327048Snate@binkert.org //g_eventQueue_ptr->triggerAllEvents(); 5336145Snate@binkert.org 5347048Snate@binkert.org // update the start time 5357048Snate@binkert.org m_ruby_start = g_eventQueue_ptr->getTime(); 5366145Snate@binkert.org} 5376145Snate@binkert.org 5387048Snate@binkert.orgvoid 5398174Snilay@cs.wisc.eduProfiler::addAddressTraceSample(const RubyRequest& msg, NodeID id) 5406145Snate@binkert.org{ 5418165Snilay@cs.wisc.edu if (msg.getType() != RubyRequestType_IFETCH) { 5427048Snate@binkert.org // Note: The following line should be commented out if you 5437048Snate@binkert.org // want to use the special profiling that is part of the GS320 5447048Snate@binkert.org // protocol 5456145Snate@binkert.org 5467048Snate@binkert.org // NOTE: Unless PROFILE_HOT_LINES is enabled, nothing will be 5477048Snate@binkert.org // profiled by the AddressProfiler 5487048Snate@binkert.org m_address_profiler_ptr-> 5497048Snate@binkert.org addTraceSample(msg.getLineAddress(), msg.getProgramCounter(), 5507048Snate@binkert.org msg.getType(), msg.getAccessMode(), id, false); 5517048Snate@binkert.org } 5526145Snate@binkert.org} 5536145Snate@binkert.org 5547048Snate@binkert.orgvoid 5557048Snate@binkert.orgProfiler::profileSharing(const Address& addr, AccessType type, 5567048Snate@binkert.org NodeID requestor, const Set& sharers, 5577048Snate@binkert.org const Set& owner) 5586145Snate@binkert.org{ 5597048Snate@binkert.org Set set_contacted(owner); 5607048Snate@binkert.org if (type == AccessType_Write) { 5617048Snate@binkert.org set_contacted.addSet(sharers); 5627048Snate@binkert.org } 5637048Snate@binkert.org set_contacted.remove(requestor); 5647048Snate@binkert.org int number_contacted = set_contacted.count(); 5656145Snate@binkert.org 5667048Snate@binkert.org if (type == AccessType_Write) { 5677048Snate@binkert.org m_write_sharing_histogram.add(number_contacted); 5687048Snate@binkert.org } else { 5697048Snate@binkert.org m_read_sharing_histogram.add(number_contacted); 5707048Snate@binkert.org } 5717048Snate@binkert.org m_all_sharing_histogram.add(number_contacted); 5726145Snate@binkert.org 5737048Snate@binkert.org if (number_contacted == 0) { 5747048Snate@binkert.org m_memory_to_cache++; 5757048Snate@binkert.org } else { 5767048Snate@binkert.org m_cache_to_cache++; 5777048Snate@binkert.org } 5786145Snate@binkert.org} 5796145Snate@binkert.org 5807048Snate@binkert.orgvoid 5817048Snate@binkert.orgProfiler::profileMsgDelay(int virtualNetwork, int delayCycles) 5827048Snate@binkert.org{ 5837048Snate@binkert.org assert(virtualNetwork < m_delayedCyclesVCHistograms.size()); 5847048Snate@binkert.org m_delayedCyclesHistogram.add(delayCycles); 5857048Snate@binkert.org m_delayedCyclesVCHistograms[virtualNetwork].add(delayCycles); 5867048Snate@binkert.org if (virtualNetwork != 0) { 5877048Snate@binkert.org m_delayedCyclesNonPFHistogram.add(delayCycles); 5887048Snate@binkert.org } 5896145Snate@binkert.org} 5906145Snate@binkert.org 5916145Snate@binkert.org// profiles original cache requests including PUTs 5927048Snate@binkert.orgvoid 5937048Snate@binkert.orgProfiler::profileRequest(const string& requestStr) 5946145Snate@binkert.org{ 5957048Snate@binkert.org m_requests++; 5966145Snate@binkert.org 5977455Snate@binkert.org // if it doesn't exist, conveniently, it will be created with the 5987455Snate@binkert.org // default value which is 0 5997455Snate@binkert.org m_requestProfileMap[requestStr]++; 6006145Snate@binkert.org} 6016145Snate@binkert.org 6027048Snate@binkert.orgvoid 6037048Snate@binkert.orgProfiler::controllerBusy(MachineID machID) 6046145Snate@binkert.org{ 6057048Snate@binkert.org m_busyControllerCount[(int)machID.type][(int)machID.num]++; 6066145Snate@binkert.org} 6076145Snate@binkert.org 6087048Snate@binkert.orgvoid 6097048Snate@binkert.orgProfiler::profilePFWait(Time waitTime) 6106145Snate@binkert.org{ 6117048Snate@binkert.org m_prefetchWaitHistogram.add(waitTime); 6126145Snate@binkert.org} 6136145Snate@binkert.org 6147048Snate@binkert.orgvoid 6157048Snate@binkert.orgProfiler::bankBusy() 6166145Snate@binkert.org{ 6177048Snate@binkert.org m_busyBankCount++; 6186145Snate@binkert.org} 6196145Snate@binkert.org 6206145Snate@binkert.org// non-zero cycle demand request 6217048Snate@binkert.orgvoid 6227546SBrad.Beckmann@amd.comProfiler::missLatency(Time cycles, 6237546SBrad.Beckmann@amd.com RubyRequestType type, 6247546SBrad.Beckmann@amd.com const GenericMachineType respondingMach) 6256145Snate@binkert.org{ 6267546SBrad.Beckmann@amd.com m_allMissLatencyHistogram.add(cycles); 6277546SBrad.Beckmann@amd.com m_missLatencyHistograms[type].add(cycles); 6287546SBrad.Beckmann@amd.com m_machLatencyHistograms[respondingMach].add(cycles); 6297565SBrad.Beckmann@amd.com m_missMachLatencyHistograms[type][respondingMach].add(cycles); 6307565SBrad.Beckmann@amd.com} 6317565SBrad.Beckmann@amd.com 6327565SBrad.Beckmann@amd.comvoid 6337565SBrad.Beckmann@amd.comProfiler::missLatencyWcc(Time issuedTime, 6347565SBrad.Beckmann@amd.com Time initialRequestTime, 6357565SBrad.Beckmann@amd.com Time forwardRequestTime, 6367565SBrad.Beckmann@amd.com Time firstResponseTime, 6377565SBrad.Beckmann@amd.com Time completionTime) 6387565SBrad.Beckmann@amd.com{ 6397565SBrad.Beckmann@amd.com if ((issuedTime <= initialRequestTime) && 6407565SBrad.Beckmann@amd.com (initialRequestTime <= forwardRequestTime) && 6417565SBrad.Beckmann@amd.com (forwardRequestTime <= firstResponseTime) && 6427565SBrad.Beckmann@amd.com (firstResponseTime <= completionTime)) { 6437565SBrad.Beckmann@amd.com m_wCCIssueToInitialRequestHistogram.add(initialRequestTime - issuedTime); 6447565SBrad.Beckmann@amd.com 6457565SBrad.Beckmann@amd.com m_wCCInitialRequestToForwardRequestHistogram.add(forwardRequestTime - 6467565SBrad.Beckmann@amd.com initialRequestTime); 6477565SBrad.Beckmann@amd.com 6487565SBrad.Beckmann@amd.com m_wCCForwardRequestToFirstResponseHistogram.add(firstResponseTime - 6497565SBrad.Beckmann@amd.com forwardRequestTime); 6507565SBrad.Beckmann@amd.com 6517565SBrad.Beckmann@amd.com m_wCCFirstResponseToCompleteHistogram.add(completionTime - 6527565SBrad.Beckmann@amd.com firstResponseTime); 6537565SBrad.Beckmann@amd.com } else { 6547565SBrad.Beckmann@amd.com m_wCCIncompleteTimes++; 6557565SBrad.Beckmann@amd.com } 6567565SBrad.Beckmann@amd.com} 6577565SBrad.Beckmann@amd.com 6587565SBrad.Beckmann@amd.comvoid 6597565SBrad.Beckmann@amd.comProfiler::missLatencyDir(Time issuedTime, 6607565SBrad.Beckmann@amd.com Time initialRequestTime, 6617565SBrad.Beckmann@amd.com Time forwardRequestTime, 6627565SBrad.Beckmann@amd.com Time firstResponseTime, 6637565SBrad.Beckmann@amd.com Time completionTime) 6647565SBrad.Beckmann@amd.com{ 6657565SBrad.Beckmann@amd.com if ((issuedTime <= initialRequestTime) && 6667565SBrad.Beckmann@amd.com (initialRequestTime <= forwardRequestTime) && 6677565SBrad.Beckmann@amd.com (forwardRequestTime <= firstResponseTime) && 6687565SBrad.Beckmann@amd.com (firstResponseTime <= completionTime)) { 6697565SBrad.Beckmann@amd.com m_dirIssueToInitialRequestHistogram.add(initialRequestTime - issuedTime); 6707565SBrad.Beckmann@amd.com 6717565SBrad.Beckmann@amd.com m_dirInitialRequestToForwardRequestHistogram.add(forwardRequestTime - 6727565SBrad.Beckmann@amd.com initialRequestTime); 6737565SBrad.Beckmann@amd.com 6747565SBrad.Beckmann@amd.com m_dirForwardRequestToFirstResponseHistogram.add(firstResponseTime - 6757565SBrad.Beckmann@amd.com forwardRequestTime); 6767565SBrad.Beckmann@amd.com 6777565SBrad.Beckmann@amd.com m_dirFirstResponseToCompleteHistogram.add(completionTime - 6787565SBrad.Beckmann@amd.com firstResponseTime); 6797565SBrad.Beckmann@amd.com } else { 6807565SBrad.Beckmann@amd.com m_dirIncompleteTimes++; 6817565SBrad.Beckmann@amd.com } 6826145Snate@binkert.org} 6836145Snate@binkert.org 6846145Snate@binkert.org// non-zero cycle prefetch request 6857048Snate@binkert.orgvoid 6867546SBrad.Beckmann@amd.comProfiler::swPrefetchLatency(Time cycles, 6878165Snilay@cs.wisc.edu RubyRequestType type, 6887546SBrad.Beckmann@amd.com const GenericMachineType respondingMach) 6896145Snate@binkert.org{ 6907546SBrad.Beckmann@amd.com m_allSWPrefetchLatencyHistogram.add(cycles); 6917546SBrad.Beckmann@amd.com m_SWPrefetchLatencyHistograms[type].add(cycles); 6927546SBrad.Beckmann@amd.com m_SWPrefetchMachLatencyHistograms[respondingMach].add(cycles); 6937048Snate@binkert.org if (respondingMach == GenericMachineType_Directory || 6947048Snate@binkert.org respondingMach == GenericMachineType_NUM) { 6957546SBrad.Beckmann@amd.com m_SWPrefetchL2MissLatencyHistogram.add(cycles); 6967048Snate@binkert.org } 6976145Snate@binkert.org} 6986145Snate@binkert.org 6996145Snate@binkert.org// Helper function 7007048Snate@binkert.orgstatic double 7017048Snate@binkert.orgprocess_memory_total() 7026145Snate@binkert.org{ 7037048Snate@binkert.org // 4kB page size, 1024*1024 bytes per MB, 7047054Snate@binkert.org const double MULTIPLIER = 4096.0 / (1024.0 * 1024.0); 7057048Snate@binkert.org ifstream proc_file; 7067048Snate@binkert.org proc_file.open("/proc/self/statm"); 7077048Snate@binkert.org int total_size_in_pages = 0; 7087048Snate@binkert.org int res_size_in_pages = 0; 7097048Snate@binkert.org proc_file >> total_size_in_pages; 7107048Snate@binkert.org proc_file >> res_size_in_pages; 7117048Snate@binkert.org return double(total_size_in_pages) * MULTIPLIER; // size in megabytes 7126145Snate@binkert.org} 7136145Snate@binkert.org 7147048Snate@binkert.orgstatic double 7157048Snate@binkert.orgprocess_memory_resident() 7166145Snate@binkert.org{ 7177048Snate@binkert.org // 4kB page size, 1024*1024 bytes per MB, 7187048Snate@binkert.org const double MULTIPLIER = 4096.0 / (1024.0 * 1024.0); 7197048Snate@binkert.org ifstream proc_file; 7207048Snate@binkert.org proc_file.open("/proc/self/statm"); 7217048Snate@binkert.org int total_size_in_pages = 0; 7227048Snate@binkert.org int res_size_in_pages = 0; 7237048Snate@binkert.org proc_file >> total_size_in_pages; 7247048Snate@binkert.org proc_file >> res_size_in_pages; 7257048Snate@binkert.org return double(res_size_in_pages) * MULTIPLIER; // size in megabytes 7266145Snate@binkert.org} 7276145Snate@binkert.org 7287048Snate@binkert.orgvoid 7297048Snate@binkert.orgProfiler::rubyWatch(int id) 7307048Snate@binkert.org{ 7317010SBrad.Beckmann@amd.com uint64 tr = 0; 7326285Snate@binkert.org Address watch_address = Address(tr); 7336285Snate@binkert.org 7347832Snate@binkert.org DPRINTFN("%7s %3s RUBY WATCH %d\n", g_eventQueue_ptr->getTime(), id, 7357832Snate@binkert.org watch_address); 7367048Snate@binkert.org 7377455Snate@binkert.org // don't care about success or failure 7387455Snate@binkert.org m_watch_address_set.insert(watch_address); 7396285Snate@binkert.org} 7406285Snate@binkert.org 7417048Snate@binkert.orgbool 7427048Snate@binkert.orgProfiler::watchAddress(Address addr) 7437048Snate@binkert.org{ 7447455Snate@binkert.org return m_watch_address_set.count(addr) > 0; 7456285Snate@binkert.org} 7466285Snate@binkert.org 7476876Ssteve.reinhardt@amd.comProfiler * 7486876Ssteve.reinhardt@amd.comRubyProfilerParams::create() 7496876Ssteve.reinhardt@amd.com{ 7506876Ssteve.reinhardt@amd.com return new Profiler(this); 7516876Ssteve.reinhardt@amd.com} 752