AccessTraceForAddress.cc revision 8165
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
297048Snate@binkert.org#include "mem/ruby/common/Histogram.hh"
306154Snate@binkert.org#include "mem/ruby/profiler/AccessTraceForAddress.hh"
316145Snate@binkert.org
326145Snate@binkert.orgAccessTraceForAddress::~AccessTraceForAddress()
336145Snate@binkert.org{
347455Snate@binkert.org    if (m_histogram_ptr) {
357048Snate@binkert.org        delete m_histogram_ptr;
367048Snate@binkert.org        m_histogram_ptr = NULL;
377048Snate@binkert.org    }
386145Snate@binkert.org}
396145Snate@binkert.org
407048Snate@binkert.orgvoid
417055Snate@binkert.orgAccessTraceForAddress::print(std::ostream& out) const
426145Snate@binkert.org{
437048Snate@binkert.org    out << m_addr;
446145Snate@binkert.org
457048Snate@binkert.org    if (m_histogram_ptr == NULL) {
467048Snate@binkert.org        out << " " << m_total;
477048Snate@binkert.org        out << " | " << m_loads;
487048Snate@binkert.org        out << " " << m_stores;
497048Snate@binkert.org        out << " " << m_atomics;
507048Snate@binkert.org        out << " | " << m_user;
517048Snate@binkert.org        out << " " << m_total-m_user;
527048Snate@binkert.org        out << " | " << m_sharing;
537048Snate@binkert.org        out << " | " << m_touched_by.count();
547048Snate@binkert.org    } else {
557048Snate@binkert.org        assert(m_total == 0);
567048Snate@binkert.org        out << " " << (*m_histogram_ptr);
577048Snate@binkert.org    }
586145Snate@binkert.org}
596145Snate@binkert.org
607048Snate@binkert.orgvoid
618165Snilay@cs.wisc.eduAccessTraceForAddress::update(RubyRequestType type,
628164Snilay@cs.wisc.edu                              RubyAccessMode access_mode, NodeID cpu,
637048Snate@binkert.org                              bool sharing_miss)
646145Snate@binkert.org{
657048Snate@binkert.org    m_touched_by.add(cpu);
667048Snate@binkert.org    m_total++;
678165Snilay@cs.wisc.edu    if(type == RubyRequestType_ATOMIC) {
687048Snate@binkert.org        m_atomics++;
698165Snilay@cs.wisc.edu    } else if(type == RubyRequestType_LD){
707048Snate@binkert.org        m_loads++;
718165Snilay@cs.wisc.edu    } else if (type == RubyRequestType_ST){
727048Snate@binkert.org        m_stores++;
737048Snate@binkert.org    } else {
747048Snate@binkert.org        //  ERROR_MSG("Trying to add invalid access to trace");
757048Snate@binkert.org    }
766145Snate@binkert.org
778164Snilay@cs.wisc.edu    if (access_mode == RubyAccessMode_User) {
787048Snate@binkert.org        m_user++;
797048Snate@binkert.org    }
806145Snate@binkert.org
817048Snate@binkert.org    if (sharing_miss) {
827048Snate@binkert.org        m_sharing++;
837048Snate@binkert.org    }
846145Snate@binkert.org}
856145Snate@binkert.org
867048Snate@binkert.orgint
877048Snate@binkert.orgAccessTraceForAddress::getTotal() const
886145Snate@binkert.org{
897048Snate@binkert.org    if (m_histogram_ptr == NULL) {
907048Snate@binkert.org        return m_total;
917048Snate@binkert.org    } else {
927048Snate@binkert.org        return m_histogram_ptr->getTotal();
937048Snate@binkert.org    }
946145Snate@binkert.org}
956145Snate@binkert.org
967048Snate@binkert.orgvoid
977048Snate@binkert.orgAccessTraceForAddress::addSample(int value)
986145Snate@binkert.org{
997048Snate@binkert.org    assert(m_total == 0);
1007048Snate@binkert.org    if (m_histogram_ptr == NULL) {
1017048Snate@binkert.org        m_histogram_ptr = new Histogram;
1027048Snate@binkert.org    }
1037048Snate@binkert.org    m_histogram_ptr->add(value);
1046145Snate@binkert.org}
105