gem5  v20.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  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
59 #ifndef __SIM_PROBE_PROBE_HH__
60 #define __SIM_PROBE_PROBE_HH__
61 
62 #include <string>
63 #include <vector>
64 
65 #include "base/compiler.hh"
66 #include "base/trace.hh"
67 #include "sim/sim_object.hh"
68 
70 class ProbeManager;
71 class ProbeListener;
72 class ProbeListenerObjectParams;
73 
82 namespace ProbePoints {
83 /* Note: This is only here for documentation purposes, new probe
84  * points should normally be declared in their own header files. See
85  * for example pmu.hh.
86  */
87 }
88 
99 {
100  protected:
103 
104  public:
105  ProbeListenerObject(const ProbeListenerObjectParams *params);
106  virtual ~ProbeListenerObject();
108 };
109 
118 {
119  public:
120  ProbeListener(ProbeManager *manager, const std::string &name);
121  virtual ~ProbeListener();
122 
123  protected:
125  const std::string name;
126 };
127 
134 {
135  protected:
136  const std::string name;
137  public:
138  ProbePoint(ProbeManager *manager, const std::string &name);
139  virtual ~ProbePoint() {}
140 
141  virtual void addListener(ProbeListener *listener) = 0;
142  virtual void removeListener(ProbeListener *listener) = 0;
143  std::string getName() const { return name; }
144 };
145 
151 {
152  private:
157 
158  public:
160  : object(obj)
161  {}
162  virtual ~ProbeManager() {}
163 
171  bool addListener(std::string pointName, ProbeListener &listener);
172 
181  bool removeListener(std::string pointName, ProbeListener &listener);
182 
187  void addPoint(ProbePoint &point);
188 };
189 
197 template <class Arg>
199 {
200  public:
201  ProbeListenerArgBase(ProbeManager *pm, const std::string &name)
202  : ProbeListener(pm, name)
203  {}
204  virtual void notify(const Arg &val) = 0;
205 };
206 
214 template <class T, class Arg>
216 {
217  private:
218  T *object;
219  void (T::* function)(const Arg &);
220 
221  public:
227  ProbeListenerArg(T *obj, const std::string &name, void (T::* func)(const Arg &))
228  : ProbeListenerArgBase<Arg>(obj->getProbeManager(), name),
229  object(obj),
230  function(func)
231  {}
232 
238  virtual void notify(const Arg &val) { (object->*function)(val); }
239 };
240 
248 template <typename Arg>
249 class ProbePointArg : public ProbePoint
250 {
253 
254  public:
255  ProbePointArg(ProbeManager *manager, std::string name)
256  : ProbePoint(manager, name)
257  {
258  }
259 
265  {
266  // check listener not already added
267  if (std::find(listeners.begin(), listeners.end(), l) == listeners.end()) {
268  listeners.push_back(static_cast<ProbeListenerArgBase<Arg> *>(l));
269  }
270  }
271 
277  {
278  listeners.erase(std::remove(listeners.begin(), listeners.end(), l),
279  listeners.end());
280  }
281 
286  void notify(const Arg &arg)
287  {
288  for (auto l = listeners.begin(); l != listeners.end(); ++l) {
289  (*l)->notify(arg);
290  }
291  }
292 };
293 #endif//__SIM_PROBE_PROBE_HH__
ProbePoint::name
const std::string name
Definition: probe.hh:136
ProbeManager::addPoint
void addPoint(ProbePoint &point)
Add a ProbePoint to this SimObject ProbeManager.
Definition: probe.cc:117
ProbePoint::getName
std::string getName() const
Definition: probe.hh:143
ProbeListener::ProbeListener
ProbeListener(ProbeManager *manager, const std::string &name)
Definition: probe.cc:65
ProbePoints
Name space containing shared probe point declarations.
Definition: mem.hh:46
ProbeManager::object
const M5_CLASS_VAR_USED SimObject * object
Required for sensible debug messages.
Definition: probe.hh:154
ProbeManager::~ProbeManager
virtual ~ProbeManager()
Definition: probe.hh:162
ProbeListenerArgBase::ProbeListenerArgBase
ProbeListenerArgBase(ProbeManager *pm, const std::string &name)
Definition: probe.hh:201
ProbeManager::removeListener
bool removeListener(std::string pointName, ProbeListener &listener)
Remove a ProbeListener from the ProbePoint named by pointName.
Definition: probe.cc:100
ProbeListenerArg::function
void(T::* function)(const Arg &)
Definition: probe.hh:219
ProbePointArg
ProbePointArg generates a point for the class of Arg.
Definition: thermal_domain.hh:50
ProbeManager::ProbeManager
ProbeManager(SimObject *obj)
Definition: probe.hh:159
std::vector< ProbeListener * >
ProbePoint::~ProbePoint
virtual ~ProbePoint()
Definition: probe.hh:139
ProbePointArg::notify
void notify(const Arg &arg)
called at the ProbePoint call site, passes arg to each listener.
Definition: probe.hh:286
ProbeListenerObject::listeners
std::vector< ProbeListener * > listeners
Definition: probe.hh:102
ProbeListenerArgBase::notify
virtual void notify(const Arg &val)=0
ProbeListener::manager
ProbeManager *const manager
Definition: probe.hh:124
ProbeListener::~ProbeListener
virtual ~ProbeListener()
Definition: probe.cc:71
ProbeListenerArg
ProbeListenerArg generates a listener for the class of Arg and the class type T which is the class co...
Definition: probe.hh:215
M5_CLASS_VAR_USED
#define M5_CLASS_VAR_USED
Definition: compiler.hh:64
ProbeListener
ProbeListener base class; here to simplify things like containers containing multiple types of ProbeL...
Definition: probe.hh:117
sim_object.hh
ProbePointArg::listeners
std::vector< ProbeListenerArgBase< Arg > * > listeners
The attached listeners.
Definition: probe.hh:252
ProbeListener::name
const std::string name
Definition: probe.hh:125
ProbeListenerObject::~ProbeListenerObject
virtual ~ProbeListenerObject()
Definition: probe.cc:57
ProbePoint::addListener
virtual void addListener(ProbeListener *listener)=0
compiler.hh
ProbePoint
ProbeListener base class; again used to simplify use of ProbePoints in containers and used as to defi...
Definition: probe.hh:133
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
ProbeListenerObject
This class is a minimal wrapper around SimObject.
Definition: probe.hh:98
ProbeListenerObject::getProbeManager
ProbeManager * getProbeManager()
Definition: probe.hh:107
ProbeManager::addListener
bool addListener(std::string pointName, ProbeListener &listener)
Add a ProbeListener to the ProbePoint named by pointName.
Definition: probe.cc:83
SimObject::params
const Params * params() const
Definition: sim_object.hh:119
name
const std::string & name()
Definition: trace.cc:50
ProbePointArg::addListener
void addListener(ProbeListener *l)
adds a ProbeListener to this ProbePoints notify list.
Definition: probe.hh:264
ProbePointArg::ProbePointArg
ProbePointArg(ProbeManager *manager, std::string name)
Definition: probe.hh:255
ProbeManager
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:150
ProbePoint::removeListener
virtual void removeListener(ProbeListener *listener)=0
ProbeListenerArg::object
T * object
Definition: probe.hh:218
ProbePoint::ProbePoint
ProbePoint(ProbeManager *manager, const std::string &name)
Definition: probe.cc:43
ProbeListenerObject::ProbeListenerObject
ProbeListenerObject(const ProbeListenerObjectParams *params)
Definition: probe.cc:51
ProbeListenerArg::notify
virtual void notify(const Arg &val)
called when the ProbePoint calls notify.
Definition: probe.hh:238
ProbeManager::points
std::vector< ProbePoint * > points
Vector for name look-up.
Definition: probe.hh:156
ProbeListenerObject::manager
ProbeManager * manager
Definition: probe.hh:101
trace.hh
ProbePointArg::removeListener
void removeListener(ProbeListener *l)
remove a ProbeListener from this ProbePoints notify list.
Definition: probe.hh:276
MipsISA::l
Bitfield< 5 > l
Definition: pra_constants.hh:320
ProbeListenerArg::ProbeListenerArg
ProbeListenerArg(T *obj, const std::string &name, void(T::*func)(const Arg &))
Definition: probe.hh:227
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92
ProbeListenerArgBase
ProbeListenerArgBase is used to define the base interface to a ProbeListenerArg (i....
Definition: probe.hh:198

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17