AccessTraceForAddress.cc revision 7055
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{ 347048Snate@binkert.org m_histogram_ptr = NULL; 356145Snate@binkert.org} 366145Snate@binkert.org 376145Snate@binkert.orgAccessTraceForAddress::AccessTraceForAddress(const Address& addr) 386145Snate@binkert.org{ 397048Snate@binkert.org m_addr = addr; 407048Snate@binkert.org m_total = 0; 417048Snate@binkert.org m_loads = 0; 427048Snate@binkert.org m_stores = 0; 437048Snate@binkert.org m_atomics = 0; 447048Snate@binkert.org m_user = 0; 457048Snate@binkert.org m_sharing = 0; 467048Snate@binkert.org m_histogram_ptr = NULL; 476145Snate@binkert.org} 486145Snate@binkert.org 496145Snate@binkert.orgAccessTraceForAddress::~AccessTraceForAddress() 506145Snate@binkert.org{ 517048Snate@binkert.org if (m_histogram_ptr != NULL) { 527048Snate@binkert.org delete m_histogram_ptr; 537048Snate@binkert.org m_histogram_ptr = NULL; 547048Snate@binkert.org } 556145Snate@binkert.org} 566145Snate@binkert.org 577048Snate@binkert.orgvoid 587055Snate@binkert.orgAccessTraceForAddress::print(std::ostream& out) const 596145Snate@binkert.org{ 607048Snate@binkert.org out << m_addr; 616145Snate@binkert.org 627048Snate@binkert.org if (m_histogram_ptr == NULL) { 637048Snate@binkert.org out << " " << m_total; 647048Snate@binkert.org out << " | " << m_loads; 657048Snate@binkert.org out << " " << m_stores; 667048Snate@binkert.org out << " " << m_atomics; 677048Snate@binkert.org out << " | " << m_user; 687048Snate@binkert.org out << " " << m_total-m_user; 697048Snate@binkert.org out << " | " << m_sharing; 707048Snate@binkert.org out << " | " << m_touched_by.count(); 717048Snate@binkert.org } else { 727048Snate@binkert.org assert(m_total == 0); 737048Snate@binkert.org out << " " << (*m_histogram_ptr); 747048Snate@binkert.org } 756145Snate@binkert.org} 766145Snate@binkert.org 777048Snate@binkert.orgvoid 787048Snate@binkert.orgAccessTraceForAddress::update(CacheRequestType type, 797048Snate@binkert.org AccessModeType access_mode, NodeID cpu, 807048Snate@binkert.org bool sharing_miss) 816145Snate@binkert.org{ 827048Snate@binkert.org m_touched_by.add(cpu); 837048Snate@binkert.org m_total++; 847048Snate@binkert.org if(type == CacheRequestType_ATOMIC) { 857048Snate@binkert.org m_atomics++; 867048Snate@binkert.org } else if(type == CacheRequestType_LD){ 877048Snate@binkert.org m_loads++; 887048Snate@binkert.org } else if (type == CacheRequestType_ST){ 897048Snate@binkert.org m_stores++; 907048Snate@binkert.org } else { 917048Snate@binkert.org // ERROR_MSG("Trying to add invalid access to trace"); 927048Snate@binkert.org } 936145Snate@binkert.org 947048Snate@binkert.org if (access_mode == AccessModeType_UserMode) { 957048Snate@binkert.org m_user++; 967048Snate@binkert.org } 976145Snate@binkert.org 987048Snate@binkert.org if (sharing_miss) { 997048Snate@binkert.org m_sharing++; 1007048Snate@binkert.org } 1016145Snate@binkert.org} 1026145Snate@binkert.org 1037048Snate@binkert.orgint 1047048Snate@binkert.orgAccessTraceForAddress::getTotal() const 1056145Snate@binkert.org{ 1067048Snate@binkert.org if (m_histogram_ptr == NULL) { 1077048Snate@binkert.org return m_total; 1087048Snate@binkert.org } else { 1097048Snate@binkert.org return m_histogram_ptr->getTotal(); 1107048Snate@binkert.org } 1116145Snate@binkert.org} 1126145Snate@binkert.org 1137048Snate@binkert.orgvoid 1147048Snate@binkert.orgAccessTraceForAddress::addSample(int value) 1156145Snate@binkert.org{ 1167048Snate@binkert.org assert(m_total == 0); 1177048Snate@binkert.org if (m_histogram_ptr == NULL) { 1187048Snate@binkert.org m_histogram_ptr = new Histogram; 1197048Snate@binkert.org } 1207048Snate@binkert.org m_histogram_ptr->add(value); 1216145Snate@binkert.org} 122