powerstats: Add config support for AdaptiveDvfs data provider

Bug: 273415531
Test: dumpsys android.hardware.power.stats.IPowerStats/default
Change-Id: I48bd1ec622680a3c93d15b571fbf21579f0e21ed
Signed-off-by: Darren Hsu <darrenhsu@google.com>
This commit is contained in:
Darren Hsu 2023-03-14 14:31:43 +08:00
parent 75a5c5dceb
commit 529b618a7c
3 changed files with 29 additions and 22 deletions

View File

@ -25,6 +25,9 @@
using android::base::Split; using android::base::Split;
using android::base::Trim; using android::base::Trim;
static const std::string pathSuffix = "/time_in_state";
static const std::string stateSuffix = "MHz";
namespace aidl { namespace aidl {
namespace android { namespace android {
namespace hardware { namespace hardware {
@ -34,33 +37,35 @@ namespace stats {
AdaptiveDvfsStateResidencyDataProvider::AdaptiveDvfsStateResidencyDataProvider( AdaptiveDvfsStateResidencyDataProvider::AdaptiveDvfsStateResidencyDataProvider(
std::string path, std::string path,
uint64_t clockRate, uint64_t clockRate,
std::string powerEntityName, std::vector<std::pair<std::string, std::string>> powerEntities)
std::string freqPath)
: DvfsStateResidencyDataProvider(path, clockRate, {}) { : DvfsStateResidencyDataProvider(path, clockRate, {}) {
std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(freqPath.c_str(), "r"), fclose);
if (!fp) {
PLOG(ERROR) << __func__ << ":Failed to open file " << freqPath;
return;
}
size_t len = 0; size_t len = 0;
char *line = nullptr; char *line = nullptr;
std::string suffix = "MHz";
std::vector<std::pair<std::string, std::string>> states = {}; std::vector<std::pair<std::string, std::string>> states = {};
std::vector<std::string> parts; std::vector<std::string> parts;
std::string freqStr;
while (getline(&line, &len, fp.get()) != -1) { for (int32_t i = 0; i < powerEntities.size(); i++) {
parts = Split(line, " "); std::string freqPath = powerEntities[i].second + pathSuffix;
if (parts.size() > 0) { std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(freqPath.c_str(), "r"), fclose);
freqStr = Trim(parts[0]); if (!fp) {
states.push_back(std::make_pair( PLOG(ERROR) << __func__ << ":Failed to open file " << freqPath;
freqStr.substr(0, freqStr.length() - 3) + suffix, continue;
freqStr));
} }
while (getline(&line, &len, fp.get()) != -1) {
parts = Split(Trim(std::string(line)), " ");
if (parts.size() > 0) {
std::string freqStr = Trim(parts[0]);
states.push_back(std::make_pair(
freqStr.substr(0, freqStr.length() - 3) + stateSuffix,
freqStr));
}
}
mPowerEntities.push_back({powerEntities[i].first, std::move(states)});
} }
mPowerEntities.push_back({powerEntityName, std::move(states)}); free(line);
} }
bool AdaptiveDvfsStateResidencyDataProvider::getStateResidencies( bool AdaptiveDvfsStateResidencyDataProvider::getStateResidencies(

View File

@ -103,6 +103,10 @@ bool DvfsStateResidencyDataProvider::getStateResidencies(
it = residencies->find(mPowerEntities[powerEntityIndex].powerEntityName + nameSuffix); it = residencies->find(mPowerEntities[powerEntityIndex].powerEntityName + nameSuffix);
} }
// The given string is last state for each entity.
if (StartsWith(Trim(std::string(line)), "last_freq_change_time_ns:"))
it = residencies->end();
if (it != residencies->end()) { if (it != residencies->end()) {
stateId = matchState(line, mPowerEntities[powerEntityIndex]); stateId = matchState(line, mPowerEntities[powerEntityIndex]);

View File

@ -28,14 +28,12 @@ class AdaptiveDvfsStateResidencyDataProvider : public DvfsStateResidencyDataProv
/* /*
* path - path to dvfs sysfs node. * path - path to dvfs sysfs node.
* clockRate - clock rate in KHz. * clockRate - clock rate in KHz.
* powerEntityName - power entity name to parse. * powerEntities - list of power entity pairs (name to power entity, path to frequency table)
* freqPath - path to frequency table.
*/ */
AdaptiveDvfsStateResidencyDataProvider( AdaptiveDvfsStateResidencyDataProvider(
std::string path, std::string path,
uint64_t clockRate, uint64_t clockRate,
std::string powerEntityName, std::vector<std::pair<std::string, std::string>> powerEntities);
std::string freqPath);
~AdaptiveDvfsStateResidencyDataProvider() = default; ~AdaptiveDvfsStateResidencyDataProvider() = default;
/* /*