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

Commit 43f4d26d authored by Jeffrey Huang's avatar Jeffrey Huang
Browse files

Migrate HealthHal to StatsPullAtomService

Bug: 148618655

Test: atest HostAtomTests
Test: adb shell cmd stats pull-source 10019
Test: adb shell cmd stats pull-source 10020
Test: adb shell cmd stats pull-source 10030
Test: adb shell cmd stats pull-source 10045
Change-Id: I10a0682828b086751b90c3cc133fb51c34cbea23
parent 9a3c1b6e
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -69,7 +69,6 @@ cc_defaults {
        "src/external/PowerStatsPuller.cpp",
        "src/external/PullResultReceiver.cpp",
        "src/external/puller_util.cpp",
        "src/external/ResourceHealthManagerPuller.cpp",
        "src/external/StatsCallbackPuller.cpp",
        "src/external/StatsPuller.cpp",
        "src/external/StatsPullerManager.cpp",
@@ -127,7 +126,6 @@ cc_defaults {
        "android.hardware.power@1.1",
        "libbase",
        "libcutils",
        "libhealthhalutils",
        "liblog",
        "libplatformprotos",
        "libprotoutil",
@@ -136,7 +134,6 @@ cc_defaults {
        "libsysutils",
    ],
    shared_libs: [
        "android.hardware.health@2.0",
        "libbinder",
        "libgraphicsenv",
        "libhidlbase",
+4 −4
Original line number Diff line number Diff line
@@ -411,8 +411,8 @@ message Atom {
        CpuActiveTime cpu_active_time = 10016 [(module) = "framework"];
        CpuClusterTime cpu_cluster_time = 10017 [(module) = "framework"];
        DiskSpace disk_space = 10018 [deprecated=true];
        RemainingBatteryCapacity remaining_battery_capacity = 10019;
        FullBatteryCapacity full_battery_capacity = 10020;
        RemainingBatteryCapacity remaining_battery_capacity = 10019 [(module) = "framework"];
        FullBatteryCapacity full_battery_capacity = 10020 [(module) = "framework"];
        Temperature temperature = 10021 [(module) = "framework"];
        BinderCalls binder_calls = 10022 [(module) = "framework"];
        BinderCallsExceptions binder_calls_exceptions = 10023 [(module) = "framework"];
@@ -422,7 +422,7 @@ message Atom {
        AppSize app_size = 10027 [(module) = "framework"];
        CategorySize category_size = 10028 [(module) = "framework"];
        ProcStats proc_stats = 10029 [(module) = "framework"];
        BatteryVoltage battery_voltage = 10030;
        BatteryVoltage battery_voltage = 10030 [(module) = "framework"];
        NumFingerprintsEnrolled num_fingerprints_enrolled = 10031 [(module) = "framework"];
        DiskIo disk_io = 10032 [(module) = "framework"];
        PowerProfile power_profile = 10033 [(module) = "framework"];
@@ -438,7 +438,7 @@ message Atom {
        ProcessMemoryHighWaterMark process_memory_high_water_mark = 10042 [(module) = "framework"];
        BatteryLevel battery_level = 10043 [(module) = "framework"];
        BuildInformation build_information = 10044 [(module) = "framework"];
        BatteryCycleCount battery_cycle_count = 10045;
        BatteryCycleCount battery_cycle_count = 10045 [(module) = "framework"];
        DebugElapsedClock debug_elapsed_clock = 10046 [(module) = "framework"];
        DebugFailingElapsedClock debug_failing_elapsed_clock = 10047 [(module) = "framework"];
        NumFacesEnrolled num_faces_enrolled = 10048 [(module) = "framework"];
+0 −117
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define DEBUG false  // STOPSHIP if true
#include "Log.h"

#include <android/hardware/health/2.0/IHealth.h>
#include <healthhalutils/HealthHalUtils.h>
#include "external/ResourceHealthManagerPuller.h"
#include "external/StatsPuller.h"

#include "ResourceHealthManagerPuller.h"
#include "logd/LogEvent.h"
#include "stats_log_util.h"
#include "statslog.h"

using android::hardware::hidl_vec;
using android::hardware::Return;
using android::hardware::Void;
using android::hardware::health::V2_0::get_health_service;
using android::hardware::health::V2_0::HealthInfo;
using android::hardware::health::V2_0::IHealth;
using android::hardware::health::V2_0::Result;

using std::make_shared;
using std::shared_ptr;

namespace android {
namespace os {
namespace statsd {

sp<android::hardware::health::V2_0::IHealth> gHealthHal = nullptr;

bool getHealthHal() {
    if (gHealthHal == nullptr) {
        gHealthHal = get_health_service();
    }
    return gHealthHal != nullptr;
}

ResourceHealthManagerPuller::ResourceHealthManagerPuller(int tagId) : StatsPuller(tagId) {
}

// TODO(b/110565992): add other health atoms (eg. Temperature).
bool ResourceHealthManagerPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) {
    if (!getHealthHal()) {
        ALOGE("Health Hal not loaded");
        return false;
    }

    int64_t wallClockTimestampNs = getWallClockNs();
    int64_t elapsedTimestampNs = getElapsedRealtimeNs();

    data->clear();
    bool result_success = true;

    // Get the data from the Health HAL (hardware/interfaces/health/1.0/types.hal).
    Return<void> ret = gHealthHal->getHealthInfo([&](Result r, HealthInfo v) {
        if (r != Result::SUCCESS) {
            result_success = false;
            return;
        }
        if (mTagId == android::util::REMAINING_BATTERY_CAPACITY) {
            auto ptr = make_shared<LogEvent>(android::util::REMAINING_BATTERY_CAPACITY,
                                             wallClockTimestampNs, elapsedTimestampNs);
            ptr->write(v.legacy.batteryChargeCounter);
            ptr->init();
            data->push_back(ptr);
        } else if (mTagId == android::util::FULL_BATTERY_CAPACITY) {
            auto ptr = make_shared<LogEvent>(android::util::FULL_BATTERY_CAPACITY,
                                             wallClockTimestampNs, elapsedTimestampNs);
            ptr->write(v.legacy.batteryFullCharge);
            ptr->init();
            data->push_back(ptr);
        } else if (mTagId == android::util::BATTERY_VOLTAGE) {
            auto ptr = make_shared<LogEvent>(android::util::BATTERY_VOLTAGE, wallClockTimestampNs,
                                             elapsedTimestampNs);
            ptr->write(v.legacy.batteryVoltage);
            ptr->init();
            data->push_back(ptr);
        } else if (mTagId == android::util::BATTERY_CYCLE_COUNT) {
            auto ptr = make_shared<LogEvent>(android::util::BATTERY_CYCLE_COUNT,
                                             wallClockTimestampNs, elapsedTimestampNs);
            ptr->write(v.legacy.batteryCycleCount);
            ptr->init();
            data->push_back(ptr);
        } else {
            ALOGE("Unsupported tag in ResourceHealthManagerPuller: %d", mTagId);
        }
    });
    if (!result_success || !ret.isOk()) {
        ALOGE("getHealthHal() failed: health HAL service not available. Description: %s",
              ret.description().c_str());
        if (!ret.isOk() && ret.isDeadObject()) {
            gHealthHal = nullptr;
        }
        return false;
    }
    return true;
}

}  // namespace statsd
}  // namespace os
}  // namespace android
+0 −39
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <utils/String16.h>
#include "StatsPuller.h"

namespace android {
namespace os {
namespace statsd {

/**
 * Reads Ihealth.hal
 */
class ResourceHealthManagerPuller : public StatsPuller {
public:
    explicit ResourceHealthManagerPuller(int tagId);

private:
    bool PullInternal(vector<std::shared_ptr<LogEvent>>* data) override;
};

}  // namespace statsd
}  // namespace os
}  // namespace android
+0 −17
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@
#include "../statscompanion_util.h"
#include "GpuStatsPuller.h"
#include "PowerStatsPuller.h"
#include "ResourceHealthManagerPuller.h"
#include "StatsCallbackPuller.h"
#include "SubsystemSleepStatePuller.h"
#include "TrainInfoPuller.h"
@@ -62,22 +61,6 @@ StatsPullerManager::StatsPullerManager()
              // on_device_power_measurement
              {{.atomTag = android::util::ON_DEVICE_POWER_MEASUREMENT}, new PowerStatsPuller()},

              // remaining_battery_capacity
              {{.atomTag = android::util::REMAINING_BATTERY_CAPACITY},
               new ResourceHealthManagerPuller(android::util::REMAINING_BATTERY_CAPACITY)},

              // full_battery_capacity
              {{.atomTag = android::util::FULL_BATTERY_CAPACITY},
               new ResourceHealthManagerPuller(android::util::FULL_BATTERY_CAPACITY)},

              // battery_voltage
              {{.atomTag = android::util::BATTERY_VOLTAGE},
               new ResourceHealthManagerPuller(android::util::BATTERY_VOLTAGE)},

              // battery_cycle_count
              {{.atomTag = android::util::BATTERY_CYCLE_COUNT},
               new ResourceHealthManagerPuller(android::util::BATTERY_CYCLE_COUNT)},

              // TrainInfo.
              {{.atomTag = android::util::TRAIN_INFO}, new TrainInfoPuller()},

Loading