gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
probe.hh
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 
63 #ifndef __SIM_PROBE_PROBE_HH__
64 #define __SIM_PROBE_PROBE_HH__
65 
66 #include <string>
67 #include <vector>
68 
69 #include "base/compiler.hh"
70 #include "base/trace.hh"
71 #include "sim/sim_object.hh"
72 
73 namespace gem5
74 {
75 
77 class ProbeManager;
78 class ProbeListener;
79 struct ProbeListenerObjectParams;
80 
89 namespace probing
90 {
91 /* Note: This is only here for documentation purposes, new probe
92  * points should normally be declared in their own header files. See
93  * for example pmu.hh.
94  */
95 }
96 
107 {
108  protected:
111 
112  public:
113  ProbeListenerObject(const ProbeListenerObjectParams &params);
114  virtual ~ProbeListenerObject();
116 };
117 
126 {
127  public:
128  ProbeListener(ProbeManager *manager, const std::string &name);
129  virtual ~ProbeListener();
130  ProbeListener(const ProbeListener& other) = delete;
131  ProbeListener& operator=(const ProbeListener& other) = delete;
132  ProbeListener(ProbeListener&& other) noexcept = delete;
133  ProbeListener& operator=(ProbeListener&& other) noexcept = delete;
134 
135  protected:
137  const std::string name;
138 };
139 
146 {
147  protected:
148  const std::string name;
149  public:
150  ProbePoint(ProbeManager *manager, const std::string &name);
151  virtual ~ProbePoint() {}
152 
153  virtual void addListener(ProbeListener *listener) = 0;
154  virtual void removeListener(ProbeListener *listener) = 0;
155  std::string getName() const { return name; }
156 };
157 
163 {
164  private:
169 
170  public:
172  : object(obj)
173  {}
174  virtual ~ProbeManager() {}
175 
183  bool addListener(std::string point_name, ProbeListener &listener);
184 
193  bool removeListener(std::string point_name, ProbeListener &listener);
194 
199  void addPoint(ProbePoint &point);
200 };
201 
209 template <class Arg>
211 {
212  public:
213  ProbeListenerArgBase(ProbeManager *pm, const std::string &name)
214  : ProbeListener(pm, name)
215  {}
216  virtual void notify(const Arg &val) = 0;
217 };
218 
226 template <class T, class Arg>
228 {
229  private:
230  T *object;
231  void (T::* function)(const Arg &);
232 
233  public:
239  ProbeListenerArg(T *obj, const std::string &name,
240  void (T::* func)(const Arg &))
241  : ProbeListenerArgBase<Arg>(obj->getProbeManager(), name),
242  object(obj),
243  function(func)
244  {}
245 
251  void notify(const Arg &val) override { (object->*function)(val); }
252 };
253 
261 template <typename Arg>
262 class ProbePointArg : public ProbePoint
263 {
266 
267  public:
268  ProbePointArg(ProbeManager *manager, std::string name)
269  : ProbePoint(manager, name)
270  {
271  }
272 
280  bool hasListeners() const { return listeners.size() > 0; }
281 
286  void
288  {
289  // check listener not already added
290  if (std::find(listeners.begin(), listeners.end(), l) ==
291  listeners.end()) {
292  listeners.push_back(static_cast<ProbeListenerArgBase<Arg> *>(l));
293  }
294  }
295 
300  void
302  {
303  listeners.erase(std::remove(listeners.begin(), listeners.end(), l),
304  listeners.end());
305  }
306 
311  void
312  notify(const Arg &arg)
313  {
314  for (auto l = listeners.begin(); l != listeners.end(); ++l) {
315  (*l)->notify(arg);
316  }
317  }
318 };
319 
320 } // namespace gem5
321 
322 #endif//__SIM_PROBE_PROBE_HH__
gem5::ProbeListener::ProbeListener
ProbeListener(ProbeManager *manager, const std::string &name)
Definition: probe.cc:72
gem5::ProbeListener::~ProbeListener
virtual ~ProbeListener()
Definition: probe.cc:78
gem5::ProbePointArg::notify
void notify(const Arg &arg)
called at the ProbePoint call site, passes arg to each listener.
Definition: probe.hh:312
gem5::ProbeManager::ProbeManager
ProbeManager(SimObject *obj)
Definition: probe.hh:171
gem5::ProbePoint::getName
std::string getName() const
Definition: probe.hh:155
gem5::ProbeManager::addListener
bool addListener(std::string point_name, ProbeListener &listener)
Add a ProbeListener to the ProbePoint named by pointName.
Definition: probe.cc:84
gem5::ProbeListenerArgBase::ProbeListenerArgBase
ProbeListenerArgBase(ProbeManager *pm, const std::string &name)
Definition: probe.hh:213
gem5::ProbePoint::addListener
virtual void addListener(ProbeListener *listener)=0
gem5::ProbeListenerArg::function
void(T::* function)(const Arg &)
Definition: probe.hh:231
gem5::ProbeListener::manager
ProbeManager *const manager
Definition: probe.hh:136
gem5::ProbeListenerObject::manager
ProbeManager * manager
Definition: probe.hh:109
gem5::ProbeListenerArg::object
T * object
Definition: probe.hh:230
gem5::ProbeListenerObject::listeners
std::vector< ProbeListener * > listeners
Definition: probe.hh:110
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:776
gem5::ProbeListenerArg::notify
void notify(const Arg &val) override
called when the ProbePoint calls notify.
Definition: probe.hh:251
gem5::ProbePoint::name
const std::string name
Definition: probe.hh:148
std::vector
STL vector class.
Definition: stl.hh:37
gem5::ProbeListenerObject
This class is a minimal wrapper around SimObject.
Definition: probe.hh:106
gem5::ProbeListenerArg
ProbeListenerArg generates a listener for the class of Arg and the class type T which is the class co...
Definition: probe.hh:227
gem5::ProbeListenerObject::ProbeListenerObject
ProbeListenerObject(const ProbeListenerObjectParams &params)
Definition: probe.cc:57
gem5::ProbeListenerArgBase::notify
virtual void notify(const Arg &val)=0
GEM5_CLASS_VAR_USED
#define GEM5_CLASS_VAR_USED
Definition: compiler.hh:141
gem5::ProbePointArg::removeListener
void removeListener(ProbeListener *l) override
remove a ProbeListener from this ProbePoints notify list.
Definition: probe.hh:301
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:125
gem5::ProbePointArg::addListener
void addListener(ProbeListener *l) override
adds a ProbeListener to this ProbePoints notify list.
Definition: probe.hh:287
gem5::ProbeListenerObject::getProbeManager
ProbeManager * getProbeManager()
Definition: probe.hh:115
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
sim_object.hh
gem5::ProbePointArg::listeners
std::vector< ProbeListenerArgBase< Arg > * > listeners
The attached listeners.
Definition: probe.hh:265
gem5::ProbeManager::points
std::vector< ProbePoint * > points
Vector for name look-up.
Definition: probe.hh:168
gem5::ProbeListenerArg::ProbeListenerArg
ProbeListenerArg(T *obj, const std::string &name, void(T::*func)(const Arg &))
Definition: probe.hh:239
compiler.hh
gem5::ProbePoint::removeListener
virtual void removeListener(ProbeListener *listener)=0
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
name
const std::string & name()
Definition: trace.cc:48
gem5::ProbeManager
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:162
gem5::ProbePointArg::ProbePointArg
ProbePointArg(ProbeManager *manager, std::string name)
Definition: probe.hh:268
gem5::ProbeManager::~ProbeManager
virtual ~ProbeManager()
Definition: probe.hh:174
gem5::ProbeListenerObject::~ProbeListenerObject
virtual ~ProbeListenerObject()
Definition: probe.cc:64
gem5::ProbePointArg::hasListeners
bool hasListeners() const
Informs whether any listeners are attached to this probe.
Definition: probe.hh:280
gem5::ProbeListenerArgBase
ProbeListenerArgBase is used to define the base interface to a ProbeListenerArg (i....
Definition: probe.hh:210
gem5::ProbePoint::ProbePoint
ProbePoint(ProbeManager *manager, const std::string &name)
Definition: probe.cc:49
gem5::VegaISA::l
Bitfield< 55 > l
Definition: pagetable.hh:54
gem5::ProbePoint::~ProbePoint
virtual ~ProbePoint()
Definition: probe.hh:151
gem5::ProbeListener::name
const std::string name
Definition: probe.hh:137
gem5::ProbePoint
ProbeListener base class; again used to simplify use of ProbePoints in containers and used as to defi...
Definition: probe.hh:145
trace.hh
gem5::ProbeManager::object
const GEM5_CLASS_VAR_USED SimObject * object
Required for sensible debug messages.
Definition: probe.hh:166
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::ProbeManager::removeListener
bool removeListener(std::string point_name, ProbeListener &listener)
Remove a ProbeListener from the ProbePoint named by pointName.
Definition: probe.cc:103
gem5::ProbeListener::operator=
ProbeListener & operator=(const ProbeListener &other)=delete

Generated on Sun Jul 30 2023 01:56:59 for gem5 by doxygen 1.8.17