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

Commit 1d80be21 authored by Varad Gautam's avatar Varad Gautam
Browse files

gpuwork: Simplify checks to avoid uploading negative timestamps



Flag: EXEMPT bugfix
Bug: 347657694
Test: statsd_testdrive 10147
Change-Id: Ief44505e152adf08dacfe6f6a109b256589533ab
Signed-off-by: default avatarVarad Gautam <varadgautam@google.com>
parent 66fb25e4
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -385,10 +385,11 @@ AStatsManager_PullAtomCallbackReturn GpuWork::pullWorkAtoms(AStatsEventList* dat
    ALOGI("pullWorkAtoms: after random selection: uids.size() == %zu", uids.size());

    auto now = std::chrono::steady_clock::now();
    long long duration =
    int32_t duration =
            static_cast<int32_t>(
                std::chrono::duration_cast<std::chrono::seconds>(now - mPreviousMapClearTimePoint)
                    .count();
    if (duration > std::numeric_limits<int32_t>::max() || duration < 0) {
                    .count());
    if (duration < 0) {
        // This is essentially impossible. If it does somehow happen, give up,
        // but still clear the map.
        clearMap();
@@ -404,13 +405,14 @@ AStatsManager_PullAtomCallbackReturn GpuWork::pullWorkAtoms(AStatsEventList* dat
            }
            const UidTrackingInfo& info = it->second;

            uint64_t total_active_duration_ms = info.total_active_duration_ns / MSEC_PER_NSEC;
            uint64_t total_inactive_duration_ms = info.total_inactive_duration_ns / MSEC_PER_NSEC;
            int32_t total_active_duration_ms =
                static_cast<int32_t>(info.total_active_duration_ns / MSEC_PER_NSEC);
            int32_t total_inactive_duration_ms =
                static_cast<int32_t>(info.total_inactive_duration_ns / MSEC_PER_NSEC);

            // Skip this atom if any numbers are out of range. |duration| is
            // already checked above.
            if (total_active_duration_ms > std::numeric_limits<int32_t>::max() ||
                total_inactive_duration_ms > std::numeric_limits<int32_t>::max()) {
            if (total_active_duration_ms < 0 || total_inactive_duration_ms < 0) {
                continue;
            }

@@ -421,11 +423,11 @@ AStatsManager_PullAtomCallbackReturn GpuWork::pullWorkAtoms(AStatsEventList* dat
                                          // gpu_id
                                          bitcast_int32(gpuId),
                                          // time_duration_seconds
                                          static_cast<int32_t>(duration),
                                          duration,
                                          // total_active_duration_millis
                                          static_cast<int32_t>(total_active_duration_ms),
                                          total_active_duration_ms,
                                          // total_inactive_duration_millis
                                          static_cast<int32_t>(total_inactive_duration_ms));
                                          total_inactive_duration_ms);
        }
    }
    clearMap();