gem5 v24.0.0.0
Loading...
Searching...
No Matches
probe.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 ARM Limited
3 * Copyright (c) 2022-2023 The University of Edinburgh
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 2020 Inria
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
64#ifndef __SIM_PROBE_PROBE_HH__
65#define __SIM_PROBE_PROBE_HH__
66
67#include <string>
68#include <vector>
69
70#include "base/compiler.hh"
71#include "base/trace.hh"
72#include "sim/sim_object.hh"
73
74namespace gem5
75{
76
78class ProbeManager;
79class ProbeListener;
80struct ProbeListenerObjectParams;
81
90namespace probing
91{
92/* Note: This is only here for documentation purposes, new probe
93 * points should normally be declared in their own header files. See
94 * for example pmu.hh.
95 */
96}
97
108{
109 protected:
112
113 public:
114 ProbeListenerObject(const ProbeListenerObjectParams &params);
115 virtual ~ProbeListenerObject();
117};
118
127{
128 public:
129 ProbeListener(ProbeManager *manager, const std::string &name);
130 virtual ~ProbeListener();
131 ProbeListener(const ProbeListener& other) = delete;
132 ProbeListener& operator=(const ProbeListener& other) = delete;
133 ProbeListener(ProbeListener&& other) noexcept = delete;
134 ProbeListener& operator=(ProbeListener&& other) noexcept = delete;
135
136 protected:
138 const std::string name;
139};
140
147{
148 protected:
149 const std::string name;
150 public:
151 ProbePoint(ProbeManager *manager, const std::string &name);
152 virtual ~ProbePoint() {}
153
154 virtual void addListener(ProbeListener *listener) = 0;
155 virtual void removeListener(ProbeListener *listener) = 0;
156 std::string getName() const { return name; }
157};
158
164{
165 private:
170
171 public:
173 : object(obj)
174 {}
175 virtual ~ProbeManager() {}
176
184 bool addListener(std::string point_name, ProbeListener &listener);
185
194 bool removeListener(std::string point_name, ProbeListener &listener);
195
200 void addPoint(ProbePoint &point);
201};
202
210template <class Arg>
212{
213 public:
214 ProbeListenerArgBase(ProbeManager *pm, const std::string &name)
215 : ProbeListener(pm, name)
216 {}
217 virtual void notify(const Arg &val) = 0;
218};
219
227template <class T, class Arg>
229{
230 private:
232 void (T::* function)(const Arg &);
233
234 public:
240 ProbeListenerArg(T *obj, const std::string &name,
241 void (T::* func)(const Arg &))
242 : ProbeListenerArgBase<Arg>(obj->getProbeManager(), name),
243 object(obj),
244 function(func)
245 {}
246
252 void notify(const Arg &val) override { (object->*function)(val); }
253};
254
262template <typename Arg>
264{
267
268 public:
269 ProbePointArg(ProbeManager *manager, std::string name)
270 : ProbePoint(manager, name)
271 {
272 }
273
281 bool hasListeners() const { return listeners.size() > 0; }
282
287 void
289 {
290 // check listener not already added
291 if (std::find(listeners.begin(), listeners.end(), l) ==
292 listeners.end()) {
293 listeners.push_back(static_cast<ProbeListenerArgBase<Arg> *>(l));
294 }
295 }
296
301 void
303 {
304 listeners.erase(std::remove(listeners.begin(), listeners.end(), l),
305 listeners.end());
306 }
307
312 void
313 notify(const Arg &arg)
314 {
315 for (auto l = listeners.begin(); l != listeners.end(); ++l) {
316 (*l)->notify(arg);
317 }
318 }
319};
320
321
333template <class Arg>
335{
336 typedef std::function<void(const Arg &)> NotifyFunction;
337 private:
339
340 public:
347 ProbeListenerArgFunc(ProbeManager *pm, const std::string &name,
348 const NotifyFunction &func)
349 : ProbeListenerArgBase<Arg>(pm, name),
350 function(func)
351 {}
352
358 void notify(const Arg &val) override { function(val); }
359};
360
361
362} // namespace gem5
363
364#endif//__SIM_PROBE_PROBE_HH__
ProbeListenerArgBase is used to define the base interface to a ProbeListenerArg (i....
Definition probe.hh:212
ProbeListenerArgBase(ProbeManager *pm, const std::string &name)
Definition probe.hh:214
virtual void notify(const Arg &val)=0
ProbeListenerArgFunc generates a listener for the class of Arg and a lambda callback function that is...
Definition probe.hh:335
ProbeListenerArgFunc(ProbeManager *pm, const std::string &name, const NotifyFunction &func)
Definition probe.hh:347
std::function< void(const Arg &)> NotifyFunction
Definition probe.hh:336
void notify(const Arg &val) override
called when the ProbePoint calls notify.
Definition probe.hh:358
NotifyFunction function
Definition probe.hh:338
ProbeListenerArg generates a listener for the class of Arg and the class type T which is the class co...
Definition probe.hh:229
ProbeListenerArg(T *obj, const std::string &name, void(T::*func)(const Arg &))
Definition probe.hh:240
void(T::* function)(const Arg &)
Definition probe.hh:232
void notify(const Arg &val) override
called when the ProbePoint calls notify.
Definition probe.hh:252
This class is a minimal wrapper around SimObject.
Definition probe.hh:108
ProbeListenerObject(const ProbeListenerObjectParams &params)
Definition probe.cc:57
ProbeManager * getProbeManager()
Definition probe.hh:116
virtual ~ProbeListenerObject()
Definition probe.cc:64
ProbeManager * manager
Definition probe.hh:110
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
ProbeListener & operator=(const ProbeListener &other)=delete
ProbeListener & operator=(ProbeListener &&other) noexcept=delete
ProbeListener(ProbeListener &&other) noexcept=delete
virtual ~ProbeListener()
Definition probe.cc:78
ProbeManager *const manager
Definition probe.hh:137
ProbeListener(ProbeManager *manager, const std::string &name)
Definition probe.cc:72
ProbeListener(const ProbeListener &other)=delete
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
ProbeManager(SimObject *obj)
Definition probe.hh:172
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
virtual ~ProbeManager()
Definition probe.hh:175
ProbePointArg generates a point for the class of Arg.
Definition probe.hh:264
void addListener(ProbeListener *l) override
adds a ProbeListener to this ProbePoints notify list.
Definition probe.hh:288
void removeListener(ProbeListener *l) override
remove a ProbeListener from this ProbePoints notify list.
Definition probe.hh:302
bool hasListeners() const
Informs whether any listeners are attached to this probe.
Definition probe.hh:281
void notify(const Arg &arg)
called at the ProbePoint call site, passes arg to each listener.
Definition probe.hh:313
ProbePointArg(ProbeManager *manager, std::string name)
Definition probe.hh:269
std::vector< ProbeListenerArgBase< Arg > * > listeners
The attached listeners.
Definition probe.hh:266
ProbeListener base class; again used to simplify use of ProbePoints in containers and used as to defi...
Definition probe.hh:147
virtual ~ProbePoint()
Definition probe.hh:152
virtual void removeListener(ProbeListener *listener)=0
const std::string name
Definition probe.hh:149
ProbePoint(ProbeManager *manager, const std::string &name)
Definition probe.cc:49
virtual void addListener(ProbeListener *listener)=0
std::string getName() const
Definition probe.hh:156
Abstract superclass for simulation objects.
STL vector class.
Definition stl.hh:37
#define GEM5_CLASS_VAR_USED
Definition compiler.hh:141
const Params & params() const
Bitfield< 5 > l
Bitfield< 63 > val
Definition misc.hh:804
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36

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