gem5  v21.1.0.2
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 GEM5_DEPRECATED_NAMESPACE(ProbePoints, probing);
90 namespace 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 
210 template <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 
227 template <class T, class Arg>
229 {
230  private:
231  T *object;
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 
262 template <typename Arg>
263 class ProbePointArg : public ProbePoint
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 } // namespace gem5
322 
323 #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:313
gem5::ProbeManager::ProbeManager
ProbeManager(SimObject *obj)
Definition: probe.hh:172
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
gem5::ProbeListenerArgBase::ProbeListenerArgBase
ProbeListenerArgBase(ProbeManager *pm, const std::string &name)
Definition: probe.hh:214
gem5::ProbePoint::addListener
virtual void addListener(ProbeListener *listener)=0
gem5::ProbeListenerArg::function
void(T::* function)(const Arg &)
Definition: probe.hh:232
gem5::ProbeListener::manager
ProbeManager *const manager
Definition: probe.hh:137
gem5::ProbeListenerObject::manager
ProbeManager * manager
Definition: probe.hh:110
gem5::ProbeListenerArg::object
T * object
Definition: probe.hh:231
gem5::ProbeListenerObject::listeners
std::vector< ProbeListener * > listeners
Definition: probe.hh:111
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:775
gem5::ProbeListenerArg::notify
void notify(const Arg &val) override
called when the ProbePoint calls notify.
Definition: probe.hh:252
gem5::ProbePoint::name
const std::string name
Definition: probe.hh:149
std::vector
STL vector class.
Definition: stl.hh:37
gem5::ProbeListenerObject
This class is a minimal wrapper around SimObject.
Definition: probe.hh:107
gem5::ProbeListenerArg
ProbeListenerArg generates a listener for the class of Arg and the class type T which is the class co...
Definition: probe.hh:228
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:189
gem5::ProbePointArg::removeListener
void removeListener(ProbeListener *l) override
remove a ProbeListener from this ProbePoints notify list.
Definition: probe.hh:302
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::ProbePointArg::addListener
void addListener(ProbeListener *l) override
adds a ProbeListener to this ProbePoints notify list.
Definition: probe.hh:288
gem5::ProbeListenerObject::getProbeManager
ProbeManager * getProbeManager()
Definition: probe.hh:116
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:266
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::ProbeListenerArg::ProbeListenerArg
ProbeListenerArg(T *obj, const std::string &name, void(T::*func)(const Arg &))
Definition: probe.hh:240
compiler.hh
gem5::ProbePoint::removeListener
virtual void removeListener(ProbeListener *listener)=0
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
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::ProbePointArg::ProbePointArg
ProbePointArg(ProbeManager *manager, std::string name)
Definition: probe.hh:269
gem5::ProbeManager::~ProbeManager
virtual ~ProbeManager()
Definition: probe.hh:175
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:281
gem5::ProbeListenerArgBase
ProbeListenerArgBase is used to define the base interface to a ProbeListenerArg (i....
Definition: probe.hh:211
gem5::ProbePoint::ProbePoint
ProbePoint(ProbeManager *manager, const std::string &name)
Definition: probe.cc:49
gem5::ProbePoint::~ProbePoint
virtual ~ProbePoint()
Definition: probe.hh:152
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
trace.hh
gem5::ProbeManager::object
const GEM5_CLASS_VAR_USED SimObject * object
Required for sensible debug messages.
Definition: probe.hh:167
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
gem5::ProbeListener::operator=
ProbeListener & operator=(const ProbeListener &other)=delete

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