gem5  v20.1.0.0
group.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, 2020 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 
38 #include "base/stats/group.hh"
39 
40 #include <cassert>
41 
42 #include "base/stats/info.hh"
43 #include "base/trace.hh"
44 #include "debug/Stats.hh"
45 #include "sim/sim_object.hh"
46 
47 namespace Stats {
48 
49 Group::Group(Group *parent, const char *name)
50  : mergedParent(name ? nullptr : parent)
51 {
52  if (parent && name) {
53  parent->addStatGroup(name, this);
54  } else if (parent && !name) {
55  parent->mergeStatGroup(this);
56  }
57 }
58 
60 {
61 }
62 
63 void
65 {
66  for (auto &g : mergedStatGroups)
67  g->regStats();
68 
69  for (auto &g : statGroups) {
70  if (DTRACE(Stats)) {
71  const SimObject M5_VAR_USED *so =
72  dynamic_cast<const SimObject *>(this);
73  DPRINTF(Stats, "%s: regStats in group %s\n",
74  so ? so->name() : "?",
75  g.first);
76  }
77  g.second->regStats();
78  }
79 }
80 
81 void
83 {
84  for (auto &s : stats)
85  s->reset();
86 
87  for (auto &g : mergedStatGroups)
88  g->resetStats();
89 
90  for (auto &g : statGroups)
91  g.second->resetStats();
92 }
93 
94 void
96 {
97  for (auto &g : mergedStatGroups)
98  g->preDumpStats();
99 
100  for (auto &g : statGroups)
101  g.second->preDumpStats();
102 }
103 
104 void
106 {
107  stats.push_back(info);
108  if (mergedParent)
109  mergedParent->addStat(info);
110 }
111 
112 void
113 Group::addStatGroup(const char *name, Group *block)
114 {
115  assert(statGroups.find(name) == statGroups.end());
116 
117  statGroups[name] = block;
118 }
119 
120 const Info *
121 Group::resolveStat(std::string name) const
122 {
123  auto pos = name.find(".");
124  if (pos == std::string::npos) {
125  // look for the stat in this group
126  for (auto &info : stats) {
127  if (info->name == name) {
128  return info;
129  }
130  }
131  } else {
132  // look for the stat in subgroups
133  const std::string gname = name.substr(0, pos);
134  for (auto &g : statGroups) {
135  if (g.first == gname) {
136  return g.second->resolveStat(name.substr(pos + 1));
137  }
138  }
139  }
140 
141  // finally look for the stat in groups that have been merged
142  for (auto &g : mergedStatGroups) {
143  auto info = g->resolveStat(name);
144  if (info) {
145  return info;
146  }
147  }
148 
149  return nullptr;
150 }
151 
152 void
154 {
155  mergedStatGroups.push_back(block);
156 }
157 
158 const std::map<std::string, Group *> &
160 {
161  return statGroups;
162 }
163 
164 const std::vector<Info *> &
166 {
167  return stats;
168 }
169 
170 } // namespace Stats
Stats::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:64
group.hh
Stats::Group::mergedParent
Group *const mergedParent
Parent pointer if merged into parent.
Definition: group.hh:208
Stats::Group::getStatGroups
const std::map< std::string, Group * > & getStatGroups() const
Get all child groups associated with this object.
Definition: group.cc:159
PowerISA::so
Bitfield< 28 > so
Definition: miscregs.hh:49
Stats::Group::Group
Group()=delete
DTRACE
#define DTRACE(x)
Definition: debug.hh:146
Stats::Group::preDumpStats
virtual void preDumpStats()
Callback before stats are dumped.
Definition: group.cc:95
std::vector
STL vector class.
Definition: stl.hh:37
Stats::Group::mergedStatGroups
std::vector< Group * > mergedStatGroups
Definition: group.hh:211
Stats::Group::resetStats
virtual void resetStats()
Callback to reset stats.
Definition: group.cc:82
info.hh
sim_object.hh
Stats::Group::resolveStat
const Info * resolveStat(std::string name) const
Resolve a stat by its name within this group.
Definition: group.cc:121
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
MipsISA::g
Bitfield< 4 > g
Definition: dt_constants.hh:83
Stats::Group::stats
std::vector< Info * > stats
Definition: group.hh:212
name
const std::string & name()
Definition: trace.cc:50
Stats::Group::statGroups
std::map< std::string, Group * > statGroups
Definition: group.hh:210
Stats::Info
Definition: info.hh:69
Stats::Group::~Group
virtual ~Group()
Definition: group.cc:59
Stats::Group::mergeStatGroup
void mergeStatGroup(Group *block)
Merge the contents (stats & children) of a block to this block.
Definition: group.cc:153
Stats::Group::getStats
const std::vector< Info * > & getStats() const
Get all stats associated with this object.
Definition: group.cc:165
Stats::Group
Statistics container.
Definition: group.hh:83
Stats
Definition: statistics.cc:61
Stats::Group::addStat
void addStat(Stats::Info *info)
Register a stat with this group.
Definition: group.cc:105
trace.hh
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
Stats::Group::addStatGroup
void addStatGroup(const char *name, Group *block)
Add a stat block as a child of this block.
Definition: group.cc:113
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

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