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
2911793Sbrandon.potter@amd.com#include "mem/ruby/profiler/AccessTraceForAddress.hh"
3011793Sbrandon.potter@amd.com
317048Snate@binkert.org#include "mem/ruby/common/Histogram.hh"
326145Snate@binkert.org
336145Snate@binkert.orgAccessTraceForAddress::~AccessTraceForAddress()
346145Snate@binkert.org{
357455Snate@binkert.org    if (m_histogram_ptr) {
367048Snate@binkert.org        delete m_histogram_ptr;
377048Snate@binkert.org        m_histogram_ptr = NULL;
387048Snate@binkert.org    }
396145Snate@binkert.org}
406145Snate@binkert.org
417048Snate@binkert.orgvoid
427055Snate@binkert.orgAccessTraceForAddress::print(std::ostream& out) const
436145Snate@binkert.org{
447048Snate@binkert.org    out << m_addr;
456145Snate@binkert.org
467048Snate@binkert.org    if (m_histogram_ptr == NULL) {
477048Snate@binkert.org        out << " " << m_total;
487048Snate@binkert.org        out << " | " << m_loads;
497048Snate@binkert.org        out << " " << m_stores;
507048Snate@binkert.org        out << " " << m_atomics;
517048Snate@binkert.org        out << " | " << m_user;
527048Snate@binkert.org        out << " " << m_total-m_user;
537048Snate@binkert.org        out << " | " << m_sharing;
547048Snate@binkert.org        out << " | " << m_touched_by.count();
557048Snate@binkert.org    } else {
567048Snate@binkert.org        assert(m_total == 0);
577048Snate@binkert.org        out << " " << (*m_histogram_ptr);
587048Snate@binkert.org    }
596145Snate@binkert.org}
606145Snate@binkert.org
617048Snate@binkert.orgvoid
628165Snilay@cs.wisc.eduAccessTraceForAddress::update(RubyRequestType type,
638164Snilay@cs.wisc.edu                              RubyAccessMode access_mode, NodeID cpu,
647048Snate@binkert.org                              bool sharing_miss)
656145Snate@binkert.org{
667048Snate@binkert.org    m_touched_by.add(cpu);
677048Snate@binkert.org    m_total++;
6811321Ssteve.reinhardt@amd.com    if (type == RubyRequestType_ATOMIC) {
697048Snate@binkert.org        m_atomics++;
7011321Ssteve.reinhardt@amd.com    } else if (type == RubyRequestType_LD){
717048Snate@binkert.org        m_loads++;
728165Snilay@cs.wisc.edu    } else if (type == RubyRequestType_ST){
737048Snate@binkert.org        m_stores++;
747048Snate@binkert.org    } else {
757048Snate@binkert.org        //  ERROR_MSG("Trying to add invalid access to trace");
767048Snate@binkert.org    }
776145Snate@binkert.org
788164Snilay@cs.wisc.edu    if (access_mode == RubyAccessMode_User) {
797048Snate@binkert.org        m_user++;
807048Snate@binkert.org    }
816145Snate@binkert.org
827048Snate@binkert.org    if (sharing_miss) {
837048Snate@binkert.org        m_sharing++;
847048Snate@binkert.org    }
856145Snate@binkert.org}
866145Snate@binkert.org
877048Snate@binkert.orgint
887048Snate@binkert.orgAccessTraceForAddress::getTotal() const
896145Snate@binkert.org{
907048Snate@binkert.org    if (m_histogram_ptr == NULL) {
917048Snate@binkert.org        return m_total;
927048Snate@binkert.org    } else {
937048Snate@binkert.org        return m_histogram_ptr->getTotal();
947048Snate@binkert.org    }
956145Snate@binkert.org}
966145Snate@binkert.org
977048Snate@binkert.orgvoid
987048Snate@binkert.orgAccessTraceForAddress::addSample(int value)
996145Snate@binkert.org{
1007048Snate@binkert.org    assert(m_total == 0);
1017048Snate@binkert.org    if (m_histogram_ptr == NULL) {
1027048Snate@binkert.org        m_histogram_ptr = new Histogram;
1037048Snate@binkert.org    }
1047048Snate@binkert.org    m_histogram_ptr->add(value);
1056145Snate@binkert.org}
106