libtimeinstate: add getCpuFreqs() function
Currently the KernelCpuUidFreqTimeReader reads the first line of
/proc/uid_time_in_state to determine a device's available CPU
frequencies, but libtimeinstate already reads this information from
sysfs files that are supported upstream. Add a function to provide
this information to libtimeinstate's users & eliminate the need to
read the proc file for this data.
Add a sanity check in libtimeinstate_test to confirm that
getCpuFreqs() and getUidCpuFreqTimes() report the same number of
frequencies for each cluster.
Bug: 138317993
Test: libtimeinstate_test passes
Change-Id: I3e8c632d14bbeb552d7e52bd83a9b4a64dec408d
Signed-off-by: Connor O'Brien <connoro@google.com>
diff --git a/libs/cputimeinstate/cputimeinstate.cpp b/libs/cputimeinstate/cputimeinstate.cpp
index 7b7a7e3..037846b 100644
--- a/libs/cputimeinstate/cputimeinstate.cpp
+++ b/libs/cputimeinstate/cputimeinstate.cpp
@@ -213,6 +213,11 @@
attachTracepointProgram("power", "cpu_frequency");
}
+std::optional<std::vector<std::vector<uint32_t>>> getCpuFreqs() {
+ if (!gInitialized && !initGlobals()) return {};
+ return gPolicyFreqs;
+}
+
// Retrieve the times in ns that uid spent running at each CPU frequency.
// Return contains no value on error, otherwise it contains a vector of vectors using the format:
// [[t0_0, t0_1, ...],