probe.cc revision 10023:91faf6649de0
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 2013 ARM Limited 36145Snate@binkert.org * All rights reserved 46145Snate@binkert.org * 56145Snate@binkert.org * The license below extends only to copyright in the software and shall 66145Snate@binkert.org * not be construed as granting a license to any other intellectual 76145Snate@binkert.org * property including but not limited to intellectual property relating 86145Snate@binkert.org * to a hardware implementation of the functionality of the software 96145Snate@binkert.org * licensed hereunder. You may use the software subject to the license 106145Snate@binkert.org * terms below provided that you ensure that this notice is replicated 116145Snate@binkert.org * unmodified and in its entirety in all distributions of the software, 126145Snate@binkert.org * modified or unmodified, in source code or in binary form. 136145Snate@binkert.org * 146145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 156145Snate@binkert.org * modification, are permitted provided that the following conditions are 166145Snate@binkert.org * met: redistributions of source code must retain the above copyright 176145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 186145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 196145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 206145Snate@binkert.org * documentation and/or other materials provided with the distribution; 216145Snate@binkert.org * neither the name of the copyright holders nor the names of its 226145Snate@binkert.org * contributors may be used to endorse or promote products derived from 236145Snate@binkert.org * this software without specific prior written permission. 246145Snate@binkert.org * 256145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 266145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 276145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 286145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 296145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 307054Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 317054Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 327054Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 337054Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 347054Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 357054Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 367054Snate@binkert.org * 377054Snate@binkert.org * Authors: Matt Horsnell 387054Snate@binkert.org */ 396145Snate@binkert.org 407054Snate@binkert.org#include "debug/ProbeVerbose.hh" 417054Snate@binkert.org#include "sim/probe/probe.hh" 426145Snate@binkert.org 437055Snate@binkert.orgProbePoint::ProbePoint(ProbeManager *manager, const std::string& _name) 447055Snate@binkert.org : name(_name) 457454Snate@binkert.org{ 467055Snate@binkert.org if (manager) { 478257SBrad.Beckmann@amd.com manager->addPoint(*this); 487054Snate@binkert.org } 498645Snilay@cs.wisc.edu} 509594Snilay@cs.wisc.edu 519594Snilay@cs.wisc.eduProbeListenerObject::ProbeListenerObject(const ProbeListenerObjectParams *params) 527054Snate@binkert.org : SimObject(params), 539465Snilay@cs.wisc.edu manager(params->manager->getProbeManager()) 546145Snate@binkert.org{ 556145Snate@binkert.org} 566145Snate@binkert.org 576145Snate@binkert.orgProbeListenerObject::~ProbeListenerObject() 589465Snilay@cs.wisc.edu{ 597054Snate@binkert.org for (auto l = listeners.begin(); l != listeners.end(); ++l) { 607054Snate@binkert.org delete (*l); 616876Ssteve.reinhardt@amd.com } 626876Ssteve.reinhardt@amd.com listeners.clear(); 639594Snilay@cs.wisc.edu} 649594Snilay@cs.wisc.edu 656145Snate@binkert.orgProbeListener::ProbeListener(ProbeManager *manager, const std::string &name) 6610303Snilay@cs.wisc.edu{ 677054Snate@binkert.org manager->addListener(name, *this); 686145Snate@binkert.org} 699497Snilay@cs.wisc.edu 7010303Snilay@cs.wisc.eduProbeListenerObject* 7110303Snilay@cs.wisc.eduProbeListenerObjectParams::create() 729275Snilay@cs.wisc.edu{ 736493STushar.Krishna@amd.com return new ProbeListenerObject(this); 747054Snate@binkert.org} 757054Snate@binkert.org 768308Stushar@csail.mit.edubool 777054Snate@binkert.orgProbeManager::addListener(std::string pointName, ProbeListener &listener) 788308Stushar@csail.mit.edu{ 7910303Snilay@cs.wisc.edu DPRINTFR(ProbeVerbose, "Probes: Call to addListener to \"%s\" on %s.\n", pointName, object->name()); 806145Snate@binkert.org bool added = false; 818257SBrad.Beckmann@amd.com for (auto p = points.begin(); p != points.end(); ++p) { 828257SBrad.Beckmann@amd.com if ((*p)->getName() == pointName) { 839799Snilay@cs.wisc.edu (*p)->addListener(&listener); 848257SBrad.Beckmann@amd.com added = true; 858257SBrad.Beckmann@amd.com } 869799Snilay@cs.wisc.edu } 878257SBrad.Beckmann@amd.com if (!added) { 888257SBrad.Beckmann@amd.com DPRINTFR(ProbeVerbose, "Probes: Call to addListener to \"%s\" on %s failed, no such point.\n", pointName, object->name()); 899799Snilay@cs.wisc.edu } 906145Snate@binkert.org return added; 919863Snilay@cs.wisc.edu} 927055Snate@binkert.org 936145Snate@binkert.orgbool 949302Snilay@cs.wisc.eduProbeManager::removeListener(std::string pointName, ProbeListener &listener) 959302Snilay@cs.wisc.edu{ 969302Snilay@cs.wisc.edu DPRINTFR(ProbeVerbose, "Probes: Call to removeListener from \"%s\" on %s.\n", pointName, object->name()); 979302Snilay@cs.wisc.edu bool removed = false; 989302Snilay@cs.wisc.edu for (auto p = points.begin(); p != points.end(); ++p) { 999302Snilay@cs.wisc.edu if ((*p)->getName() == pointName) { 1009302Snilay@cs.wisc.edu (*p)->removeListener(&listener); 1019302Snilay@cs.wisc.edu removed = true; 1029302Snilay@cs.wisc.edu } 1039302Snilay@cs.wisc.edu } 1047054Snate@binkert.org if (!removed) { 1057054Snate@binkert.org DPRINTFR(ProbeVerbose, "Probes: Call to removeListener from \"%s\" on %s failed, no such point.\n", pointName, object->name()); 1067054Snate@binkert.org } 1077054Snate@binkert.org return removed; 1086145Snate@binkert.org} 1099863Snilay@cs.wisc.edu 1109275Snilay@cs.wisc.eduvoid 1117054Snate@binkert.orgProbeManager::addPoint(ProbePoint &point) 1129275Snilay@cs.wisc.edu{ 1139275Snilay@cs.wisc.edu DPRINTFR(ProbeVerbose, "Probes: Call to addPoint \"%s\" to %s.\n", point.getName(), object->name()); 1149863Snilay@cs.wisc.edu 11510082Snilay@cs.wisc.edu for (auto p = points.begin(); p != points.end(); ++p) { 11610082Snilay@cs.wisc.edu if ((*p)->getName() == point.getName()) { 11710082Snilay@cs.wisc.edu DPRINTFR(ProbeVerbose, "Probes: Call to addPoint \"%s\" to %s failed, already added.\n", point.getName(), object->name()); 11810082Snilay@cs.wisc.edu return; 11910082Snilay@cs.wisc.edu } 12010082Snilay@cs.wisc.edu } 12110082Snilay@cs.wisc.edu points.push_back(&point); 1229863Snilay@cs.wisc.edu} 1239863Snilay@cs.wisc.edu