powerstats: include sleep duration for core down state
Bug: 263276734 Test: dumpsys android.hardware.power.stats.IPowerStats/default Change-Id: Ia9c1ed8c7ca68d03e73da35674ac299d7cf22045 Signed-off-by: Darren Hsu <darrenhsu@google.com>
This commit is contained in:
parent
a5ba7efd7b
commit
02b8df5191
@ -34,8 +34,14 @@ namespace power {
|
|||||||
namespace stats {
|
namespace stats {
|
||||||
|
|
||||||
CpupmStateResidencyDataProvider::CpupmStateResidencyDataProvider(
|
CpupmStateResidencyDataProvider::CpupmStateResidencyDataProvider(
|
||||||
const std::string &path, const Config &config)
|
const std::string &path,
|
||||||
: mPath(std::move(path)), mConfig(std::move(config)) {}
|
const Config &config,
|
||||||
|
const std::string &sleepPath,
|
||||||
|
const SleepConfig &sleepConfig)
|
||||||
|
: mPath(std::move(path)),
|
||||||
|
mConfig(std::move(config)),
|
||||||
|
mSleepPath(std::move(sleepPath)),
|
||||||
|
mSleepConfig(std::move(sleepConfig)) {}
|
||||||
|
|
||||||
int32_t CpupmStateResidencyDataProvider::matchState(char const *line) {
|
int32_t CpupmStateResidencyDataProvider::matchState(char const *line) {
|
||||||
for (int32_t i = 0; i < mConfig.states.size(); i++) {
|
for (int32_t i = 0; i < mConfig.states.size(); i++) {
|
||||||
@ -78,6 +84,12 @@ bool CpupmStateResidencyDataProvider::getStateResidencies(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<FILE, decltype(&fclose)> sleepFp(fopen(mSleepPath.c_str(), "r"), fclose);
|
||||||
|
if (!sleepFp) {
|
||||||
|
PLOG(ERROR) << __func__ << ":Failed to open file " << mSleepPath;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < mConfig.entities.size(); i++) {
|
for (int32_t i = 0; i < mConfig.entities.size(); i++) {
|
||||||
std::vector<StateResidency> stateResidencies(mConfig.states.size());
|
std::vector<StateResidency> stateResidencies(mConfig.states.size());
|
||||||
for (int32_t j = 0; j < stateResidencies.size(); j++) {
|
for (int32_t j = 0; j < stateResidencies.size(); j++) {
|
||||||
@ -90,9 +102,29 @@ bool CpupmStateResidencyDataProvider::getStateResidencies(
|
|||||||
char *line = nullptr;
|
char *line = nullptr;
|
||||||
|
|
||||||
int32_t temp, entityIndex, stateId = -1;
|
int32_t temp, entityIndex, stateId = -1;
|
||||||
uint64_t duration, count;
|
uint64_t duration, count, sleepDurationMs = 0;
|
||||||
auto it = residencies->end();
|
auto it = residencies->end();
|
||||||
|
int32_t sleepIndex = 0;
|
||||||
|
|
||||||
|
// Parse state for sleep duration
|
||||||
|
while (getline(&line, &len, sleepFp.get()) != -1) {
|
||||||
|
std::string trimedLine = Trim(std::string(line));
|
||||||
|
if (StartsWith(trimedLine, mSleepConfig[sleepIndex])) {
|
||||||
|
if (sleepIndex < mSleepConfig.size() - 1) {
|
||||||
|
sleepIndex++;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
std::vector<std::string> parts = Split(trimedLine, " ");
|
||||||
|
if (parts.size() == 2) {
|
||||||
|
ParseUint(parts[1], &sleepDurationMs);
|
||||||
|
sleepDurationMs /= NS_TO_MS;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse state for CPUPM entities
|
||||||
while (getline(&line, &len, fp.get()) != -1) {
|
while (getline(&line, &len, fp.get()) != -1) {
|
||||||
temp = matchState(line);
|
temp = matchState(line);
|
||||||
// Assign new id only when a new valid state is encountered.
|
// Assign new id only when a new valid state is encountered.
|
||||||
@ -109,7 +141,7 @@ bool CpupmStateResidencyDataProvider::getStateResidencies(
|
|||||||
it = residencies->find(mConfig.entities[entityIndex].first);
|
it = residencies->find(mConfig.entities[entityIndex].first);
|
||||||
if (it != residencies->end()) {
|
if (it != residencies->end()) {
|
||||||
if (parseState(line, &duration, &count)) {
|
if (parseState(line, &duration, &count)) {
|
||||||
it->second[stateId].totalTimeInStateMs = duration / US_TO_MS;
|
it->second[stateId].totalTimeInStateMs = duration / US_TO_MS + sleepDurationMs;
|
||||||
it->second[stateId].totalStateEntryCount = count;
|
it->second[stateId].totalStateEntryCount = count;
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "Failed to parse duration and count from [" << std::string(line)
|
LOG(ERROR) << "Failed to parse duration and count from [" << std::string(line)
|
||||||
|
@ -34,10 +34,16 @@ class CpupmStateResidencyDataProvider : public PowerStats::IStateResidencyDataPr
|
|||||||
std::vector<std::pair<std::string, std::string>> states;
|
std::vector<std::pair<std::string, std::string>> states;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef std::vector<std::string> SleepConfig;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* path - path to cpupm sysfs node.
|
* path - path to cpupm sysfs node.
|
||||||
*/
|
*/
|
||||||
CpupmStateResidencyDataProvider(const std::string &path, const Config &config);
|
CpupmStateResidencyDataProvider(
|
||||||
|
const std::string &path,
|
||||||
|
const Config &config,
|
||||||
|
const std::string &sleepPath,
|
||||||
|
const SleepConfig &sleepConfig);
|
||||||
~CpupmStateResidencyDataProvider() = default;
|
~CpupmStateResidencyDataProvider() = default;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -58,9 +64,13 @@ class CpupmStateResidencyDataProvider : public PowerStats::IStateResidencyDataPr
|
|||||||
|
|
||||||
// A constant to represent the number of microseconds in one millisecond.
|
// A constant to represent the number of microseconds in one millisecond.
|
||||||
const uint64_t US_TO_MS = 1000;
|
const uint64_t US_TO_MS = 1000;
|
||||||
|
// A constant to represent the number of nanoseconds in one millisecond.
|
||||||
|
const uint64_t NS_TO_MS = 1000000;
|
||||||
|
|
||||||
const std::string mPath;
|
const std::string mPath;
|
||||||
const Config mConfig;
|
const Config mConfig;
|
||||||
|
const std::string mSleepPath;
|
||||||
|
const SleepConfig mSleepConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace stats
|
} // namespace stats
|
||||||
|
Loading…
x
Reference in New Issue
Block a user