gem5  v22.1.0.0
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__
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
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
virtual ~ProbeListenerObject()
Definition: probe.cc:64
ProbeManager * getProbeManager()
Definition: probe.hh:116
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=(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 & operator=(const ProbeListener &other)=delete
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.
Definition: sim_object.hh:148
STL vector class.
Definition: stl.hh:37
#define GEM5_CLASS_VAR_USED
Definition: compiler.hh:141
const Params & params() const
Definition: sim_object.hh:176
Bitfield< 55 > l
Definition: pagetable.hh:54
Bitfield< 63 > val
Definition: misc.hh:776
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)

Generated on Wed Dec 21 2022 10:22:40 for gem5 by doxygen 1.9.1