Skip to content

Commit 201dab6

Browse files
committed
pcm-power: refactor (III)
Change-Id: I06c8085b4ce0f59fd9ee4d24392a7a912c86639b
1 parent 3a61c13 commit 201dab6

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

src/pcm-power.cpp

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,46 @@ void print_usage(const string & progname)
374374

375375
struct Metric
376376
{
377-
typedef std::variant<double, uint64, int64, int32> ValueType;
377+
typedef std::variant<double, uint64, int64, int32, bool> ValueType;
378378
std::string name{};
379379
ValueType value{};
380380
std::string unit{};
381381
Metric(const std::string & n, const ValueType & v, const std::string & u) : name(n), value(v), unit(u) {}
382382
Metric() = default;
383383
};
384384

385-
void printMetrics(const std::string & header, const std::vector<Metric> & metrics)
385+
void printMetrics(const std::string & header, const std::vector<Metric> & metrics, const bool skipZeroValues = false)
386386
{
387387
cout << header << "; ";
388388
for (const auto & metric : metrics)
389389
{
390+
if (skipZeroValues)
391+
{
392+
if (std::holds_alternative<uint64>(metric.value) && std::get<uint64>(metric.value) == 0)
393+
{
394+
continue;
395+
}
396+
if (std::holds_alternative<double>(metric.value) && std::get<double>(metric.value) == 0.0)
397+
{
398+
continue;
399+
}
400+
if (std::holds_alternative<int64>(metric.value) && std::get<int64>(metric.value) == 0)
401+
{
402+
continue;
403+
}
404+
if (std::holds_alternative<int32>(metric.value) && std::get<int32>(metric.value) == 0)
405+
{
406+
continue;
407+
}
408+
}
409+
if (std::holds_alternative<bool>(metric.value))
410+
{
411+
if (std::get<bool>(metric.value))
412+
{
413+
cout << metric.name << ";";
414+
}
415+
continue;
416+
}
390417
cout << metric.name << ": ";
391418
if (std::holds_alternative<uint64>(metric.value))
392419
{
@@ -417,14 +444,14 @@ void printMetrics(const std::string & header, const std::vector<Metric> & metric
417444
cout << "\n";
418445
}
419446

420-
void printMetrics(const std::string & header, const std::initializer_list<Metric> & metrics)
447+
void printMetrics(const std::string & header, const std::initializer_list<Metric> & metrics, const bool skipZeroValues = false)
421448
{
422449
std::vector<Metric> metricsVec;
423450
for (const auto & metric : metrics)
424451
{
425452
metricsVec.push_back(metric);
426453
}
427-
printMetrics(header, metricsVec);
454+
printMetrics(header, metricsVec, skipZeroValues);
428455
}
429456

430457
PCM_MAIN_NOTHROW;
@@ -737,7 +764,7 @@ int mainThrows(int argc, char * argv[])
737764
case 0:
738765
if (cpu_family_model == PCM::HASWELLX || cpu_family_model == PCM::BDX_DE || cpu_family_model == PCM::SKX)
739766
break;
740-
767+
741768
printMetrics(getHeader(),
742769
{
743770
Metric("PCUClocks", getPCUClocks(u, BeforeState[socket], AfterState[socket]), ""),
@@ -886,13 +913,13 @@ int mainThrows(int argc, char * argv[])
886913
{
887914
for (auto die = 0ULL; die < PERF_LIMIT_REASON_TPMI_dies_data[instance].size(); ++die)
888915
{
889-
cout << "S" << instance << "D" << die << "; PERF LIMIT REASONS (DIE LEVEL): ";
916+
std::vector<Metric> metrics;
890917
const auto data = PERF_LIMIT_REASON_TPMI_dies_data[instance][die];
891918
for (auto l = 0; l < PERF_LIMIT_REASON_TPMI::Coarse_Grained_PLR_Bit_Definition::MAX; ++l)
892919
{
893-
if (extract_bits(data, l, l)) cout << PERF_LIMIT_REASON_TPMI::Coarse_Grained_PLR_Bit_Definition_Strings[l] << "; ";
920+
metrics.push_back(Metric(PERF_LIMIT_REASON_TPMI::Coarse_Grained_PLR_Bit_Definition_Strings[l], extract_bits(data, l, l) ? true : false, ""));
894921
}
895-
cout << "\n";
922+
printMetrics("S" + std::to_string(instance) + "D" + std::to_string(die) + " PERF LIMIT REASONS (DIE LEVEL)", metrics);
896923
}
897924
}
898925
for (auto instance = 0ULL; instance < PERF_LIMIT_REASON_TPMI_modules_data.size(); ++instance)
@@ -923,20 +950,17 @@ int mainThrows(int argc, char * argv[])
923950
}
924951
for (auto die = 0ULL; die < coarseGrainedData.size(); ++die)
925952
{
926-
cout << "S" << instance << "D" << die << "; PERF LIMIT REASONS (#CORE MODULES): ";
953+
std::vector<Metric> metrics;
927954
for (auto l = 0; l < PERF_LIMIT_REASON_TPMI::Coarse_Grained_PLR_Bit_Definition::MAX; ++l)
928955
{
929-
if (coarseGrainedData[die][l]) cout << PERF_LIMIT_REASON_TPMI::Coarse_Grained_PLR_Bit_Definition_Strings[l] << ": " << coarseGrainedData[die][l] << "; ";
956+
metrics.push_back(Metric(PERF_LIMIT_REASON_TPMI::Coarse_Grained_PLR_Bit_Definition_Strings[l], coarseGrainedData[die][l], ""));
930957
}
931958
for (auto l = 0; l < PERF_LIMIT_REASON_TPMI::Fine_Grained_PLR_Bit_Definition::MAX_FINE; ++l)
932959
{
933-
if (fineGrainedData[die][l])
934-
{
935-
cout << PERF_LIMIT_REASON_TPMI::Coarse_Grained_PLR_Bit_Definition_Strings[PERF_LIMIT_REASON_TPMI::Fine_Grained_PLR_Bit_Definition_Data[l].coarse_grained_mapping]
936-
<< "." << PERF_LIMIT_REASON_TPMI::Fine_Grained_PLR_Bit_Definition_Data[l].name << ": " << fineGrainedData[die][l] << "; ";
937-
}
960+
metrics.push_back(Metric(std::string(PERF_LIMIT_REASON_TPMI::Coarse_Grained_PLR_Bit_Definition_Strings[PERF_LIMIT_REASON_TPMI::Fine_Grained_PLR_Bit_Definition_Data[l].coarse_grained_mapping]) + "." +
961+
PERF_LIMIT_REASON_TPMI::Fine_Grained_PLR_Bit_Definition_Data[l].name, fineGrainedData[die][l], ""));
938962
}
939-
cout << "\n";
963+
printMetrics("S" + std::to_string(instance) + "D" + std::to_string(die) + " PERF LIMIT REASONS (#CORE MODULES)", metrics, true);
940964
}
941965
}
942966
};

0 commit comments

Comments
 (0)