Skip to content

Commit

Permalink
Specialize register report in case of JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbopet committed Apr 3, 2022
1 parent 5e54a0d commit 001df5a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
7 changes: 4 additions & 3 deletions src/cli/clirunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,16 @@ int CLIRunner::postRun() {
QJsonObject jsonOutput;
for (auto &telemetry : m_options.telemetry)
if (telemetry->isEnabled())
jsonOutput.insert(telemetry->prettyKey(),
QJsonValue::fromVariant(telemetry->report()));
jsonOutput.insert(
telemetry->prettyKey(),
QJsonValue::fromVariant(telemetry->report(/*json=*/true)));
*stream << QJsonDocument(jsonOutput).toJson(QJsonDocument::Indented);
} else {
// Telemetry output
for (auto &telemetry : m_options.telemetry)
if (telemetry->isEnabled()) {
*stream << "===== " << telemetry->description() << "\n";
QVariant reportedValue = telemetry->report();
QVariant reportedValue = telemetry->report(/*json=*/false);
*stream << qVariantToString(reportedValue) << "\n";
}
}
Expand Down
45 changes: 28 additions & 17 deletions src/cli/telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class Telemetry {
Telemetry() {}
virtual ~Telemetry(){};

// Report this telemetry as a QVariant.
virtual QVariant report() = 0;
// Returns a QVariant representing representing this telemtry. If 'json' is
// set, indicates that the output is intended for JSON export.
virtual QVariant report(bool /*json*/) = 0;

// Returns the name of this telemetry.
virtual QString key() const = 0;
Expand All @@ -42,7 +43,8 @@ class CPITelemetry : public Telemetry {
QString description() const override {
return "cycles per instruction (CPI)";
}
QVariant report() override {

QVariant report(bool /*json*/) override {
const auto cycleCount = ProcessorHandler::getProcessor()->getCycleCount();
const auto instrsRetired =
ProcessorHandler::getProcessor()->getInstructionsRetired();
Expand All @@ -58,7 +60,7 @@ class IPCTelemetry : public Telemetry {
QString description() const override {
return "instructions per cycle (IPC)";
}
QVariant report() override {
QVariant report(bool /*json*/) override {
const auto cycleCount = ProcessorHandler::getProcessor()->getCycleCount();
const auto instrsRetired =
ProcessorHandler::getProcessor()->getInstructionsRetired();
Expand All @@ -72,7 +74,7 @@ class IPCTelemetry : public Telemetry {
class CyclesTelemetry : public Telemetry {
QString key() const override { return "cycles"; }
QString description() const override { return "cycles"; }
QVariant report() override {
QVariant report(bool /*json*/) override {
return ProcessorHandler::getProcessor()->getCycleCount();
}
};
Expand All @@ -81,7 +83,7 @@ class InstrsRetiredTelemetry : public Telemetry {
QString key() const override { return "iret"; }
QString prettyKey() const override { return "# instructions retired"; }
QString description() const override { return "instructions retired"; }
QVariant report() override {
QVariant report(bool /*json*/) override {
return ProcessorHandler::getProcessor()->getInstructionsRetired();
}
};
Expand All @@ -98,7 +100,7 @@ class PipelineTelemetry : public Telemetry {

QString key() const override { return "pipeline"; }
QString description() const override { return "pipeline state"; }
QVariant report() override {
QVariant report(bool /*json*/) override {
// Simply grab the current state of the pipeline diagram model and print it.
return m_pipelineDiagramModel->toString();
}
Expand All @@ -112,17 +114,26 @@ class RegisterTelemetry : public Telemetry {
QString key() const override { return "regs"; }
QString prettyKey() const override { return "registers"; }
QString description() const override { return "register values"; }
QVariant report() override {
QString v;
QTextStream out(&v);
QVariant report(bool json) override {
QVariantMap registerMap;
auto *isa = ProcessorHandler::currentISA();
for (unsigned i = 0; i < isa->regCnt(); i++) {
auto v = ProcessorHandler::getRegisterValue(RegisterFileType::GPR, i);
out << isa->regName(i) << ":\t"
<< encodeRadixValue(v, Radix::Signed, isa->bytes()) << "\t";
out << "(" << encodeRadixValue(v, Radix::Hex, isa->bytes()) << ")\n";
if (json) {
for (unsigned i = 0; i < isa->regCnt(); i++) {
registerMap[isa->regName(i)] = QVariant::fromValue(
ProcessorHandler::getRegisterValue(RegisterFileType::GPR, i));
}
return registerMap;
} else {
QString outStr;
QTextStream out(&outStr);
for (unsigned i = 0; i < isa->regCnt(); i++) {
auto v = ProcessorHandler::getRegisterValue(RegisterFileType::GPR, i);
out << isa->regName(i) << ":\t"
<< encodeRadixValue(v, Radix::Signed, isa->bytes()) << "\t";
out << "(" << encodeRadixValue(v, Radix::Hex, isa->bytes()) << ")\n";
}
return outStr;
}
return v;
}
};

Expand All @@ -138,7 +149,7 @@ class RunInfoTelemetry : public Telemetry {
return "simulation information (processor "
"configuration, input file, ...)";
}
QVariant report() override {
QVariant report(bool /*json*/) override {
QVariantMap m;
m["processor"] = enumToString<ProcessorID>(ProcessorHandler::getID());
m["ISA extensions"] = ProcessorHandler::currentISA()->enabledExtensions();
Expand Down

0 comments on commit 001df5a

Please sign in to comment.