AccessTraceForAddress.cc revision 7048:2ab58c54de63
1/* 2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include "mem/ruby/common/Histogram.hh" 30#include "mem/ruby/profiler/AccessTraceForAddress.hh" 31 32AccessTraceForAddress::AccessTraceForAddress() 33{ 34 m_histogram_ptr = NULL; 35} 36 37AccessTraceForAddress::AccessTraceForAddress(const Address& addr) 38{ 39 m_addr = addr; 40 m_total = 0; 41 m_loads = 0; 42 m_stores = 0; 43 m_atomics = 0; 44 m_user = 0; 45 m_sharing = 0; 46 m_histogram_ptr = NULL; 47} 48 49AccessTraceForAddress::~AccessTraceForAddress() 50{ 51 if (m_histogram_ptr != NULL) { 52 delete m_histogram_ptr; 53 m_histogram_ptr = NULL; 54 } 55} 56 57void 58AccessTraceForAddress::print(ostream& out) const 59{ 60 out << m_addr; 61 62 if (m_histogram_ptr == NULL) { 63 out << " " << m_total; 64 out << " | " << m_loads; 65 out << " " << m_stores; 66 out << " " << m_atomics; 67 out << " | " << m_user; 68 out << " " << m_total-m_user; 69 out << " | " << m_sharing; 70 out << " | " << m_touched_by.count(); 71 } else { 72 assert(m_total == 0); 73 out << " " << (*m_histogram_ptr); 74 } 75} 76 77void 78AccessTraceForAddress::update(CacheRequestType type, 79 AccessModeType access_mode, NodeID cpu, 80 bool sharing_miss) 81{ 82 m_touched_by.add(cpu); 83 m_total++; 84 if(type == CacheRequestType_ATOMIC) { 85 m_atomics++; 86 } else if(type == CacheRequestType_LD){ 87 m_loads++; 88 } else if (type == CacheRequestType_ST){ 89 m_stores++; 90 } else { 91 // ERROR_MSG("Trying to add invalid access to trace"); 92 } 93 94 if (access_mode == AccessModeType_UserMode) { 95 m_user++; 96 } 97 98 if (sharing_miss) { 99 m_sharing++; 100 } 101} 102 103int 104AccessTraceForAddress::getTotal() const 105{ 106 if (m_histogram_ptr == NULL) { 107 return m_total; 108 } else { 109 return m_histogram_ptr->getTotal(); 110 } 111} 112 113void 114AccessTraceForAddress::addSample(int value) 115{ 116 assert(m_total == 0); 117 if (m_histogram_ptr == NULL) { 118 m_histogram_ptr = new Histogram; 119 } 120 m_histogram_ptr->add(value); 121} 122