Merge "psh_utils: Clean up log printing" into main
diff --git a/media/psh_utils/HealthStats.cpp b/media/psh_utils/HealthStats.cpp
index b40c8fe..5e767f6 100644
--- a/media/psh_utils/HealthStats.cpp
+++ b/media/psh_utils/HealthStats.cpp
@@ -27,10 +27,11 @@
std::string result;
const float batteryVoltage = batteryVoltageMillivolts * 1e-3f; // Volts
const float charge = batteryChargeCounterUah * (3600 * 1e-6); // Joules = Amp-Second
- result.append(" battery_voltage: ")
+ result.append("{Net Battery V: ")
.append(std::to_string(batteryVoltage))
- .append(" charge: ")
- .append(std::to_string(charge));
+ .append(" J: ")
+ .append(std::to_string(charge))
+ .append("}");
return result;
}
@@ -39,12 +40,13 @@
const float batteryVoltage = batteryVoltageMillivolts * 1e-3f; // Volts
const float charge = -batteryChargeCounterUah * (3600 * 1e-6f); // Joules = Amp-Second
const float watts = charge * batteryVoltage / timeSec;
- result.append(" battery_voltage: ")
+ result.append("{Net Battery V: ")
.append(std::to_string(batteryVoltage))
.append(" J: ")
.append(std::to_string(charge))
.append(" W: ")
- .append(std::to_string(watts));
+ .append(std::to_string(watts))
+ .append("}");
return result;
}
diff --git a/media/psh_utils/PowerStats.cpp b/media/psh_utils/PowerStats.cpp
index 9c6968f..f8f87c5 100644
--- a/media/psh_utils/PowerStats.cpp
+++ b/media/psh_utils/PowerStats.cpp
@@ -160,37 +160,41 @@
return result;
}
-std::string PowerStats::toString() const {
+std::string PowerStats::toString(const std::string& prefix) const {
std::string result;
- result.append(metadata.toString()).append("\n");
- result.append(health_stats.toString()).append("\n");
+ result.append(prefix).append(metadata.toString()).append("\n");
+ result.append(prefix).append(health_stats.toString()).append("\n");
for (const auto &residency: power_entity_state_residency) {
- result.append(residency.toString()).append("\n");
+ result.append(prefix).append(residency.toString()).append("\n");
}
for (const auto &energy: rail_energy) {
- result.append(energy.toString()).append("\n");
+ result.append(prefix).append(energy.toString()).append("\n");
}
return result;
}
-std::string PowerStats::normalizedEnergy() const {
+std::string PowerStats::normalizedEnergy(const std::string& prefix) const {
if (metadata.duration_ms == 0) return {};
- std::string result(audio_utils_time_string_from_ns(
+ std::string result(prefix);
+ result.append(audio_utils_time_string_from_ns(
metadata.start_time_epoch_ms * 1'000'000).time);
result.append(" duration_boottime: ")
.append(std::to_string(metadata.duration_ms * 1e-3f))
.append(" duration_monotonic: ")
.append(std::to_string(metadata.duration_monotonic_ms * 1e-3f))
.append("\n");
- result.append(health_stats.normalizedEnergy(metadata.duration_ms * 1e-3f)).append("\n");
+ if (health_stats.isValid()) {
+ result.append(prefix)
+ .append(health_stats.normalizedEnergy(metadata.duration_ms * 1e-3f)).append("\n");
+ }
// energy_uws is converted to ave W using recip time in us.
const float recipTime = 1e-3 / metadata.duration_ms;
int64_t total_energy = 0;
for (const auto& energy: rail_energy) {
total_energy += energy.energy_uws;
- result.append(energy.subsystem_name)
+ result.append(prefix).append(energy.subsystem_name)
.append(energy.rail_name)
.append(" ")
.append(std::to_string(energy.energy_uws * 1e-6))
@@ -198,11 +202,13 @@
.append(std::to_string(energy.energy_uws * recipTime))
.append("\n");
}
- result.append("total J and ave W: ")
- .append(std::to_string(total_energy * 1e-6))
- .append(" ")
- .append(std::to_string(total_energy * recipTime))
- .append("\n");
+ if (total_energy != 0) {
+ result.append(prefix).append("total J and ave W: ")
+ .append(std::to_string(total_energy * 1e-6))
+ .append(" ")
+ .append(std::to_string(total_energy * recipTime))
+ .append("\n");
+ }
return result;
}
diff --git a/media/psh_utils/include/psh_utils/HealthStats.h b/media/psh_utils/include/psh_utils/HealthStats.h
index 982c390..d7a8d1a 100644
--- a/media/psh_utils/include/psh_utils/HealthStats.h
+++ b/media/psh_utils/include/psh_utils/HealthStats.h
@@ -42,6 +42,8 @@
std::string normalizedEnergy(double time) const;
+ bool isValid() const { return batteryVoltageMillivolts > 0; }
+
// Returns {seconds, joules, watts} from battery counters
std::tuple<float, float, float> energyFrom(const std::string& s) const;
std::string toString() const;
diff --git a/media/psh_utils/include/psh_utils/PowerStats.h b/media/psh_utils/include/psh_utils/PowerStats.h
index 1e819cc..ae48606 100644
--- a/media/psh_utils/include/psh_utils/PowerStats.h
+++ b/media/psh_utils/include/psh_utils/PowerStats.h
@@ -87,11 +87,11 @@
HealthStats health_stats;
- std::string normalizedEnergy() const;
+ std::string normalizedEnergy(const std::string& prefix = {}) const;
// Returns {seconds, joules, watts} from all rails containing a matching string.
std::tuple<float, float, float> energyFrom(const std::string& railMatcher) const;
- std::string toString() const;
+ std::string toString(const std::string& prefix = {}) const;
PowerStats operator+=(const PowerStats& other);
PowerStats operator-=(const PowerStats& other);