gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
46namespace gem5
47{
48
49ProbePoint::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
72ProbeListener::ProbeListener(ProbeManager *_manager, const std::string &_name)
73 : manager(_manager), name(_name)
74{
75 manager->addListener(name, *this);
76}
77
82
83bool
84ProbeManager::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
102bool
103ProbeManager::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
121void
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
#define DPRINTFR(x,...)
Definition trace.hh:224
virtual std::string name() const
Definition named.hh:47
ProbeListenerObject(const ProbeListenerObjectParams &params)
Definition probe.cc:57
virtual ~ProbeListenerObject()
Definition probe.cc:64
std::vector< ProbeListener * > listeners
Definition probe.hh:111
ProbeListener base class; here to simplify things like containers containing multiple types of ProbeL...
Definition probe.hh:127
virtual ~ProbeListener()
Definition probe.cc:78
ProbeManager *const manager
Definition probe.hh:137
ProbeListener(ProbeManager *manager, const std::string &name)
Definition probe.cc:72
const std::string name
Definition probe.hh:138
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition probe.hh:164
bool addListener(std::string point_name, ProbeListener &listener)
Add a ProbeListener to the ProbePoint named by pointName.
Definition probe.cc:84
bool removeListener(std::string point_name, ProbeListener &listener)
Remove a ProbeListener from the ProbePoint named by pointName.
Definition probe.cc:103
void addPoint(ProbePoint &point)
Add a ProbePoint to this SimObject ProbeManager.
Definition probe.cc:122
std::vector< ProbePoint * > points
Vector for name look-up.
Definition probe.hh:169
GEM5_CLASS_VAR_USED const SimObject * object
Required for sensible debug messages.
Definition probe.hh:167
ProbeListener base class; again used to simplify use of ProbePoints in containers and used as to defi...
Definition probe.hh:147
ProbePoint(ProbeManager *manager, const std::string &name)
Definition probe.cc:49
std::string getName() const
Definition probe.hh:156
Abstract superclass for simulation objects.
Bitfield< 5 > l
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0