Skip to content

Commit

Permalink
Add node memory usage info to V3Stats
Browse files Browse the repository at this point in the history
  • Loading branch information
gezalore committed Nov 12, 2023
1 parent 91d0f25 commit 2472fb6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/V3Ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct VNTypeInfo {
OP_OPTIONAL,
} m_opType[4];
const char* m_opNamep[4];
size_t m_sizeof;
};

class VNType final {
Expand Down
18 changes: 15 additions & 3 deletions src/V3Stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class StatsVisitor final : public VNVisitorConst {
iterateConst(nodep);

// Shorthand
const auto addStat = [&](const std::string& name, double count) { //
V3Stats::addStat(stage, name, count);
const auto addStat = [&](const std::string& name, double count, unsigned precision = 0) {
V3Stats::addStat(stage, name, count, precision);
};

// Variable widths
Expand All @@ -124,13 +124,25 @@ class StatsVisitor final : public VNVisitorConst {
}
}

// Node types
// Node types (also total memory usage)
const auto typeName = [](int type) { return std::string{VNType{type}.ascii()}; };
const auto typeSize = [](int type) { return VNType{type}.typeInfo()->m_sizeof; };
size_t totalNodeMemoryUsage = 0;
for (int t = 0; t < VNType::_ENUM_END; ++t) {
if (const uint64_t count = m_counters.m_statTypeCount[t]) {
totalNodeMemoryUsage += count * typeSize(t);
addStat("Node count, " + typeName(t), count);
}
}
addStat("Node memory TOTAL (MiB)", totalNodeMemoryUsage >> 20);

// Node Memory usage
for (int t = 0; t < VNType::_ENUM_END; ++t) {
if (const uint64_t count = m_counters.m_statTypeCount[t]) {
const double share = 100.0 * count * typeSize(t) / totalNodeMemoryUsage;
addStat("Node memory share (%), " + typeName(t), share, 2);
}
}

// Expression combinations
for (int t1 = 0; t1 < VNType::_ENUM_END; ++t1) {
Expand Down
30 changes: 17 additions & 13 deletions src/V3Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class VDouble0 final {
class V3Statistic final {
// A statistical entry we want published into the database
const string m_name; ///< Name of this statistic
double m_count; ///< Count of occurrences/ value
double m_value; ///< Value of statistic (count, ratio, etc.)
unsigned m_precision; ///< Precision to print with (number of fractional digits)
const string m_stage; ///< Runtime stage
const bool m_sumit; ///< Do summation of similar stats
const bool m_perf; ///< Performance section
Expand All @@ -77,20 +78,22 @@ class V3Statistic final {
// METHODS
string stage() const VL_MT_SAFE { return m_stage; }
string name() const VL_MT_SAFE { return m_name; }
double count() const VL_MT_SAFE { return m_count; }
double value() const VL_MT_SAFE { return m_value; }
unsigned precision() const VL_MT_SAFE { return m_precision; }
bool sumit() const VL_MT_SAFE { return m_sumit; }
bool perf() const VL_MT_SAFE { return m_perf; }
bool printit() const VL_MT_SAFE { return m_printit; }
virtual void dump(std::ofstream& os) const VL_MT_SAFE;
void combineWith(V3Statistic* otherp) {
m_count += otherp->count();
m_value += otherp->value();
otherp->m_printit = false;
}
// CONSTRUCTORS
V3Statistic(const string& stage, const string& name, double count, bool sumit = false,
bool perf = false)
V3Statistic(const string& stage, const string& name, double value, unsigned precision,
bool sumit = false, bool perf = false)
: m_name{name}
, m_count{count}
, m_value{value}
, m_precision{precision}
, m_stage{stage}
, m_sumit{sumit}
, m_perf{perf} {}
Expand All @@ -102,17 +105,18 @@ class V3Statistic final {
class V3Stats final {
public:
static void addStat(const V3Statistic&);
static void addStat(const string& stage, const string& name, double count) {
addStat(V3Statistic{stage, name, count});
static void addStat(const string& stage, const string& name, double value,
unsigned precision = 0) {
addStat(V3Statistic{stage, name, value, precision});
}
static void addStat(const string& name, double count) {
addStat(V3Statistic{"*", name, count});
static void addStat(const string& name, double value, unsigned precision = 0) {
addStat(V3Statistic{"*", name, value, precision});
}
static void addStatSum(const string& name, double count) {
addStat(V3Statistic{"*", name, count, true});
addStat(V3Statistic{"*", name, count, 0, true});
}
static void addStatPerf(const string& name, double count) {
addStat(V3Statistic{"*", name, count, true, true});
static void addStatPerf(const string& name, double value) {
addStat(V3Statistic{"*", name, value, 6, true, true});
}
/// Called each stage
static void statsStage(const string& name);
Expand Down
7 changes: 2 additions & 5 deletions src/V3StatsReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,8 @@ StatsReport::StatColl StatsReport::s_allStats;
// V3Statstic class

void V3Statistic::dump(std::ofstream& os) const {
if (perf()) {
os << " " << std::right << std::fixed << std::setprecision(6) << std::setw(9) << count();
} else {
os << " " << std::right << std::fixed << std::setprecision(0) << std::setw(9) << count();
}
os << " " << std::right << std::fixed << std::setprecision(precision()) << std::setw(9)
<< value();
}

//######################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/astgen
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ def write_ast_type_info(filename):
['VNTypeInfo::{0}'.format(s) for s in opTypeList])
opNameStr = ', '.join(['"{0}"'.format(s) for s in opNameList])
fh.write(
' {{ "Ast{name}", {{{opTypeStr}}}, {{{opNameStr}}} }},\n'.
' {{ "Ast{name}", {{{opTypeStr}}}, {{{opNameStr}}}, sizeof(Ast{name}) }},\n'.
format(
name=node.name,
opTypeStr=opTypeStr,
Expand Down

0 comments on commit 2472fb6

Please sign in to comment.