probe.cc revision 11793
110023Smatt.horsnell@ARM.com/* 210023Smatt.horsnell@ARM.com * Copyright (c) 2013 ARM Limited 310023Smatt.horsnell@ARM.com * All rights reserved 410023Smatt.horsnell@ARM.com * 510023Smatt.horsnell@ARM.com * The license below extends only to copyright in the software and shall 610023Smatt.horsnell@ARM.com * not be construed as granting a license to any other intellectual 710023Smatt.horsnell@ARM.com * property including but not limited to intellectual property relating 810023Smatt.horsnell@ARM.com * to a hardware implementation of the functionality of the software 910023Smatt.horsnell@ARM.com * licensed hereunder. You may use the software subject to the license 1010023Smatt.horsnell@ARM.com * terms below provided that you ensure that this notice is replicated 1110023Smatt.horsnell@ARM.com * unmodified and in its entirety in all distributions of the software, 1210023Smatt.horsnell@ARM.com * modified or unmodified, in source code or in binary form. 1310023Smatt.horsnell@ARM.com * 1410023Smatt.horsnell@ARM.com * Redistribution and use in source and binary forms, with or without 1510023Smatt.horsnell@ARM.com * modification, are permitted provided that the following conditions are 1610023Smatt.horsnell@ARM.com * met: redistributions of source code must retain the above copyright 1710023Smatt.horsnell@ARM.com * notice, this list of conditions and the following disclaimer; 1810023Smatt.horsnell@ARM.com * redistributions in binary form must reproduce the above copyright 1910023Smatt.horsnell@ARM.com * notice, this list of conditions and the following disclaimer in the 2010023Smatt.horsnell@ARM.com * documentation and/or other materials provided with the distribution; 2110023Smatt.horsnell@ARM.com * neither the name of the copyright holders nor the names of its 2210023Smatt.horsnell@ARM.com * contributors may be used to endorse or promote products derived from 2310023Smatt.horsnell@ARM.com * this software without specific prior written permission. 2410023Smatt.horsnell@ARM.com * 2510023Smatt.horsnell@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2610023Smatt.horsnell@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2710023Smatt.horsnell@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2810023Smatt.horsnell@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2910023Smatt.horsnell@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3010023Smatt.horsnell@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3110023Smatt.horsnell@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3210023Smatt.horsnell@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3310023Smatt.horsnell@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3410023Smatt.horsnell@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3510023Smatt.horsnell@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3610023Smatt.horsnell@ARM.com * 3710023Smatt.horsnell@ARM.com * Authors: Matt Horsnell 3810023Smatt.horsnell@ARM.com */ 3910023Smatt.horsnell@ARM.com 4011793Sbrandon.potter@amd.com#include "sim/probe/probe.hh" 4111793Sbrandon.potter@amd.com 4210023Smatt.horsnell@ARM.com#include "debug/ProbeVerbose.hh" 4310023Smatt.horsnell@ARM.com 4410023Smatt.horsnell@ARM.comProbePoint::ProbePoint(ProbeManager *manager, const std::string& _name) 4510023Smatt.horsnell@ARM.com : name(_name) 4610023Smatt.horsnell@ARM.com{ 4710023Smatt.horsnell@ARM.com if (manager) { 4810023Smatt.horsnell@ARM.com manager->addPoint(*this); 4910023Smatt.horsnell@ARM.com } 5010023Smatt.horsnell@ARM.com} 5110023Smatt.horsnell@ARM.com 5210023Smatt.horsnell@ARM.comProbeListenerObject::ProbeListenerObject(const ProbeListenerObjectParams *params) 5310023Smatt.horsnell@ARM.com : SimObject(params), 5410023Smatt.horsnell@ARM.com manager(params->manager->getProbeManager()) 5510023Smatt.horsnell@ARM.com{ 5610023Smatt.horsnell@ARM.com} 5710023Smatt.horsnell@ARM.com 5810023Smatt.horsnell@ARM.comProbeListenerObject::~ProbeListenerObject() 5910023Smatt.horsnell@ARM.com{ 6010023Smatt.horsnell@ARM.com for (auto l = listeners.begin(); l != listeners.end(); ++l) { 6110023Smatt.horsnell@ARM.com delete (*l); 6210023Smatt.horsnell@ARM.com } 6310023Smatt.horsnell@ARM.com listeners.clear(); 6410023Smatt.horsnell@ARM.com} 6510023Smatt.horsnell@ARM.com 6610365SAndreas.Sandberg@ARM.comProbeListener::ProbeListener(ProbeManager *_manager, const std::string &_name) 6710365SAndreas.Sandberg@ARM.com : manager(_manager), name(_name) 6810023Smatt.horsnell@ARM.com{ 6910023Smatt.horsnell@ARM.com manager->addListener(name, *this); 7010023Smatt.horsnell@ARM.com} 7110023Smatt.horsnell@ARM.com 7210365SAndreas.Sandberg@ARM.comProbeListener::~ProbeListener() 7310365SAndreas.Sandberg@ARM.com{ 7410365SAndreas.Sandberg@ARM.com manager->removeListener(name, *this); 7510365SAndreas.Sandberg@ARM.com} 7610365SAndreas.Sandberg@ARM.com 7710023Smatt.horsnell@ARM.comProbeListenerObject* 7810023Smatt.horsnell@ARM.comProbeListenerObjectParams::create() 7910023Smatt.horsnell@ARM.com{ 8010023Smatt.horsnell@ARM.com return new ProbeListenerObject(this); 8110023Smatt.horsnell@ARM.com} 8210023Smatt.horsnell@ARM.com 8310023Smatt.horsnell@ARM.combool 8410023Smatt.horsnell@ARM.comProbeManager::addListener(std::string pointName, ProbeListener &listener) 8510023Smatt.horsnell@ARM.com{ 8610023Smatt.horsnell@ARM.com DPRINTFR(ProbeVerbose, "Probes: Call to addListener to \"%s\" on %s.\n", pointName, object->name()); 8710023Smatt.horsnell@ARM.com bool added = false; 8810023Smatt.horsnell@ARM.com for (auto p = points.begin(); p != points.end(); ++p) { 8910023Smatt.horsnell@ARM.com if ((*p)->getName() == pointName) { 9010023Smatt.horsnell@ARM.com (*p)->addListener(&listener); 9110023Smatt.horsnell@ARM.com added = true; 9210023Smatt.horsnell@ARM.com } 9310023Smatt.horsnell@ARM.com } 9410023Smatt.horsnell@ARM.com if (!added) { 9510023Smatt.horsnell@ARM.com DPRINTFR(ProbeVerbose, "Probes: Call to addListener to \"%s\" on %s failed, no such point.\n", pointName, object->name()); 9610023Smatt.horsnell@ARM.com } 9710023Smatt.horsnell@ARM.com return added; 9810023Smatt.horsnell@ARM.com} 9910023Smatt.horsnell@ARM.com 10010023Smatt.horsnell@ARM.combool 10110023Smatt.horsnell@ARM.comProbeManager::removeListener(std::string pointName, ProbeListener &listener) 10210023Smatt.horsnell@ARM.com{ 10310023Smatt.horsnell@ARM.com DPRINTFR(ProbeVerbose, "Probes: Call to removeListener from \"%s\" on %s.\n", pointName, object->name()); 10410023Smatt.horsnell@ARM.com bool removed = false; 10510023Smatt.horsnell@ARM.com for (auto p = points.begin(); p != points.end(); ++p) { 10610023Smatt.horsnell@ARM.com if ((*p)->getName() == pointName) { 10710023Smatt.horsnell@ARM.com (*p)->removeListener(&listener); 10810023Smatt.horsnell@ARM.com removed = true; 10910023Smatt.horsnell@ARM.com } 11010023Smatt.horsnell@ARM.com } 11110023Smatt.horsnell@ARM.com if (!removed) { 11210023Smatt.horsnell@ARM.com DPRINTFR(ProbeVerbose, "Probes: Call to removeListener from \"%s\" on %s failed, no such point.\n", pointName, object->name()); 11310023Smatt.horsnell@ARM.com } 11410023Smatt.horsnell@ARM.com return removed; 11510023Smatt.horsnell@ARM.com} 11610023Smatt.horsnell@ARM.com 11710023Smatt.horsnell@ARM.comvoid 11810023Smatt.horsnell@ARM.comProbeManager::addPoint(ProbePoint &point) 11910023Smatt.horsnell@ARM.com{ 12010023Smatt.horsnell@ARM.com DPRINTFR(ProbeVerbose, "Probes: Call to addPoint \"%s\" to %s.\n", point.getName(), object->name()); 12110023Smatt.horsnell@ARM.com 12210023Smatt.horsnell@ARM.com for (auto p = points.begin(); p != points.end(); ++p) { 12310023Smatt.horsnell@ARM.com if ((*p)->getName() == point.getName()) { 12410023Smatt.horsnell@ARM.com DPRINTFR(ProbeVerbose, "Probes: Call to addPoint \"%s\" to %s failed, already added.\n", point.getName(), object->name()); 12510023Smatt.horsnell@ARM.com return; 12610023Smatt.horsnell@ARM.com } 12710023Smatt.horsnell@ARM.com } 12810023Smatt.horsnell@ARM.com points.push_back(&point); 12910023Smatt.horsnell@ARM.com} 130