Profiler.cc revision 9497
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>
488946Sandreas.hansson@arm.com#include <sys/types.h>
498946Sandreas.hansson@arm.com#include <unistd.h>
507002Snate@binkert.org
517454Snate@binkert.org#include <algorithm>
527832Snate@binkert.org#include <fstream>
537454Snate@binkert.org
547454Snate@binkert.org#include "base/stl_helpers.hh"
557056Snate@binkert.org#include "base/str.hh"
567048Snate@binkert.org#include "mem/protocol/MachineType.hh"
578229Snate@binkert.org#include "mem/protocol/RubyRequest.hh"
587048Snate@binkert.org#include "mem/ruby/network/Network.hh"
597048Snate@binkert.org#include "mem/ruby/profiler/AddressProfiler.hh"
606154Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh"
616154Snate@binkert.org#include "mem/ruby/system/System.hh"
626876Ssteve.reinhardt@amd.com
637055Snate@binkert.orgusing namespace std;
647454Snate@binkert.orgusing m5::stl_helpers::operator<<;
657055Snate@binkert.org
666145Snate@binkert.orgstatic double process_memory_total();
676145Snate@binkert.orgstatic double process_memory_resident();
686145Snate@binkert.org
696876Ssteve.reinhardt@amd.comProfiler::Profiler(const Params *p)
709171Snilay@cs.wisc.edu    : SimObject(p), m_event(this)
716145Snate@binkert.org{
727048Snate@binkert.org    m_inst_profiler_ptr = NULL;
737048Snate@binkert.org    m_address_profiler_ptr = NULL;
746285Snate@binkert.org
757048Snate@binkert.org    m_real_time_start_time = time(NULL); // Not reset in clearStats()
767048Snate@binkert.org    m_stats_period = 1000000; // Default
777048Snate@binkert.org    m_periodic_output_file_ptr = &cerr;
786145Snate@binkert.org
797048Snate@binkert.org    m_hot_lines = p->hot_lines;
807048Snate@binkert.org    m_all_instructions = p->all_instructions;
816876Ssteve.reinhardt@amd.com
827048Snate@binkert.org    m_num_of_sequencers = p->num_of_sequencers;
836896SBrad.Beckmann@amd.com
847048Snate@binkert.org    m_hot_lines = false;
857048Snate@binkert.org    m_all_instructions = false;
866285Snate@binkert.org
877048Snate@binkert.org    m_address_profiler_ptr = new AddressProfiler(m_num_of_sequencers);
887048Snate@binkert.org    m_address_profiler_ptr->setHotLines(m_hot_lines);
897048Snate@binkert.org    m_address_profiler_ptr->setAllInstructions(m_all_instructions);
906285Snate@binkert.org
917048Snate@binkert.org    if (m_all_instructions) {
927048Snate@binkert.org        m_inst_profiler_ptr = new AddressProfiler(m_num_of_sequencers);
937048Snate@binkert.org        m_inst_profiler_ptr->setHotLines(m_hot_lines);
947048Snate@binkert.org        m_inst_profiler_ptr->setAllInstructions(m_all_instructions);
957048Snate@binkert.org    }
968436SBrad.Beckmann@amd.com
978436SBrad.Beckmann@amd.com    p->ruby_system->registerProfiler(this);
986285Snate@binkert.org}
996285Snate@binkert.org
1006889SBrad.Beckmann@amd.comProfiler::~Profiler()
1016889SBrad.Beckmann@amd.com{
1027048Snate@binkert.org    if (m_periodic_output_file_ptr != &cerr) {
1037048Snate@binkert.org        delete m_periodic_output_file_ptr;
1047048Snate@binkert.org    }
1056889SBrad.Beckmann@amd.com}
1066889SBrad.Beckmann@amd.com
1077048Snate@binkert.orgvoid
1087048Snate@binkert.orgProfiler::wakeup()
1096145Snate@binkert.org{
1107048Snate@binkert.org    // FIXME - avoid the repeated code
1116145Snate@binkert.org
1129231Snilay@cs.wisc.edu    vector<int64_t> perProcCycleCount(m_num_of_sequencers);
1136145Snate@binkert.org
1147048Snate@binkert.org    for (int i = 0; i < m_num_of_sequencers; i++) {
1157048Snate@binkert.org        perProcCycleCount[i] =
1169171Snilay@cs.wisc.edu            g_system_ptr->getTime() - m_cycles_executed_at_start[i] + 1;
1177048Snate@binkert.org        // The +1 allows us to avoid division by zero
1187048Snate@binkert.org    }
1196145Snate@binkert.org
1207048Snate@binkert.org    ostream &out = *m_periodic_output_file_ptr;
1216889SBrad.Beckmann@amd.com
1229171Snilay@cs.wisc.edu    out << "ruby_cycles: " << g_system_ptr->getTime()-m_ruby_start << endl
1237048Snate@binkert.org        << "mbytes_resident: " << process_memory_resident() << endl
1247048Snate@binkert.org        << "mbytes_total: " << process_memory_total() << endl;
1256889SBrad.Beckmann@amd.com
1267048Snate@binkert.org    if (process_memory_total() > 0) {
1277054Snate@binkert.org        out << "resident_ratio: "
1287048Snate@binkert.org            << process_memory_resident() / process_memory_total() << endl;
1297048Snate@binkert.org    }
1306889SBrad.Beckmann@amd.com
1316145Snate@binkert.org    out << "miss_latency: " << m_allMissLatencyHistogram << endl;
1326145Snate@binkert.org
1336145Snate@binkert.org    out << endl;
1346145Snate@binkert.org
1357048Snate@binkert.org    if (m_all_instructions) {
1367048Snate@binkert.org        m_inst_profiler_ptr->printStats(out);
1376145Snate@binkert.org    }
1386145Snate@binkert.org
1397048Snate@binkert.org    //g_system_ptr->getNetwork()->printStats(out);
1409465Snilay@cs.wisc.edu    schedule(m_event, g_system_ptr->clockEdge(Cycles(m_stats_period)));
1417048Snate@binkert.org}
1427048Snate@binkert.org
1437048Snate@binkert.orgvoid
1447048Snate@binkert.orgProfiler::setPeriodicStatsFile(const string& filename)
1457048Snate@binkert.org{
1467048Snate@binkert.org    cout << "Recording periodic statistics to file '" << filename << "' every "
1477048Snate@binkert.org         << m_stats_period << " Ruby cycles" << endl;
1487048Snate@binkert.org
1497048Snate@binkert.org    if (m_periodic_output_file_ptr != &cerr) {
1507048Snate@binkert.org        delete m_periodic_output_file_ptr;
1516145Snate@binkert.org    }
1526145Snate@binkert.org
1537048Snate@binkert.org    m_periodic_output_file_ptr = new ofstream(filename.c_str());
1549206Snilay@cs.wisc.edu    schedule(m_event, g_system_ptr->clockEdge(Cycles(1)));
1557048Snate@binkert.org}
1567048Snate@binkert.org
1577048Snate@binkert.orgvoid
1589231Snilay@cs.wisc.eduProfiler::setPeriodicStatsInterval(int64_t period)
1597048Snate@binkert.org{
1607054Snate@binkert.org    cout << "Recording periodic statistics every " << m_stats_period
1617048Snate@binkert.org         << " Ruby cycles" << endl;
1627048Snate@binkert.org
1637048Snate@binkert.org    m_stats_period = period;
1649206Snilay@cs.wisc.edu    schedule(m_event, g_system_ptr->clockEdge(Cycles(1)));
1657048Snate@binkert.org}
1667048Snate@binkert.org
1677048Snate@binkert.orgvoid
1687048Snate@binkert.orgProfiler::print(ostream& out) const
1697048Snate@binkert.org{
1707048Snate@binkert.org    out << "[Profiler]";
1717048Snate@binkert.org}
1727048Snate@binkert.org
1737048Snate@binkert.orgvoid
1749496Snilay@cs.wisc.eduProfiler::printRequestProfile(ostream &out)
1759496Snilay@cs.wisc.edu{
1769496Snilay@cs.wisc.edu    out << "Request vs. RubySystem State Profile" << endl;
1779496Snilay@cs.wisc.edu    out << "--------------------------------" << endl;
1789496Snilay@cs.wisc.edu    out << endl;
1799496Snilay@cs.wisc.edu
1809496Snilay@cs.wisc.edu    map<string, uint64_t> m_requestProfileMap;
1819496Snilay@cs.wisc.edu    uint64_t m_requests = 0;
1829496Snilay@cs.wisc.edu
1839496Snilay@cs.wisc.edu    for (uint32_t i = 0; i < MachineType_NUM; i++) {
1849496Snilay@cs.wisc.edu        for (map<uint32_t, AbstractController*>::iterator it =
1859496Snilay@cs.wisc.edu                  g_abs_controls[i].begin();
1869496Snilay@cs.wisc.edu             it != g_abs_controls[i].end(); ++it) {
1879496Snilay@cs.wisc.edu
1889496Snilay@cs.wisc.edu            AbstractController *ctr = (*it).second;
1899496Snilay@cs.wisc.edu            map<string, uint64_t> mp = ctr->getRequestProfileMap();
1909496Snilay@cs.wisc.edu
1919496Snilay@cs.wisc.edu            for (map<string, uint64_t>::iterator jt = mp.begin();
1929496Snilay@cs.wisc.edu                 jt != mp.end(); ++jt) {
1939496Snilay@cs.wisc.edu
1949496Snilay@cs.wisc.edu                map<string, uint64_t>::iterator kt =
1959496Snilay@cs.wisc.edu                    m_requestProfileMap.find((*jt).first);
1969496Snilay@cs.wisc.edu                if (kt != m_requestProfileMap.end()) {
1979496Snilay@cs.wisc.edu                    (*kt).second += (*jt).second;
1989496Snilay@cs.wisc.edu                } else {
1999496Snilay@cs.wisc.edu                    m_requestProfileMap[(*jt).first] = (*jt).second;
2009496Snilay@cs.wisc.edu                }
2019496Snilay@cs.wisc.edu            }
2029496Snilay@cs.wisc.edu
2039496Snilay@cs.wisc.edu            m_requests += ctr->getRequestCount();
2049496Snilay@cs.wisc.edu        }
2059496Snilay@cs.wisc.edu    }
2069496Snilay@cs.wisc.edu
2079496Snilay@cs.wisc.edu    map<string, uint64_t>::const_iterator i = m_requestProfileMap.begin();
2089496Snilay@cs.wisc.edu    map<string, uint64_t>::const_iterator end = m_requestProfileMap.end();
2099496Snilay@cs.wisc.edu    for (; i != end; ++i) {
2109496Snilay@cs.wisc.edu        const string &key = i->first;
2119496Snilay@cs.wisc.edu        uint64_t count = i->second;
2129496Snilay@cs.wisc.edu
2139496Snilay@cs.wisc.edu        double percent = (100.0 * double(count)) / double(m_requests);
2149496Snilay@cs.wisc.edu        vector<string> items;
2159496Snilay@cs.wisc.edu        tokenize(items, key, ':');
2169496Snilay@cs.wisc.edu        vector<string>::iterator j = items.begin();
2179496Snilay@cs.wisc.edu        vector<string>::iterator end = items.end();
2189496Snilay@cs.wisc.edu        for (; j != end; ++i)
2199496Snilay@cs.wisc.edu            out << setw(10) << *j;
2209496Snilay@cs.wisc.edu        out << setw(11) << count;
2219496Snilay@cs.wisc.edu        out << setw(14) << percent << endl;
2229496Snilay@cs.wisc.edu    }
2239496Snilay@cs.wisc.edu    out << endl;
2249496Snilay@cs.wisc.edu}
2259496Snilay@cs.wisc.edu
2269496Snilay@cs.wisc.eduvoid
2279497Snilay@cs.wisc.eduProfiler::printDelayProfile(ostream &out)
2289497Snilay@cs.wisc.edu{
2299497Snilay@cs.wisc.edu    out << "Message Delayed Cycles" << endl;
2309497Snilay@cs.wisc.edu    out << "----------------------" << endl;
2319497Snilay@cs.wisc.edu
2329497Snilay@cs.wisc.edu    uint32_t numVNets = Network::getNumberOfVirtualNetworks();
2339497Snilay@cs.wisc.edu    Histogram delayHistogram;
2349497Snilay@cs.wisc.edu    std::vector<Histogram> delayVCHistogram(numVNets);
2359497Snilay@cs.wisc.edu
2369497Snilay@cs.wisc.edu    for (uint32_t i = 0; i < MachineType_NUM; i++) {
2379497Snilay@cs.wisc.edu        for (map<uint32_t, AbstractController*>::iterator it =
2389497Snilay@cs.wisc.edu                  g_abs_controls[i].begin();
2399497Snilay@cs.wisc.edu             it != g_abs_controls[i].end(); ++it) {
2409497Snilay@cs.wisc.edu
2419497Snilay@cs.wisc.edu            AbstractController *ctr = (*it).second;
2429497Snilay@cs.wisc.edu            delayHistogram.add(ctr->getDelayHist());
2439497Snilay@cs.wisc.edu
2449497Snilay@cs.wisc.edu            for (uint32_t i = 0; i < numVNets; i++) {
2459497Snilay@cs.wisc.edu                delayVCHistogram[i].add(ctr->getDelayVCHist(i));
2469497Snilay@cs.wisc.edu            }
2479497Snilay@cs.wisc.edu        }
2489497Snilay@cs.wisc.edu    }
2499497Snilay@cs.wisc.edu
2509497Snilay@cs.wisc.edu    out << "Total_delay_cycles: " <<   delayHistogram << endl;
2519497Snilay@cs.wisc.edu
2529497Snilay@cs.wisc.edu    for (int i = 0; i < numVNets; i++) {
2539497Snilay@cs.wisc.edu        out << "  virtual_network_" << i << "_delay_cycles: "
2549497Snilay@cs.wisc.edu            << delayVCHistogram[i] << endl;
2559497Snilay@cs.wisc.edu    }
2569497Snilay@cs.wisc.edu}
2579497Snilay@cs.wisc.edu
2589497Snilay@cs.wisc.eduvoid
2597048Snate@binkert.orgProfiler::printStats(ostream& out, bool short_stats)
2607048Snate@binkert.org{
2617048Snate@binkert.org    out << endl;
2627048Snate@binkert.org    if (short_stats) {
2637048Snate@binkert.org        out << "SHORT ";
2647048Snate@binkert.org    }
2657048Snate@binkert.org    out << "Profiler Stats" << endl;
2667048Snate@binkert.org    out << "--------------" << endl;
2677048Snate@binkert.org
2687048Snate@binkert.org    time_t real_time_current = time(NULL);
2697048Snate@binkert.org    double seconds = difftime(real_time_current, m_real_time_start_time);
2707048Snate@binkert.org    double minutes = seconds / 60.0;
2717048Snate@binkert.org    double hours = minutes / 60.0;
2727048Snate@binkert.org    double days = hours / 24.0;
2739171Snilay@cs.wisc.edu    Time ruby_cycles = g_system_ptr->getTime()-m_ruby_start;
2747048Snate@binkert.org
2757048Snate@binkert.org    if (!short_stats) {
2767048Snate@binkert.org        out << "Elapsed_time_in_seconds: " << seconds << endl;
2777048Snate@binkert.org        out << "Elapsed_time_in_minutes: " << minutes << endl;
2787048Snate@binkert.org        out << "Elapsed_time_in_hours: " << hours << endl;
2797048Snate@binkert.org        out << "Elapsed_time_in_days: " << days << endl;
2807048Snate@binkert.org        out << endl;
2817048Snate@binkert.org    }
2827048Snate@binkert.org
2837048Snate@binkert.org    // print the virtual runtimes as well
2847048Snate@binkert.org    struct tms vtime;
2857048Snate@binkert.org    times(&vtime);
2867048Snate@binkert.org    seconds = (vtime.tms_utime + vtime.tms_stime) / 100.0;
2877048Snate@binkert.org    minutes = seconds / 60.0;
2887048Snate@binkert.org    hours = minutes / 60.0;
2897048Snate@binkert.org    days = hours / 24.0;
2907048Snate@binkert.org    out << "Virtual_time_in_seconds: " << seconds << endl;
2917048Snate@binkert.org    out << "Virtual_time_in_minutes: " << minutes << endl;
2927048Snate@binkert.org    out << "Virtual_time_in_hours:   " << hours << endl;
2937048Snate@binkert.org    out << "Virtual_time_in_days:    " << days << endl;
2946145Snate@binkert.org    out << endl;
2956145Snate@binkert.org
2969171Snilay@cs.wisc.edu    out << "Ruby_current_time: " << g_system_ptr->getTime() << endl;
2977048Snate@binkert.org    out << "Ruby_start_time: " << m_ruby_start << endl;
2987048Snate@binkert.org    out << "Ruby_cycles: " << ruby_cycles << endl;
2996145Snate@binkert.org    out << endl;
3006145Snate@binkert.org
3017048Snate@binkert.org    if (!short_stats) {
3027048Snate@binkert.org        out << "mbytes_resident: " << process_memory_resident() << endl;
3037048Snate@binkert.org        out << "mbytes_total: " << process_memory_total() << endl;
3047048Snate@binkert.org        if (process_memory_total() > 0) {
3057054Snate@binkert.org            out << "resident_ratio: "
3067048Snate@binkert.org                << process_memory_resident()/process_memory_total() << endl;
3077048Snate@binkert.org        }
3087048Snate@binkert.org        out << endl;
3096145Snate@binkert.org    }
3106145Snate@binkert.org
3119231Snilay@cs.wisc.edu    vector<int64_t> perProcCycleCount(m_num_of_sequencers);
3127048Snate@binkert.org
3137048Snate@binkert.org    for (int i = 0; i < m_num_of_sequencers; i++) {
3147048Snate@binkert.org        perProcCycleCount[i] =
3159171Snilay@cs.wisc.edu            g_system_ptr->getTime() - m_cycles_executed_at_start[i] + 1;
3167048Snate@binkert.org        // The +1 allows us to avoid division by zero
3176145Snate@binkert.org    }
3186145Snate@binkert.org
3197048Snate@binkert.org    out << "ruby_cycles_executed: " << perProcCycleCount << endl;
3207048Snate@binkert.org
3216145Snate@binkert.org    out << endl;
3227048Snate@binkert.org
3237048Snate@binkert.org    if (!short_stats) {
3247048Snate@binkert.org        out << "Busy Controller Counts:" << endl;
3259496Snilay@cs.wisc.edu        for (uint32_t i = 0; i < MachineType_NUM; i++) {
3269496Snilay@cs.wisc.edu            uint32_t size = MachineType_base_count((MachineType)i);
3279496Snilay@cs.wisc.edu
3289496Snilay@cs.wisc.edu            for (uint32_t j = 0; j < size; j++) {
3297048Snate@binkert.org                MachineID machID;
3307048Snate@binkert.org                machID.type = (MachineType)i;
3317048Snate@binkert.org                machID.num = j;
3329496Snilay@cs.wisc.edu
3339496Snilay@cs.wisc.edu                AbstractController *ctr =
3349496Snilay@cs.wisc.edu                    (*(g_abs_controls[i].find(j))).second;
3359496Snilay@cs.wisc.edu                out << machID << ":" << ctr->getFullyBusyCycles() << "  ";
3367048Snate@binkert.org                if ((j + 1) % 8 == 0) {
3377048Snate@binkert.org                    out << endl;
3387048Snate@binkert.org                }
3397048Snate@binkert.org            }
3407048Snate@binkert.org            out << endl;
3417048Snate@binkert.org        }
3427048Snate@binkert.org        out << endl;
3437048Snate@binkert.org
3447048Snate@binkert.org        out << "Busy Bank Count:" << m_busyBankCount << endl;
3457048Snate@binkert.org        out << endl;
3467048Snate@binkert.org
3477048Snate@binkert.org        out << "sequencer_requests_outstanding: "
3487048Snate@binkert.org            << m_sequencer_requests << endl;
3497048Snate@binkert.org        out << endl;
3506145Snate@binkert.org    }
3516145Snate@binkert.org
3527048Snate@binkert.org    if (!short_stats) {
3537048Snate@binkert.org        out << "All Non-Zero Cycle Demand Cache Accesses" << endl;
3547048Snate@binkert.org        out << "----------------------------------------" << endl;
3557048Snate@binkert.org        out << "miss_latency: " << m_allMissLatencyHistogram << endl;
3567048Snate@binkert.org        for (int i = 0; i < m_missLatencyHistograms.size(); i++) {
3577048Snate@binkert.org            if (m_missLatencyHistograms[i].size() > 0) {
3587048Snate@binkert.org                out << "miss_latency_" << RubyRequestType(i) << ": "
3597048Snate@binkert.org                    << m_missLatencyHistograms[i] << endl;
3607048Snate@binkert.org            }
3617048Snate@binkert.org        }
3627048Snate@binkert.org        for (int i = 0; i < m_machLatencyHistograms.size(); i++) {
3637048Snate@binkert.org            if (m_machLatencyHistograms[i].size() > 0) {
3647048Snate@binkert.org                out << "miss_latency_" << GenericMachineType(i) << ": "
3657048Snate@binkert.org                    << m_machLatencyHistograms[i] << endl;
3667048Snate@binkert.org            }
3677048Snate@binkert.org        }
3686145Snate@binkert.org
3697565SBrad.Beckmann@amd.com        out << "miss_latency_wCC_issue_to_initial_request: "
3707565SBrad.Beckmann@amd.com            << m_wCCIssueToInitialRequestHistogram << endl;
3717565SBrad.Beckmann@amd.com        out << "miss_latency_wCC_initial_forward_request: "
3727565SBrad.Beckmann@amd.com            << m_wCCInitialRequestToForwardRequestHistogram << endl;
3737565SBrad.Beckmann@amd.com        out << "miss_latency_wCC_forward_to_first_response: "
3747565SBrad.Beckmann@amd.com            << m_wCCForwardRequestToFirstResponseHistogram << endl;
3757565SBrad.Beckmann@amd.com        out << "miss_latency_wCC_first_response_to_completion: "
3767565SBrad.Beckmann@amd.com            << m_wCCFirstResponseToCompleteHistogram << endl;
3777565SBrad.Beckmann@amd.com        out << "imcomplete_wCC_Times: " << m_wCCIncompleteTimes << endl;
3787565SBrad.Beckmann@amd.com        out << "miss_latency_dir_issue_to_initial_request: "
3797565SBrad.Beckmann@amd.com            << m_dirIssueToInitialRequestHistogram << endl;
3807565SBrad.Beckmann@amd.com        out << "miss_latency_dir_initial_forward_request: "
3817565SBrad.Beckmann@amd.com            << m_dirInitialRequestToForwardRequestHistogram << endl;
3827565SBrad.Beckmann@amd.com        out << "miss_latency_dir_forward_to_first_response: "
3837565SBrad.Beckmann@amd.com            << m_dirForwardRequestToFirstResponseHistogram << endl;
3847565SBrad.Beckmann@amd.com        out << "miss_latency_dir_first_response_to_completion: "
3857565SBrad.Beckmann@amd.com            << m_dirFirstResponseToCompleteHistogram << endl;
3867565SBrad.Beckmann@amd.com        out << "imcomplete_dir_Times: " << m_dirIncompleteTimes << endl;
3877565SBrad.Beckmann@amd.com
3887565SBrad.Beckmann@amd.com        for (int i = 0; i < m_missMachLatencyHistograms.size(); i++) {
3897565SBrad.Beckmann@amd.com            for (int j = 0; j < m_missMachLatencyHistograms[i].size(); j++) {
3907565SBrad.Beckmann@amd.com                if (m_missMachLatencyHistograms[i][j].size() > 0) {
3917565SBrad.Beckmann@amd.com                    out << "miss_latency_" << RubyRequestType(i)
3927565SBrad.Beckmann@amd.com                        << "_" << GenericMachineType(j) << ": "
3937565SBrad.Beckmann@amd.com                        << m_missMachLatencyHistograms[i][j] << endl;
3947565SBrad.Beckmann@amd.com                }
3957565SBrad.Beckmann@amd.com            }
3967565SBrad.Beckmann@amd.com        }
3977565SBrad.Beckmann@amd.com
3987048Snate@binkert.org        out << endl;
3997048Snate@binkert.org
4007048Snate@binkert.org        out << "All Non-Zero Cycle SW Prefetch Requests" << endl;
4017048Snate@binkert.org        out << "------------------------------------" << endl;
4027048Snate@binkert.org        out << "prefetch_latency: " << m_allSWPrefetchLatencyHistogram << endl;
4037048Snate@binkert.org        for (int i = 0; i < m_SWPrefetchLatencyHistograms.size(); i++) {
4047048Snate@binkert.org            if (m_SWPrefetchLatencyHistograms[i].size() > 0) {
4058165Snilay@cs.wisc.edu                out << "prefetch_latency_" << RubyRequestType(i) << ": "
4067048Snate@binkert.org                    << m_SWPrefetchLatencyHistograms[i] << endl;
4077048Snate@binkert.org            }
4087048Snate@binkert.org        }
4097048Snate@binkert.org        for (int i = 0; i < m_SWPrefetchMachLatencyHistograms.size(); i++) {
4107048Snate@binkert.org            if (m_SWPrefetchMachLatencyHistograms[i].size() > 0) {
4117048Snate@binkert.org                out << "prefetch_latency_" << GenericMachineType(i) << ": "
4127048Snate@binkert.org                    << m_SWPrefetchMachLatencyHistograms[i] << endl;
4137048Snate@binkert.org            }
4147048Snate@binkert.org        }
4157048Snate@binkert.org        out << "prefetch_latency_L2Miss:"
4167048Snate@binkert.org            << m_SWPrefetchL2MissLatencyHistogram << endl;
4177048Snate@binkert.org
4187048Snate@binkert.org        if (m_all_sharing_histogram.size() > 0) {
4197048Snate@binkert.org            out << "all_sharing: " << m_all_sharing_histogram << endl;
4207048Snate@binkert.org            out << "read_sharing: " << m_read_sharing_histogram << endl;
4217048Snate@binkert.org            out << "write_sharing: " << m_write_sharing_histogram << endl;
4227048Snate@binkert.org
4237048Snate@binkert.org            out << "all_sharing_percent: ";
4247048Snate@binkert.org            m_all_sharing_histogram.printPercent(out);
4257048Snate@binkert.org            out << endl;
4267048Snate@binkert.org
4277048Snate@binkert.org            out << "read_sharing_percent: ";
4287048Snate@binkert.org            m_read_sharing_histogram.printPercent(out);
4297048Snate@binkert.org            out << endl;
4307048Snate@binkert.org
4317048Snate@binkert.org            out << "write_sharing_percent: ";
4327048Snate@binkert.org            m_write_sharing_histogram.printPercent(out);
4337048Snate@binkert.org            out << endl;
4347048Snate@binkert.org
4357048Snate@binkert.org            int64 total_miss = m_cache_to_cache +  m_memory_to_cache;
4367048Snate@binkert.org            out << "all_misses: " << total_miss << endl;
4377048Snate@binkert.org            out << "cache_to_cache_misses: " << m_cache_to_cache << endl;
4387048Snate@binkert.org            out << "memory_to_cache_misses: " << m_memory_to_cache << endl;
4397048Snate@binkert.org            out << "cache_to_cache_percent: "
4407048Snate@binkert.org                << 100.0 * (double(m_cache_to_cache) / double(total_miss))
4417048Snate@binkert.org                << endl;
4427048Snate@binkert.org            out << "memory_to_cache_percent: "
4437048Snate@binkert.org                << 100.0 * (double(m_memory_to_cache) / double(total_miss))
4447048Snate@binkert.org                << endl;
4457048Snate@binkert.org            out << endl;
4467048Snate@binkert.org        }
4477048Snate@binkert.org
4487048Snate@binkert.org        if (m_outstanding_requests.size() > 0) {
4497048Snate@binkert.org            out << "outstanding_requests: ";
4507048Snate@binkert.org            m_outstanding_requests.printPercent(out);
4517048Snate@binkert.org            out << endl;
4527048Snate@binkert.org            out << endl;
4537048Snate@binkert.org        }
4547048Snate@binkert.org    }
4557048Snate@binkert.org
4567048Snate@binkert.org    if (!short_stats) {
4579496Snilay@cs.wisc.edu        printRequestProfile(out);
4587048Snate@binkert.org
4597048Snate@binkert.org        out << "filter_action: " << m_filter_action_histogram << endl;
4607048Snate@binkert.org
4617048Snate@binkert.org        if (!m_all_instructions) {
4627048Snate@binkert.org            m_address_profiler_ptr->printStats(out);
4637048Snate@binkert.org        }
4647048Snate@binkert.org
4657048Snate@binkert.org        if (m_all_instructions) {
4667048Snate@binkert.org            m_inst_profiler_ptr->printStats(out);
4677048Snate@binkert.org        }
4687048Snate@binkert.org
4697048Snate@binkert.org        out << endl;
4709497Snilay@cs.wisc.edu        printDelayProfile(out);
4717048Snate@binkert.org        printResourceUsage(out);
4727048Snate@binkert.org    }
4736145Snate@binkert.org}
4746145Snate@binkert.org
4757048Snate@binkert.orgvoid
4767048Snate@binkert.orgProfiler::printResourceUsage(ostream& out) const
4776145Snate@binkert.org{
4787048Snate@binkert.org    out << endl;
4797048Snate@binkert.org    out << "Resource Usage" << endl;
4807048Snate@binkert.org    out << "--------------" << endl;
4816145Snate@binkert.org
4829231Snilay@cs.wisc.edu    int64_t pagesize = getpagesize(); // page size in bytes
4837048Snate@binkert.org    out << "page_size: " << pagesize << endl;
4846145Snate@binkert.org
4857048Snate@binkert.org    rusage usage;
4867048Snate@binkert.org    getrusage (RUSAGE_SELF, &usage);
4876145Snate@binkert.org
4887048Snate@binkert.org    out << "user_time: " << usage.ru_utime.tv_sec << endl;
4897048Snate@binkert.org    out << "system_time: " << usage.ru_stime.tv_sec << endl;
4907048Snate@binkert.org    out << "page_reclaims: " << usage.ru_minflt << endl;
4917048Snate@binkert.org    out << "page_faults: " << usage.ru_majflt << endl;
4927048Snate@binkert.org    out << "swaps: " << usage.ru_nswap << endl;
4937048Snate@binkert.org    out << "block_inputs: " << usage.ru_inblock << endl;
4947048Snate@binkert.org    out << "block_outputs: " << usage.ru_oublock << endl;
4956145Snate@binkert.org}
4966145Snate@binkert.org
4977048Snate@binkert.orgvoid
4987048Snate@binkert.orgProfiler::clearStats()
4996145Snate@binkert.org{
5009171Snilay@cs.wisc.edu    m_ruby_start = g_system_ptr->getTime();
5019350Skhaleghzadeh@gmail.com    m_real_time_start_time = time(NULL);
5026145Snate@binkert.org
5037454Snate@binkert.org    m_cycles_executed_at_start.resize(m_num_of_sequencers);
5047048Snate@binkert.org    for (int i = 0; i < m_num_of_sequencers; i++) {
5057048Snate@binkert.org        if (g_system_ptr == NULL) {
5067048Snate@binkert.org            m_cycles_executed_at_start[i] = 0;
5077048Snate@binkert.org        } else {
5089171Snilay@cs.wisc.edu            m_cycles_executed_at_start[i] = g_system_ptr->getTime();
5097048Snate@binkert.org        }
5106145Snate@binkert.org    }
5116145Snate@binkert.org
5127048Snate@binkert.org    m_busyBankCount = 0;
5136145Snate@binkert.org
5147454Snate@binkert.org    m_missLatencyHistograms.resize(RubyRequestType_NUM);
5157048Snate@binkert.org    for (int i = 0; i < m_missLatencyHistograms.size(); i++) {
5167048Snate@binkert.org        m_missLatencyHistograms[i].clear(200);
5177048Snate@binkert.org    }
5187454Snate@binkert.org    m_machLatencyHistograms.resize(GenericMachineType_NUM+1);
5197048Snate@binkert.org    for (int i = 0; i < m_machLatencyHistograms.size(); i++) {
5207048Snate@binkert.org        m_machLatencyHistograms[i].clear(200);
5217048Snate@binkert.org    }
5227565SBrad.Beckmann@amd.com    m_missMachLatencyHistograms.resize(RubyRequestType_NUM);
5237565SBrad.Beckmann@amd.com    for (int i = 0; i < m_missLatencyHistograms.size(); i++) {
5247565SBrad.Beckmann@amd.com        m_missMachLatencyHistograms[i].resize(GenericMachineType_NUM+1);
5257565SBrad.Beckmann@amd.com        for (int j = 0; j < m_missMachLatencyHistograms[i].size(); j++) {
5267565SBrad.Beckmann@amd.com            m_missMachLatencyHistograms[i][j].clear(200);
5277565SBrad.Beckmann@amd.com        }
5287565SBrad.Beckmann@amd.com    }
5297048Snate@binkert.org    m_allMissLatencyHistogram.clear(200);
5307565SBrad.Beckmann@amd.com    m_wCCIssueToInitialRequestHistogram.clear(200);
5317565SBrad.Beckmann@amd.com    m_wCCInitialRequestToForwardRequestHistogram.clear(200);
5327565SBrad.Beckmann@amd.com    m_wCCForwardRequestToFirstResponseHistogram.clear(200);
5337565SBrad.Beckmann@amd.com    m_wCCFirstResponseToCompleteHistogram.clear(200);
5347565SBrad.Beckmann@amd.com    m_wCCIncompleteTimes = 0;
5357565SBrad.Beckmann@amd.com    m_dirIssueToInitialRequestHistogram.clear(200);
5367565SBrad.Beckmann@amd.com    m_dirInitialRequestToForwardRequestHistogram.clear(200);
5377565SBrad.Beckmann@amd.com    m_dirForwardRequestToFirstResponseHistogram.clear(200);
5387565SBrad.Beckmann@amd.com    m_dirFirstResponseToCompleteHistogram.clear(200);
5397565SBrad.Beckmann@amd.com    m_dirIncompleteTimes = 0;
5406145Snate@binkert.org
5418165Snilay@cs.wisc.edu    m_SWPrefetchLatencyHistograms.resize(RubyRequestType_NUM);
5427048Snate@binkert.org    for (int i = 0; i < m_SWPrefetchLatencyHistograms.size(); i++) {
5437048Snate@binkert.org        m_SWPrefetchLatencyHistograms[i].clear(200);
5447048Snate@binkert.org    }
5457454Snate@binkert.org    m_SWPrefetchMachLatencyHistograms.resize(GenericMachineType_NUM+1);
5467048Snate@binkert.org    for (int i = 0; i < m_SWPrefetchMachLatencyHistograms.size(); i++) {
5477048Snate@binkert.org        m_SWPrefetchMachLatencyHistograms[i].clear(200);
5487048Snate@binkert.org    }
5497048Snate@binkert.org    m_allSWPrefetchLatencyHistogram.clear(200);
5506145Snate@binkert.org
5517048Snate@binkert.org    m_sequencer_requests.clear();
5527048Snate@binkert.org    m_read_sharing_histogram.clear();
5537048Snate@binkert.org    m_write_sharing_histogram.clear();
5547048Snate@binkert.org    m_all_sharing_histogram.clear();
5557048Snate@binkert.org    m_cache_to_cache = 0;
5567048Snate@binkert.org    m_memory_to_cache = 0;
5576145Snate@binkert.org
5587048Snate@binkert.org    m_outstanding_requests.clear();
5597048Snate@binkert.org    m_outstanding_persistent_requests.clear();
5606145Snate@binkert.org
5617048Snate@binkert.org    // Flush the prefetches through the system - used so that there
5627048Snate@binkert.org    // are no outstanding requests after stats are cleared
5637048Snate@binkert.org    //g_eventQueue_ptr->triggerAllEvents();
5646145Snate@binkert.org
5657048Snate@binkert.org    // update the start time
5669171Snilay@cs.wisc.edu    m_ruby_start = g_system_ptr->getTime();
5676145Snate@binkert.org}
5686145Snate@binkert.org
5697048Snate@binkert.orgvoid
5708174Snilay@cs.wisc.eduProfiler::addAddressTraceSample(const RubyRequest& msg, NodeID id)
5716145Snate@binkert.org{
5728165Snilay@cs.wisc.edu    if (msg.getType() != RubyRequestType_IFETCH) {
5737048Snate@binkert.org        // Note: The following line should be commented out if you
5747048Snate@binkert.org        // want to use the special profiling that is part of the GS320
5757048Snate@binkert.org        // protocol
5766145Snate@binkert.org
5777048Snate@binkert.org        // NOTE: Unless PROFILE_HOT_LINES is enabled, nothing will be
5787048Snate@binkert.org        // profiled by the AddressProfiler
5797048Snate@binkert.org        m_address_profiler_ptr->
5807048Snate@binkert.org            addTraceSample(msg.getLineAddress(), msg.getProgramCounter(),
5817048Snate@binkert.org                           msg.getType(), msg.getAccessMode(), id, false);
5827048Snate@binkert.org    }
5836145Snate@binkert.org}
5846145Snate@binkert.org
5857048Snate@binkert.orgvoid
5867048Snate@binkert.orgProfiler::profileSharing(const Address& addr, AccessType type,
5877048Snate@binkert.org                         NodeID requestor, const Set& sharers,
5887048Snate@binkert.org                         const Set& owner)
5896145Snate@binkert.org{
5907048Snate@binkert.org    Set set_contacted(owner);
5917048Snate@binkert.org    if (type == AccessType_Write) {
5927048Snate@binkert.org        set_contacted.addSet(sharers);
5937048Snate@binkert.org    }
5947048Snate@binkert.org    set_contacted.remove(requestor);
5957048Snate@binkert.org    int number_contacted = set_contacted.count();
5966145Snate@binkert.org
5977048Snate@binkert.org    if (type == AccessType_Write) {
5987048Snate@binkert.org        m_write_sharing_histogram.add(number_contacted);
5997048Snate@binkert.org    } else {
6007048Snate@binkert.org        m_read_sharing_histogram.add(number_contacted);
6017048Snate@binkert.org    }
6027048Snate@binkert.org    m_all_sharing_histogram.add(number_contacted);
6036145Snate@binkert.org
6047048Snate@binkert.org    if (number_contacted == 0) {
6057048Snate@binkert.org        m_memory_to_cache++;
6067048Snate@binkert.org    } else {
6077048Snate@binkert.org        m_cache_to_cache++;
6087048Snate@binkert.org    }
6096145Snate@binkert.org}
6106145Snate@binkert.org
6117048Snate@binkert.orgvoid
6127048Snate@binkert.orgProfiler::profilePFWait(Time waitTime)
6136145Snate@binkert.org{
6147048Snate@binkert.org    m_prefetchWaitHistogram.add(waitTime);
6156145Snate@binkert.org}
6166145Snate@binkert.org
6177048Snate@binkert.orgvoid
6187048Snate@binkert.orgProfiler::bankBusy()
6196145Snate@binkert.org{
6207048Snate@binkert.org    m_busyBankCount++;
6216145Snate@binkert.org}
6226145Snate@binkert.org
6236145Snate@binkert.org// non-zero cycle demand request
6247048Snate@binkert.orgvoid
6257546SBrad.Beckmann@amd.comProfiler::missLatency(Time cycles,
6267546SBrad.Beckmann@amd.com                      RubyRequestType type,
6277546SBrad.Beckmann@amd.com                      const GenericMachineType respondingMach)
6286145Snate@binkert.org{
6297546SBrad.Beckmann@amd.com    m_allMissLatencyHistogram.add(cycles);
6307546SBrad.Beckmann@amd.com    m_missLatencyHistograms[type].add(cycles);
6317546SBrad.Beckmann@amd.com    m_machLatencyHistograms[respondingMach].add(cycles);
6327565SBrad.Beckmann@amd.com    m_missMachLatencyHistograms[type][respondingMach].add(cycles);
6337565SBrad.Beckmann@amd.com}
6347565SBrad.Beckmann@amd.com
6357565SBrad.Beckmann@amd.comvoid
6367565SBrad.Beckmann@amd.comProfiler::missLatencyWcc(Time issuedTime,
6377565SBrad.Beckmann@amd.com                         Time initialRequestTime,
6387565SBrad.Beckmann@amd.com                         Time forwardRequestTime,
6397565SBrad.Beckmann@amd.com                         Time firstResponseTime,
6407565SBrad.Beckmann@amd.com                         Time completionTime)
6417565SBrad.Beckmann@amd.com{
6427565SBrad.Beckmann@amd.com    if ((issuedTime <= initialRequestTime) &&
6437565SBrad.Beckmann@amd.com        (initialRequestTime <= forwardRequestTime) &&
6447565SBrad.Beckmann@amd.com        (forwardRequestTime <= firstResponseTime) &&
6457565SBrad.Beckmann@amd.com        (firstResponseTime <= completionTime)) {
6467565SBrad.Beckmann@amd.com        m_wCCIssueToInitialRequestHistogram.add(initialRequestTime - issuedTime);
6477565SBrad.Beckmann@amd.com
6487565SBrad.Beckmann@amd.com        m_wCCInitialRequestToForwardRequestHistogram.add(forwardRequestTime -
6497565SBrad.Beckmann@amd.com                                                         initialRequestTime);
6507565SBrad.Beckmann@amd.com
6517565SBrad.Beckmann@amd.com        m_wCCForwardRequestToFirstResponseHistogram.add(firstResponseTime -
6527565SBrad.Beckmann@amd.com                                                        forwardRequestTime);
6537565SBrad.Beckmann@amd.com
6547565SBrad.Beckmann@amd.com        m_wCCFirstResponseToCompleteHistogram.add(completionTime -
6557565SBrad.Beckmann@amd.com                                                  firstResponseTime);
6567565SBrad.Beckmann@amd.com    } else {
6577565SBrad.Beckmann@amd.com        m_wCCIncompleteTimes++;
6587565SBrad.Beckmann@amd.com    }
6597565SBrad.Beckmann@amd.com}
6607565SBrad.Beckmann@amd.com
6617565SBrad.Beckmann@amd.comvoid
6627565SBrad.Beckmann@amd.comProfiler::missLatencyDir(Time issuedTime,
6637565SBrad.Beckmann@amd.com                         Time initialRequestTime,
6647565SBrad.Beckmann@amd.com                         Time forwardRequestTime,
6657565SBrad.Beckmann@amd.com                         Time firstResponseTime,
6667565SBrad.Beckmann@amd.com                         Time completionTime)
6677565SBrad.Beckmann@amd.com{
6687565SBrad.Beckmann@amd.com    if ((issuedTime <= initialRequestTime) &&
6697565SBrad.Beckmann@amd.com        (initialRequestTime <= forwardRequestTime) &&
6707565SBrad.Beckmann@amd.com        (forwardRequestTime <= firstResponseTime) &&
6717565SBrad.Beckmann@amd.com        (firstResponseTime <= completionTime)) {
6727565SBrad.Beckmann@amd.com        m_dirIssueToInitialRequestHistogram.add(initialRequestTime - issuedTime);
6737565SBrad.Beckmann@amd.com
6747565SBrad.Beckmann@amd.com        m_dirInitialRequestToForwardRequestHistogram.add(forwardRequestTime -
6757565SBrad.Beckmann@amd.com                                                         initialRequestTime);
6767565SBrad.Beckmann@amd.com
6777565SBrad.Beckmann@amd.com        m_dirForwardRequestToFirstResponseHistogram.add(firstResponseTime -
6787565SBrad.Beckmann@amd.com                                                        forwardRequestTime);
6797565SBrad.Beckmann@amd.com
6807565SBrad.Beckmann@amd.com        m_dirFirstResponseToCompleteHistogram.add(completionTime -
6817565SBrad.Beckmann@amd.com                                                  firstResponseTime);
6827565SBrad.Beckmann@amd.com    } else {
6837565SBrad.Beckmann@amd.com        m_dirIncompleteTimes++;
6847565SBrad.Beckmann@amd.com    }
6856145Snate@binkert.org}
6866145Snate@binkert.org
6876145Snate@binkert.org// non-zero cycle prefetch request
6887048Snate@binkert.orgvoid
6897546SBrad.Beckmann@amd.comProfiler::swPrefetchLatency(Time cycles,
6908165Snilay@cs.wisc.edu                            RubyRequestType type,
6917546SBrad.Beckmann@amd.com                            const GenericMachineType respondingMach)
6926145Snate@binkert.org{
6937546SBrad.Beckmann@amd.com    m_allSWPrefetchLatencyHistogram.add(cycles);
6947546SBrad.Beckmann@amd.com    m_SWPrefetchLatencyHistograms[type].add(cycles);
6957546SBrad.Beckmann@amd.com    m_SWPrefetchMachLatencyHistograms[respondingMach].add(cycles);
6967048Snate@binkert.org    if (respondingMach == GenericMachineType_Directory ||
6977048Snate@binkert.org        respondingMach == GenericMachineType_NUM) {
6987546SBrad.Beckmann@amd.com        m_SWPrefetchL2MissLatencyHistogram.add(cycles);
6997048Snate@binkert.org    }
7006145Snate@binkert.org}
7016145Snate@binkert.org
7026145Snate@binkert.org// Helper function
7037048Snate@binkert.orgstatic double
7047048Snate@binkert.orgprocess_memory_total()
7056145Snate@binkert.org{
7067048Snate@binkert.org    // 4kB page size, 1024*1024 bytes per MB,
7077054Snate@binkert.org    const double MULTIPLIER = 4096.0 / (1024.0 * 1024.0);
7087048Snate@binkert.org    ifstream proc_file;
7097048Snate@binkert.org    proc_file.open("/proc/self/statm");
7107048Snate@binkert.org    int total_size_in_pages = 0;
7117048Snate@binkert.org    int res_size_in_pages = 0;
7127048Snate@binkert.org    proc_file >> total_size_in_pages;
7137048Snate@binkert.org    proc_file >> res_size_in_pages;
7147048Snate@binkert.org    return double(total_size_in_pages) * MULTIPLIER; // size in megabytes
7156145Snate@binkert.org}
7166145Snate@binkert.org
7177048Snate@binkert.orgstatic double
7187048Snate@binkert.orgprocess_memory_resident()
7196145Snate@binkert.org{
7207048Snate@binkert.org    // 4kB page size, 1024*1024 bytes per MB,
7217048Snate@binkert.org    const double MULTIPLIER = 4096.0 / (1024.0 * 1024.0);
7227048Snate@binkert.org    ifstream proc_file;
7237048Snate@binkert.org    proc_file.open("/proc/self/statm");
7247048Snate@binkert.org    int total_size_in_pages = 0;
7257048Snate@binkert.org    int res_size_in_pages = 0;
7267048Snate@binkert.org    proc_file >> total_size_in_pages;
7277048Snate@binkert.org    proc_file >> res_size_in_pages;
7287048Snate@binkert.org    return double(res_size_in_pages) * MULTIPLIER; // size in megabytes
7296145Snate@binkert.org}
7306145Snate@binkert.org
7317048Snate@binkert.orgvoid
7327048Snate@binkert.orgProfiler::rubyWatch(int id)
7337048Snate@binkert.org{
7347010SBrad.Beckmann@amd.com    uint64 tr = 0;
7356285Snate@binkert.org    Address watch_address = Address(tr);
7366285Snate@binkert.org
7379171Snilay@cs.wisc.edu    DPRINTFN("%7s %3s RUBY WATCH %d\n", g_system_ptr->getTime(), id,
7387832Snate@binkert.org        watch_address);
7397048Snate@binkert.org
7407455Snate@binkert.org    // don't care about success or failure
7417455Snate@binkert.org    m_watch_address_set.insert(watch_address);
7426285Snate@binkert.org}
7436285Snate@binkert.org
7447048Snate@binkert.orgbool
7457048Snate@binkert.orgProfiler::watchAddress(Address addr)
7467048Snate@binkert.org{
7477455Snate@binkert.org    return m_watch_address_set.count(addr) > 0;
7486285Snate@binkert.org}
7496285Snate@binkert.org
7506876Ssteve.reinhardt@amd.comProfiler *
7516876Ssteve.reinhardt@amd.comRubyProfilerParams::create()
7526876Ssteve.reinhardt@amd.com{
7536876Ssteve.reinhardt@amd.com    return new Profiler(this);
7546876Ssteve.reinhardt@amd.com}
755