Gabe Black has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/30960 )
Change subject: cpu: Slightly modernize and simplify code in
cpu/profile.(hh|cc).
......................................................................
cpu: Slightly modernize and simplify code in cpu/profile.(hh|cc).
Change-Id: Ideb104d20b333305ead2356cbfff2aac2e0173b5
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/30960
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
Reviewed-by: Andreas Sandberg <[email protected]>
---
M src/cpu/o3/thread_state.hh
M src/cpu/profile.cc
M src/cpu/profile.hh
M src/cpu/simple_thread.cc
4 files changed, 42 insertions(+), 54 deletions(-)
Approvals:
Andreas Sandberg: Looks good to me, approved
Gabe Black: Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/cpu/o3/thread_state.hh b/src/cpu/o3/thread_state.hh
index 76e2011..833b2b8 100644
--- a/src/cpu/o3/thread_state.hh
+++ b/src/cpu/o3/thread_state.hh
@@ -154,7 +154,7 @@
{
OutputStream *os(
simout.create(csprintf("profile.%s.dat", cpu->name())));
- profile->dump(tc, *os->stream());
+ profile->dump(*os->stream());
simout.close(os);
}
};
diff --git a/src/cpu/profile.cc b/src/cpu/profile.cc
index d1826e4..972346e 100644
--- a/src/cpu/profile.cc
+++ b/src/cpu/profile.cc
@@ -30,49 +30,39 @@
#include <string>
-#include "base/bitfield.hh"
#include "base/callback.hh"
#include "base/loader/symtab.hh"
#include "base/statistics.hh"
#include "base/trace.hh"
-#include "cpu/base.hh"
#include "cpu/thread_context.hh"
-using namespace std;
-
-ProfileNode::ProfileNode()
- : count(0)
-{ }
-
void
-ProfileNode::dump(const string &symbol, uint64_t id,
- const Loader::SymbolTable &symtab, ostream &os) const
+ProfileNode::dump(const std::string &symbol, uint64_t id,
+ const Loader::SymbolTable &symtab, std::ostream &os)
const
{
ccprintf(os, "%#x %s %d ", id, symbol, count);
- ChildList::const_iterator i, end = children.end();
- for (i = children.begin(); i != end; ++i) {
- const ProfileNode *node = i->second;
- ccprintf(os, "%#x ", (intptr_t)node);
- }
+ for (const auto &p: children)
+ ccprintf(os, "%#x ", (intptr_t)(p.second));
ccprintf(os, "\n");
- Loader::SymbolTable::const_iterator it;
- for (i = children.begin(); i != end; ++i) {
- Addr addr = i->first;
- string symbol;
- if (addr == 1)
+ for (const auto &p: children) {
+ Addr addr = p.first;
+ std::string symbol;
+ if (addr == 1) {
symbol = "user";
- else if (addr == 2)
+ } else if (addr == 2) {
symbol = "console";
- else if (addr == 3)
+ } else if (addr == 3) {
symbol = "unknown";
- else if ((it = symtab.find(addr)) != symtab.end())
+ } else {
+ const auto it = symtab.find(addr);
+ panic_if(it == symtab.end(),
+ "Could not find symbol for address %#x\n", addr);
symbol = it->name;
- else
- panic("could not find symbol for address %#x\n", addr);
+ }
- const ProfileNode *node = i->second;
+ const auto *node = p.second;
node->dump(symbol, (intptr_t)node, symtab, os);
}
}
@@ -81,13 +71,12 @@
ProfileNode::clear()
{
count = 0;
- ChildList::iterator i, end = children.end();
- for (i = children.begin(); i != end; ++i)
- i->second->clear();
+ for (const auto &p: children)
+ p.second->clear();
}
-FunctionProfile::FunctionProfile(const Loader::SymbolTable &_symtab)
- : reset(0), symtab(_symtab)
+FunctionProfile::FunctionProfile(const Loader::SymbolTable &_symtab) :
+ symtab(_symtab)
{
reset = new MakeCallback<FunctionProfile,
&FunctionProfile::clear>(this);
Stats::registerResetCallback(reset);
@@ -95,17 +84,16 @@
FunctionProfile::~FunctionProfile()
{
- if (reset)
- delete reset;
+ delete reset;
}
ProfileNode *
-FunctionProfile::consume(const vector<Addr> &stack)
+FunctionProfile::consume(const std::vector<Addr> &stack)
{
ProfileNode *current = ⊤
for (int i = 0, size = stack.size(); i < size; ++i) {
ProfileNode *&ptr = current->children[stack[size - i - 1]];
- if (ptr == NULL)
+ if (!ptr)
ptr = new ProfileNode;
current = ptr;
@@ -122,23 +110,25 @@
}
void
-FunctionProfile::dump(ThreadContext *tc, ostream &os) const
+FunctionProfile::dump(std::ostream &os) const
{
ccprintf(os, ">>>PC data\n");
- map<Addr, Counter>::const_iterator i, end = pc_count.end();
- for (i = pc_count.begin(); i != end; ++i) {
- Addr pc = i->first;
- Counter count = i->second;
+ for (const auto &p: pc_count) {
+ Addr pc = p.first;
+ Counter count = p.second;
- Loader::SymbolTable::const_iterator it;
if (pc == 1) {
ccprintf(os, "user %d\n", count);
- } else if ((it = symtab.find(pc)) != symtab.end() &&
- !it->name.empty()) {
- ccprintf(os, "%s %d\n", it->name, count);
- } else {
- ccprintf(os, "%#x %d\n", pc, count);
+ continue;
}
+
+ const auto it = symtab.find(pc);
+ if (it != symtab.end() && !it->name.empty()) {
+ ccprintf(os, "%s %d\n", it->name, count);
+ continue;
+ }
+
+ ccprintf(os, "%#x %d\n", pc, count);
}
ccprintf(os, ">>>function data\n");
diff --git a/src/cpu/profile.hh b/src/cpu/profile.hh
index 96d5526..f6b98d3 100644
--- a/src/cpu/profile.hh
+++ b/src/cpu/profile.hh
@@ -47,11 +47,9 @@
ChildList children;
public:
- Counter count;
+ Counter count = 0;
public:
- ProfileNode();
-
void dump(const std::string &symbol, uint64_t id,
const Loader::SymbolTable &symtab, std::ostream &os) const;
void clear();
@@ -61,7 +59,7 @@
class FunctionProfile
{
private:
- Callback *reset;
+ Callback *reset = nullptr;
const Loader::SymbolTable &symtab;
ProfileNode top;
std::map<Addr, Counter> pc_count;
@@ -74,7 +72,7 @@
ProfileNode *consume(ThreadContext *tc, const StaticInstPtr &inst);
ProfileNode *consume(const std::vector<Addr> &stack);
void clear();
- void dump(ThreadContext *tc, std::ostream &out) const;
+ void dump(std::ostream &out) const;
void sample(ProfileNode *node, Addr pc);
};
@@ -82,7 +80,7 @@
FunctionProfile::consume(ThreadContext *tc, const StaticInstPtr &inst)
{
if (!trace.trace(tc, inst))
- return NULL;
+ return nullptr;
trace.dprintf();
return consume(trace.getstack());
}
diff --git a/src/cpu/simple_thread.cc b/src/cpu/simple_thread.cc
index 8f2ab54..c30872c 100644
--- a/src/cpu/simple_thread.cc
+++ b/src/cpu/simple_thread.cc
@@ -150,7 +150,7 @@
SimpleThread::dumpFuncProfile()
{
OutputStream *os(simout.create(csprintf("profile.%s.dat",
baseCpu->name())));
- profile->dump(this, *os->stream());
+ profile->dump(*os->stream());
simout.close(os);
}
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/30960
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ideb104d20b333305ead2356cbfff2aac2e0173b5
Gerrit-Change-Number: 30960
Gerrit-PatchSet: 3
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Bradford Beckmann <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Hoa Nguyen <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-CC: Jason Lowe-Power <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s