summaryrefslogtreecommitdiff
path: root/source/profiler/Profiler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'source/profiler/Profiler.cc')
-rw-r--r--source/profiler/Profiler.cc172
1 files changed, 41 insertions, 131 deletions
diff --git a/source/profiler/Profiler.cc b/source/profiler/Profiler.cc
index efbc64d..7e10097 100644
--- a/source/profiler/Profiler.cc
+++ b/source/profiler/Profiler.cc
@@ -40,7 +40,7 @@ namespace app {
}
if (this->m_pPlatform && !this->m_started) {
this->m_pPlatform->timer->reset();
- this->m_tstampSt = this->m_pPlatform->timer->start_profiling();
+ this->m_tstampSt = this->m_pPlatform->timer->get_counters();
this->m_started = true;
return true;
}
@@ -51,7 +51,7 @@ namespace app {
bool Profiler::StopProfiling()
{
if (this->m_pPlatform && this->m_started) {
- this->m_tstampEnd = this->m_pPlatform->timer->stop_profiling();
+ this->m_tstampEnd = this->m_pPlatform->timer->get_counters();
this->m_started = false;
this->AddProfilingUnit(this->m_tstampSt, this->m_tstampEnd, this->m_name);
@@ -99,111 +99,28 @@ namespace app {
result.name = item.first;
result.samplesNum = series.size();
- Statistics AXI0_RD {
- .name = "NPU AXI0_RD_DATA_BEAT_RECEIVED",
- .unit = "beats",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].axi0writes,
- .max = 0
- };
- Statistics AXI0_WR {
- .name = "NPU AXI0_WR_DATA_BEAT_WRITTEN",
- .unit = "beats",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].axi0reads,
- .max = 0
- };
- Statistics AXI1_RD {
- .name = "NPU AXI1_RD_DATA_BEAT_RECEIVED",
- .unit = "beats",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].axi1reads,
- .max = 0
- };
- Statistics NPU_ACTIVE {
- .name = "NPU ACTIVE",
- .unit = "cycles",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].activeNpuCycles,
- .max = 0
- };
- Statistics NPU_IDLE {
- .name = "NPU IDLE",
- .unit = "cycles",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].idleNpuCycles,
- .max = 0
- };
- Statistics NPU_Total {
- .name = "NPU TOTAL",
- .unit = "cycles",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].npuCycles,
- .max = 0,
- };
-#if defined(CPU_PROFILE_ENABLED)
- Statistics CPU_ACTIVE {
- .name = "CPU ACTIVE",
- .unit = "cycles (approx)",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].cpuCycles - NPU_ACTIVE.min,
- .max = 0
- };
- Statistics TIME {
- .name = "Time",
- .unit = "ms",
- .total = 0,
- .avrg = 0.0,
- .min = static_cast<uint64_t>(series[0].time),
- .max = 0
- };
-#endif
- for(ProfilingUnit& unit: series){
-
- calcProfilingStat(unit.npuCycles,
- NPU_Total, result.samplesNum);
-
- calcProfilingStat(unit.activeNpuCycles,
- NPU_ACTIVE, result.samplesNum);
-
- calcProfilingStat(unit.idleNpuCycles,
- NPU_IDLE, result.samplesNum);
-
- calcProfilingStat(unit.axi0writes,
- AXI0_WR, result.samplesNum);
-
- calcProfilingStat(unit.axi0reads,
- AXI0_RD, result.samplesNum);
+ std::vector<Statistics> stats(series[0].counters.num_counters);
+ for (size_t i = 0; i < stats.size(); ++i) {
+ stats[i].name = series[0].counters.counters[i].name;
+ stats[i].unit = series[0].counters.counters[i].unit;
+ }
- calcProfilingStat(unit.axi1reads,
- AXI1_RD, result.samplesNum);
-#if defined(CPU_PROFILE_ENABLED)
- calcProfilingStat(static_cast<uint64_t>(unit.time),
- TIME, result.samplesNum);
+ for(ProfilingUnit& unit: series) {
+ for (size_t i = 0; i < stats.size(); ++i) {
+ calcProfilingStat(
+ unit.counters.counters[i].value,
+ stats[i],
+ result.samplesNum);
+ }
+ }
- calcProfilingStat(unit.cpuCycles - unit.activeNpuCycles,
- CPU_ACTIVE, result.samplesNum);
-#endif
+ for (Statistics& stat : stats) {
+ result.data.emplace_back(stat);
}
- result.data.emplace_back(AXI0_RD);
- result.data.emplace_back(AXI0_WR);
- result.data.emplace_back(AXI1_RD);
- result.data.emplace_back(NPU_ACTIVE);
- result.data.emplace_back(NPU_IDLE);
- result.data.emplace_back(NPU_Total);
-#if defined(CPU_PROFILE_ENABLED)
- result.data.emplace_back(CPU_ACTIVE);
- result.data.emplace_back(TIME);
-#endif
- results.emplace_back(result);
+
+ results.emplace_back(result);
}
+
this->Reset();
}
@@ -216,10 +133,11 @@ namespace app {
std::vector<ProfileResult> results{};
GetAllResultsAndReset(results);
for(ProfileResult& result: results) {
- info("Profile for %s:\n", result.name.c_str());
-
- if (printFullStat) {
- printStatisticsHeader(result.samplesNum);
+ if (result.data.size()) {
+ info("Profile for %s:\n", result.name.c_str());
+ if (printFullStat) {
+ printStatisticsHeader(result.samplesNum);
+ }
}
for (Statistics &stat: result.data) {
@@ -228,7 +146,7 @@ namespace app {
stat.name.c_str(), stat.unit.c_str(),
stat.total, stat.avrg, stat.min, stat.max);
} else {
- info("%s %s: %.0f\n", stat.name.c_str(), stat.unit.c_str(), stat.avrg);
+ info("%s: %.0f %s\n", stat.name.c_str(), stat.avrg, stat.unit.c_str());
}
}
}
@@ -239,7 +157,7 @@ namespace app {
this->m_name = std::string(str);
}
- void Profiler::AddProfilingUnit(time_counter start, time_counter end,
+ void Profiler::AddProfilingUnit(pmu_counters start, pmu_counters end,
const std::string& name)
{
if (!this->m_pPlatform) {
@@ -247,31 +165,23 @@ namespace app {
return;
}
- platform_timer * timer = this->m_pPlatform->timer;
+ struct ProfilingUnit unit = {
+ .counters = end
+ };
- struct ProfilingUnit unit;
-
- if (timer->cap.npu_cycles && timer->get_npu_cycles_diff)
- {
- const size_t size = 6;
- uint64_t pmuCounters[size] = {0};
- /* 6 values: total cc, active cc, idle cc, axi0 read, axi0 write, axi1 read*/
- if (0 == timer->get_npu_cycles_diff(&start, &end, pmuCounters, size)) {
- unit.npuCycles = pmuCounters[0];
- unit.activeNpuCycles = pmuCounters[1];
- unit.idleNpuCycles = pmuCounters[2];
- unit.axi0reads = pmuCounters[3];
- unit.axi0writes = pmuCounters[4];
- unit.axi1reads = pmuCounters[5];
- }
- }
-
- if (timer->cap.cpu_cycles && timer->get_cpu_cycle_diff) {
- unit.cpuCycles = timer->get_cpu_cycle_diff(&start, &end);
+ if (end.num_counters != start.num_counters ||
+ true != end.initialised || true != start.initialised) {
+ printf_err("Invalid start or end counters\n");
+ return;
}
- if (timer->cap.duration_ms && timer->get_duration_ms) {
- unit.time = timer->get_duration_ms(&start, &end);
+ for (size_t i = 0; i < unit.counters.num_counters; ++i) {
+ if (unit.counters.counters[i].value < start.counters[i].value) {
+ warn("Overflow detected for %s\n", unit.counters.counters[i].name);
+ unit.counters.counters[i].value = 0;
+ } else {
+ unit.counters.counters[i].value -= start.counters[i].value;
+ }
}
this->m_series[name].emplace_back(unit);