From b83af347fcba3b12e27ce441c06f817d09740e0e Mon Sep 17 00:00:00 2001 From: Connor O'Brien Date: Fri, 14 Aug 2020 13:13:37 -0700 Subject: 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: Connor O'Brien Change-Id: I1d889cd02e67263c0b031be74f0b963ed80961b0 --- libs/cputimeinstate/cputimeinstate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/cputimeinstate/cputimeinstate.cpp b/libs/cputimeinstate/cputimeinstate.cpp index b2ebf5d729..e56c79989d 100644 --- a/libs/cputimeinstate/cputimeinstate.cpp +++ b/libs/cputimeinstate/cputimeinstate.cpp @@ -251,7 +251,7 @@ std::optional>> 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 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; -- cgit v1.2.3-59-g8ed1b