gem5  v21.1.0.2
probe.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2020 Inria
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #include "sim/probe/probe.hh"
42 
43 #include "debug/ProbeVerbose.hh"
44 #include "params/ProbeListenerObject.hh"
45 
46 namespace gem5
47 {
48 
49 ProbePoint::ProbePoint(ProbeManager *manager, const std::string& _name)
50  : name(_name)
51 {
52  if (manager) {
53  manager->addPoint(*this);
54  }
55 }
56 
58  const ProbeListenerObjectParams &params)
59  : SimObject(params),
60  manager(params.manager->getProbeManager())
61 {
62 }
63 
65 {
66  for (auto l = listeners.begin(); l != listeners.end(); ++l) {
67  delete (*l);
68  }
69  listeners.clear();
70 }
71 
72 ProbeListener::ProbeListener(ProbeManager *_manager, const std::string &_name)
73  : manager(_manager), name(_name)
74 {
75  manager->addListener(name, *this);
76 }
77 
79 {
80  manager->removeListener(name, *this);
81 }
82 
83 bool
84 ProbeManager::addListener(std::string point_name, ProbeListener &listener)
85 {
86  DPRINTFR(ProbeVerbose, "Probes: Call to addListener to \"%s\" on %s.\n",
87  point_name, object->name());
88  bool added = false;
89  for (auto p = points.begin(); p != points.end(); ++p) {
90  if ((*p)->getName() == point_name) {
91  (*p)->addListener(&listener);
92  added = true;
93  }
94  }
95  if (!added) {
96  DPRINTFR(ProbeVerbose, "Probes: Call to addListener to \"%s\" on "
97  "%s failed, no such point.\n", point_name, object->name());
98  }
99  return added;
100 }
101 
102 bool
103 ProbeManager::removeListener(std::string point_name, ProbeListener &listener)
104 {
105  DPRINTFR(ProbeVerbose, "Probes: Call to removeListener from \"%s\" on "
106  "%s.\n", point_name, object->name());
107  bool removed = false;
108  for (auto p = points.begin(); p != points.end(); ++p) {
109  if ((*p)->getName() == point_name) {
110  (*p)->removeListener(&listener);
111  removed = true;
112  }
113  }
114  if (!removed) {
115  DPRINTFR(ProbeVerbose, "Probes: Call to removeListener from \"%s\" "
116  "on %s failed, no such point.\n", point_name, object->name());
117  }
118  return removed;
119 }
120 
121 void
123 {
124  DPRINTFR(ProbeVerbose, "Probes: Call to addPoint \"%s\" to %s.\n",
125  point.getName(), object->name());
126 
127  for (auto p = points.begin(); p != points.end(); ++p) {
128  if ((*p)->getName() == point.getName()) {
129  DPRINTFR(ProbeVerbose, "Probes: Call to addPoint \"%s\" to %s "
130  "failed, already added.\n", point.getName(), object->name());
131  return;
132  }
133  }
134  points.push_back(&point);
135 }
136 
137 } // namespace gem5
gem5::ProbeListener::ProbeListener
ProbeListener(ProbeManager *manager, const std::string &name)
Definition: probe.cc:72
gem5::ProbeListener::~ProbeListener
virtual ~ProbeListener()
Definition: probe.cc:78
gem5::ProbePoint::getName
std::string getName() const
Definition: probe.hh:156
gem5::ProbeManager::addListener
bool addListener(std::string point_name, ProbeListener &listener)
Add a ProbeListener to the ProbePoint named by pointName.
Definition: probe.cc:84
DPRINTFR
#define DPRINTFR(x,...)
Definition: trace.hh:200
gem5::ProbeListener::manager
ProbeManager *const manager
Definition: probe.hh:137
gem5::ProbeListenerObject::listeners
std::vector< ProbeListener * > listeners
Definition: probe.hh:111
gem5::ProbeListenerObject::ProbeListenerObject
ProbeListenerObject(const ProbeListenerObjectParams &params)
Definition: probe.cc:57
gem5::ProbeManager::addPoint
void addPoint(ProbePoint &point)
Add a ProbePoint to this SimObject ProbeManager.
Definition: probe.cc:122
gem5::ProbeListener
ProbeListener base class; here to simplify things like containers containing multiple types of ProbeL...
Definition: probe.hh:126
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::ProbeManager::points
std::vector< ProbePoint * > points
Vector for name look-up.
Definition: probe.hh:169
gem5::MipsISA::l
Bitfield< 5 > l
Definition: pra_constants.hh:323
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
name
const std::string & name()
Definition: trace.cc:49
gem5::ProbeManager
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:163
gem5::ProbeListenerObject::~ProbeListenerObject
virtual ~ProbeListenerObject()
Definition: probe.cc:64
gem5::ProbePoint::ProbePoint
ProbePoint(ProbeManager *manager, const std::string &name)
Definition: probe.cc:49
gem5::ProbeListener::name
const std::string name
Definition: probe.hh:138
gem5::ProbePoint
ProbeListener base class; again used to simplify use of ProbePoints in containers and used as to defi...
Definition: probe.hh:146
gem5::ProbeManager::object
const GEM5_CLASS_VAR_USED SimObject * object
Required for sensible debug messages.
Definition: probe.hh:167
probe.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::ProbeManager::removeListener
bool removeListener(std::string point_name, ProbeListener &listener)
Remove a ProbeListener from the ProbePoint named by pointName.
Definition: probe.cc:103

Generated on Tue Sep 21 2021 12:25:48 for gem5 by doxygen 1.8.17