Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b83af347 authored by Connor O'Brien's avatar Connor O'Brien
Browse files

libtimeinstate: improve error handling in single-UID functions



getUidCpuFreqTimes and getUidConcurrentTimes return all zeros if the
requested UID is not present in the BPF maps on the assumption that
that UID has zero runtime, but this could also indicate that tracking
never started (in which case the map will be empty). Add a check to
distinguish these cases and return an error when tracking is not
working.

Test: load maps (but not progs) from time_in_state.o, enable
track_cpu_times_by_proc_state, run BstatsCpuTimesValidationTest
Bug: 163593704
Signed-off-by: default avatarConnor O'Brien <connoro@google.com>

Change-Id: I1d889cd02e67263c0b031be74f0b963ed80961b0
parent ea830510
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -251,7 +251,7 @@ std::optional<std::vector<std::vector<uint64_t>>> getUidCpuFreqTimes(uint32_t ui
    for (uint32_t i = 0; i <= (maxFreqCount - 1) / FREQS_PER_ENTRY; ++i) {
        key.bucket = i;
        if (findMapEntry(gTisMapFd, &key, vals.data())) {
            if (errno != ENOENT) return {};
            if (errno != ENOENT || getFirstMapKey(gTisMapFd, &key)) return {};
            continue;
        }

@@ -362,7 +362,7 @@ std::optional<concurrent_time_t> getUidConcurrentTimes(uint32_t uid, bool retry)
    time_key_t key = {.uid = uid};
    for (key.bucket = 0; key.bucket <= (gNCpus - 1) / CPUS_PER_ENTRY; ++key.bucket) {
        if (findMapEntry(gConcurrentMapFd, &key, vals.data())) {
            if (errno != ENOENT) return {};
            if (errno != ENOENT || getFirstMapKey(gConcurrentMapFd, &key)) return {};
            continue;
        }
        auto offset = key.bucket * CPUS_PER_ENTRY;