gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
probe.cc
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
41#include "sim/probe/probe.hh"
42
43#include "debug/ProbeVerbose.hh"
44
45namespace gem5
46{
47
48ProbePoint::ProbePoint(ProbeManager *manager, const std::string& _name)
49 : name(_name)
50{
51 if (manager) {
52 manager->addPoint(*this);
53 }
54}
55
56bool
57ProbeManager::addListener(std::string_view point_name, ProbeListener &listener)
58{
59 DPRINTFR(ProbeVerbose, "Probes: Call to addListener to \"%s\" on %s.\n",
60 point_name, name());
61 bool added = false;
62 for (auto p = points.begin(); p != points.end(); ++p) {
63 if ((*p)->getName() == point_name) {
64 (*p)->addListener(&listener);
65 added = true;
66 }
67 }
68 if (!added) {
69 DPRINTFR(ProbeVerbose, "Probes: Call to addListener to \"%s\" on "
70 "%s failed, no such point.\n", point_name, name());
71 }
72 return added;
73}
74
75bool
76ProbeManager::removeListener(std::string_view point_name,
77 ProbeListener &listener)
78{
79 DPRINTFR(ProbeVerbose, "Probes: Call to removeListener from \"%s\" on "
80 "%s.\n", point_name, name());
81 bool removed = false;
82 for (auto p = points.begin(); p != points.end(); ++p) {
83 if ((*p)->getName() == point_name) {
84 (*p)->removeListener(&listener);
85 removed = true;
86 }
87 }
88 if (!removed) {
89 DPRINTFR(ProbeVerbose, "Probes: Call to removeListener from \"%s\" "
90 "on %s failed, no such point.\n", point_name, name());
91 }
92 return removed;
93}
94
95void
97{
98 DPRINTFR(ProbeVerbose, "Probes: Call to addPoint \"%s\" to %s.\n",
99 point.getName(), name());
100
101 if (getFirstProbePoint(point.getName())) {
102 DPRINTFR(ProbeVerbose, "Probes: Call to addPoint \"%s\" to %s "
103 "failed, already added.\n", point.getName(), name());
104 return;
105 }
106 points.push_back(&point);
107}
108
110ProbeManager::getFirstProbePoint(std::string_view point_name) const
111{
112 for (auto p : points) {
113 if (p->getName() == point_name) {
114 return p;
115 }
116 }
117 return nullptr;
118}
119
120} // namespace gem5
#define DPRINTFR(x,...)
Definition trace.hh:223
virtual std::string name() const
Definition named.hh:60
ProbeListener base class; here to simplify things like containers containing multiple types of ProbeL...
Definition probe.hh:102
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition probe.hh:162
bool addListener(std::string_view point_name, ProbeListener &listener)
Add a ProbeListener to the ProbePoint named by pointName.
Definition probe.cc:57
void addPoint(ProbePoint &point)
Add a ProbePoint to this SimObject ProbeManager.
Definition probe.cc:96
bool removeListener(std::string_view point_name, ProbeListener &listener)
Remove a ProbeListener from the ProbePoint named by pointName.
Definition probe.cc:76
std::vector< ProbePoint * > points
Vector for name look-up.
Definition probe.hh:165
ProbePoint * getFirstProbePoint(std::string_view point_name) const
Definition probe.cc:110
ProbePoint base class; again used to simplify use of ProbePoints in containers and used as to define ...
Definition probe.hh:123
const std::string name
Definition probe.hh:125
const std::string & getName() const
Definition probe.hh:132
ProbePoint(ProbeManager *manager, const std::string &name)
Definition probe.cc:48
Bitfield< 0 > p
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36

Generated on Mon May 26 2025 09:19:13 for gem5 by doxygen 1.13.2