Loading cmds/statsd/Android.bp +0 −4 Original line number Diff line number Diff line Loading @@ -71,7 +71,6 @@ cc_defaults { "src/external/StatsCallbackPuller.cpp", "src/external/StatsPuller.cpp", "src/external/StatsPullerManager.cpp", "src/external/SubsystemSleepStatePuller.cpp", "src/external/TrainInfoPuller.cpp", "src/FieldValue.cpp", "src/guardrail/StatsdStats.cpp", Loading Loading @@ -120,9 +119,6 @@ cc_defaults { static_libs: [ "android.frameworks.stats@1.0", "android.hardware.power.stats@1.0", "android.hardware.power@1.0", "android.hardware.power@1.1", "libbase", "libcutils", "liblog", Loading cmds/statsd/src/external/StatsPullerManager.cpp +0 −4 Original line number Diff line number Diff line Loading @@ -34,7 +34,6 @@ #include "../statscompanion_util.h" #include "GpuStatsPuller.h" #include "StatsCallbackPuller.h" #include "SubsystemSleepStatePuller.h" #include "TrainInfoPuller.h" #include "statslog.h" Loading @@ -54,9 +53,6 @@ const int64_t NO_ALARM_UPDATE = INT64_MAX; StatsPullerManager::StatsPullerManager() : kAllPullAtomInfo({ // subsystem_sleep_state {{.atomTag = android::util::SUBSYSTEM_SLEEP_STATE}, new SubsystemSleepStatePuller()}, // TrainInfo. {{.atomTag = android::util::TRAIN_INFO}, new TrainInfoPuller()}, Loading services/core/jni/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ cc_library_static { "BroadcastRadio/convert.cpp", "BroadcastRadio/regions.cpp", "stats/PowerStatsPuller.cpp", "stats/SubsystemSleepStatePuller.cpp", "com_android_server_am_BatteryStatsService.cpp", "com_android_server_connectivity_Vpn.cpp", "com_android_server_ConsumerIrService.cpp", Loading services/core/jni/com_android_server_stats_pull_StatsPullAtomService.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -24,10 +24,12 @@ #include <statslog.h> #include "stats/PowerStatsPuller.h" #include "stats/SubsystemSleepStatePuller.h" namespace android { static server::stats::PowerStatsPuller gPowerStatsPuller; static server::stats::SubsystemSleepStatePuller gSubsystemSleepStatePuller; static status_pull_atom_return_t onDevicePowerMeasurementCallback(int32_t atom_tag, pulled_stats_event_list* data, Loading @@ -35,6 +37,12 @@ static status_pull_atom_return_t onDevicePowerMeasurementCallback(int32_t atom_t return gPowerStatsPuller.Pull(atom_tag, data); } static status_pull_atom_return_t subsystemSleepStateCallback(int32_t atom_tag, pulled_stats_event_list* data, void* cookie) { return gSubsystemSleepStatePuller.Pull(atom_tag, data); } static void nativeInit(JNIEnv* env, jobject javaObject) { // on device power measurement gPowerStatsPuller = server::stats::PowerStatsPuller(); Loading @@ -42,6 +50,13 @@ static void nativeInit(JNIEnv* env, jobject javaObject) { onDevicePowerMeasurementCallback, /* metadata= */ nullptr, /* cookie= */ nullptr); // subsystem sleep state gSubsystemSleepStatePuller = server::stats::SubsystemSleepStatePuller(); register_stats_pull_atom_callback(android::util::SUBSYSTEM_SLEEP_STATE, subsystemSleepStateCallback, /* metadata= */ nullptr, /* cookie= */ nullptr); } static const JNINativeMethod sMethods[] = {{"nativeInit", "()V", (void*)nativeInit}}; Loading cmds/statsd/src/external/SubsystemSleepStatePuller.cpp→services/core/jni/stats/SubsystemSleepStatePuller.cpp +107 −118 Original line number Diff line number Diff line Loading @@ -15,7 +15,10 @@ */ #define DEBUG false // STOPSHIP if true #include "Log.h" #define LOG_TAG "SubsystemSleepStatePuller" #include <log/log.h> #include <statslog.h> #include <android/hardware/power/1.0/IPower.h> #include <android/hardware/power/1.1/IPower.h> Loading @@ -32,13 +35,8 @@ #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include "external/SubsystemSleepStatePuller.h" #include "external/StatsPuller.h" #include <unordered_map> #include "SubsystemSleepStatePuller.h" #include "logd/LogEvent.h" #include "statslog.h" #include "stats_log_util.h" using android::hardware::hidl_vec; using android::hardware::power::V1_0::IPower; Loading @@ -53,14 +51,12 @@ using android::hardware::power::stats::V1_0::PowerEntityStateSpace; using android::hardware::Return; using android::hardware::Void; using std::make_shared; using std::shared_ptr; namespace android { namespace os { namespace statsd { namespace server { namespace stats { static std::function<bool(vector<shared_ptr<LogEvent>>* data)> gPuller = {}; static std::function<status_pull_atom_return_t(int32_t atomTag, pulled_stats_event_list* data)> gPuller = {}; static sp<android::hardware::power::V1_0::IPower> gPowerHalV1_0 = nullptr; static sp<android::hardware::power::V1_1::IPower> gPowerHalV1_1 = nullptr; Loading Loading @@ -91,9 +87,7 @@ struct SubsystemSleepStatePullerDeathRecipient : virtual public hardware::hidl_d static sp<SubsystemSleepStatePullerDeathRecipient> gDeathRecipient = new SubsystemSleepStatePullerDeathRecipient(); SubsystemSleepStatePuller::SubsystemSleepStatePuller() : StatsPuller(android::util::SUBSYSTEM_SLEEP_STATE) { } SubsystemSleepStatePuller::SubsystemSleepStatePuller() {} // The caller must be holding gPowerHalMutex. static bool checkResultLocked(const Return<void> &ret, const char* function) { Loading Loading @@ -182,39 +176,35 @@ static bool getPowerStatsHalLocked() { } // The caller must be holding gPowerHalMutex. static bool getIPowerStatsDataLocked(vector<shared_ptr<LogEvent>>* data) { static status_pull_atom_return_t getIPowerStatsDataLocked(int32_t atomTag, pulled_stats_event_list* data) { using android::hardware::power::stats::V1_0::Status; if(!getPowerStatsHalLocked()) { return false; return STATS_PULL_SKIP; } int64_t wallClockTimestampNs = getWallClockNs(); int64_t elapsedTimestampNs = getElapsedRealtimeNs(); // Get power entity state residency data bool success = false; Return<void> ret = gPowerStatsHalV1_0->getPowerEntityStateResidencyData({}, [&data, &success, wallClockTimestampNs, elapsedTimestampNs] (auto results, auto status) { Return<void> ret = gPowerStatsHalV1_0->getPowerEntityStateResidencyData( {}, [&data, &success](auto results, auto status) { if (status == Status::NOT_SUPPORTED) { ALOGW("getPowerEntityStateResidencyData is not supported"); success = false; return; } for (auto result : results) { for (auto stateResidency : result.stateResidencyData) { auto statePtr = make_shared<LogEvent>( android::util::SUBSYSTEM_SLEEP_STATE, wallClockTimestampNs, elapsedTimestampNs); statePtr->write(gEntityNames.at(result.powerEntityId)); statePtr->write(gStateNames.at(result.powerEntityId) .at(stateResidency.powerEntityStateId)); statePtr->write(stateResidency.totalStateEntryCount); statePtr->write(stateResidency.totalTimeInStateMs); statePtr->init(); data->emplace_back(statePtr); stats_event* event = add_stats_event_to_pull_data(data); stats_event_set_atom_id(event, android::util::SUBSYSTEM_SLEEP_STATE); stats_event_write_string8(event, gEntityNames.at(result.powerEntityId).c_str()); stats_event_write_string8(event, gStateNames.at(result.powerEntityId) .at(stateResidency.powerEntityStateId) .c_str()); stats_event_write_int64(event, stateResidency.totalStateEntryCount); stats_event_write_int64(event, stateResidency.totalTimeInStateMs); stats_event_build(event); } } success = true; Loading @@ -222,8 +212,10 @@ static bool getIPowerStatsDataLocked(vector<shared_ptr<LogEvent>>* data) { // Intentionally not returning early here. // bool success determines if this succeeded or not. checkResultLocked(ret, __func__); return success; if (!success) { return STATS_PULL_SKIP; } return STATS_PULL_SUCCESS; } // The caller must be holding gPowerHalMutex. Loading Loading @@ -252,48 +244,43 @@ static bool getPowerHalLocked() { } // The caller must be holding gPowerHalMutex. static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { static status_pull_atom_return_t getIPowerDataLocked(int32_t atomTag, pulled_stats_event_list* data) { using android::hardware::power::V1_0::Status; if(!getPowerHalLocked()) { return false; return STATS_PULL_SKIP; } int64_t wallClockTimestampNs = getWallClockNs(); int64_t elapsedTimestampNs = getElapsedRealtimeNs(); Return<void> ret; ret = gPowerHalV1_0->getPlatformLowPowerStats( [&data, wallClockTimestampNs, elapsedTimestampNs] (hidl_vec<PowerStatePlatformSleepState> states, Status status) { [&data](hidl_vec<PowerStatePlatformSleepState> states, Status status) { if (status != Status::SUCCESS) return; for (size_t i = 0; i < states.size(); i++) { const PowerStatePlatformSleepState& state = states[i]; auto statePtr = make_shared<LogEvent>( android::util::SUBSYSTEM_SLEEP_STATE, wallClockTimestampNs, elapsedTimestampNs); statePtr->write(state.name); statePtr->write(""); statePtr->write(state.totalTransitions); statePtr->write(state.residencyInMsecSinceBoot); statePtr->init(); data->push_back(statePtr); VLOG("powerstate: %s, %lld, %lld, %d", state.name.c_str(), stats_event* event = add_stats_event_to_pull_data(data); stats_event_set_atom_id(event, android::util::SUBSYSTEM_SLEEP_STATE); stats_event_write_string8(event, state.name.c_str()); stats_event_write_string8(event, ""); stats_event_write_int64(event, state.totalTransitions); stats_event_write_int64(event, state.residencyInMsecSinceBoot); stats_event_build(event); ALOGV("powerstate: %s, %lld, %lld, %d", state.name.c_str(), (long long)state.residencyInMsecSinceBoot, (long long)state.totalTransitions, state.supportedOnlyInSuspend ? 1 : 0); for (const auto& voter : state.voters) { auto voterPtr = make_shared<LogEvent>( android::util::SUBSYSTEM_SLEEP_STATE, wallClockTimestampNs, elapsedTimestampNs); voterPtr->write(state.name); voterPtr->write(voter.name); voterPtr->write(voter.totalNumberOfTimesVotedSinceBoot); voterPtr->write(voter.totalTimeInMsecVotedForSinceBoot); voterPtr->init(); data->push_back(voterPtr); VLOG("powerstatevoter: %s, %s, %lld, %lld", state.name.c_str(), stats_event* event = add_stats_event_to_pull_data(data); stats_event_set_atom_id(event, android::util::SUBSYSTEM_SLEEP_STATE); stats_event_write_string8(event, state.name.c_str()); stats_event_write_string8(event, voter.name.c_str()); stats_event_write_int64(event, voter.totalNumberOfTimesVotedSinceBoot); stats_event_write_int64(event, voter.totalTimeInMsecVotedForSinceBoot); stats_event_build(event); ALOGV("powerstatevoter: %s, %s, %lld, %lld", state.name.c_str(), voter.name.c_str(), (long long)voter.totalTimeInMsecVotedForSinceBoot, (long long)voter.totalNumberOfTimesVotedSinceBoot); Loading @@ -301,7 +288,7 @@ static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { } }); if (!checkResultLocked(ret, __func__)) { return false; return STATS_PULL_SKIP; } // Trying to cast to IPower 1.1, this will succeed only for devices supporting 1.1 Loading @@ -309,8 +296,7 @@ static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { android::hardware::power::V1_1::IPower::castFrom(gPowerHalV1_0); if (gPowerHal_1_1 != nullptr) { ret = gPowerHal_1_1->getSubsystemLowPowerStats( [&data, wallClockTimestampNs, elapsedTimestampNs] (hidl_vec<PowerStateSubsystem> subsystems, Status status) { [&data](hidl_vec<PowerStateSubsystem> subsystems, Status status) { if (status != Status::SUCCESS) return; if (subsystems.size() > 0) { Loading @@ -319,16 +305,16 @@ static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { for (size_t j = 0; j < subsystem.states.size(); j++) { const PowerStateSubsystemSleepState& state = subsystem.states[j]; auto subsystemStatePtr = make_shared<LogEvent>( android::util::SUBSYSTEM_SLEEP_STATE, wallClockTimestampNs, elapsedTimestampNs); subsystemStatePtr->write(subsystem.name); subsystemStatePtr->write(state.name); subsystemStatePtr->write(state.totalTransitions); subsystemStatePtr->write(state.residencyInMsecSinceBoot); subsystemStatePtr->init(); data->push_back(subsystemStatePtr); VLOG("subsystemstate: %s, %s, %lld, %lld, %lld", stats_event* event = add_stats_event_to_pull_data(data); stats_event_set_atom_id(event, android::util::SUBSYSTEM_SLEEP_STATE); stats_event_write_string8(event, subsystem.name.c_str()); stats_event_write_string8(event, state.name.c_str()); stats_event_write_int64(event, state.totalTransitions); stats_event_write_int64(event, state.residencyInMsecSinceBoot); stats_event_build(event); ALOGV("subsystemstate: %s, %s, %lld, %lld, %lld", subsystem.name.c_str(), state.name.c_str(), (long long)state.residencyInMsecSinceBoot, (long long)state.totalTransitions, Loading @@ -338,12 +324,14 @@ static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { } }); } return true; return STATS_PULL_SUCCESS; } // The caller must be holding gPowerHalMutex. std::function<bool(vector<shared_ptr<LogEvent>>* data)> getPullerLocked() { std::function<bool(vector<shared_ptr<LogEvent>>* data)> ret = {}; std::function<status_pull_atom_return_t(int32_t atomTag, pulled_stats_event_list* data)> getPullerLocked() { std::function<status_pull_atom_return_t(int32_t atomTag, pulled_stats_event_list * data)> ret = {}; // First see if power.stats HAL is available. Fall back to power HAL if // power.stats HAL is unavailable. Loading @@ -358,7 +346,8 @@ std::function<bool(vector<shared_ptr<LogEvent>>* data)> getPullerLocked() { return ret; } bool SubsystemSleepStatePuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { status_pull_atom_return_t SubsystemSleepStatePuller::Pull(int32_t atomTag, pulled_stats_event_list* data) { std::lock_guard<std::mutex> lock(gPowerHalMutex); if(!gPuller) { Loading @@ -366,13 +355,13 @@ bool SubsystemSleepStatePuller::PullInternal(vector<shared_ptr<LogEvent>>* data) } if(gPuller) { return gPuller(data); return gPuller(atomTag, data); } ALOGE("Unable to load Power Hal or power.stats HAL"); return false; return STATS_PULL_SKIP; } } // namespace statsd } // namespace os } // namespace stats } // namespace server } // namespace android Loading
cmds/statsd/Android.bp +0 −4 Original line number Diff line number Diff line Loading @@ -71,7 +71,6 @@ cc_defaults { "src/external/StatsCallbackPuller.cpp", "src/external/StatsPuller.cpp", "src/external/StatsPullerManager.cpp", "src/external/SubsystemSleepStatePuller.cpp", "src/external/TrainInfoPuller.cpp", "src/FieldValue.cpp", "src/guardrail/StatsdStats.cpp", Loading Loading @@ -120,9 +119,6 @@ cc_defaults { static_libs: [ "android.frameworks.stats@1.0", "android.hardware.power.stats@1.0", "android.hardware.power@1.0", "android.hardware.power@1.1", "libbase", "libcutils", "liblog", Loading
cmds/statsd/src/external/StatsPullerManager.cpp +0 −4 Original line number Diff line number Diff line Loading @@ -34,7 +34,6 @@ #include "../statscompanion_util.h" #include "GpuStatsPuller.h" #include "StatsCallbackPuller.h" #include "SubsystemSleepStatePuller.h" #include "TrainInfoPuller.h" #include "statslog.h" Loading @@ -54,9 +53,6 @@ const int64_t NO_ALARM_UPDATE = INT64_MAX; StatsPullerManager::StatsPullerManager() : kAllPullAtomInfo({ // subsystem_sleep_state {{.atomTag = android::util::SUBSYSTEM_SLEEP_STATE}, new SubsystemSleepStatePuller()}, // TrainInfo. {{.atomTag = android::util::TRAIN_INFO}, new TrainInfoPuller()}, Loading
services/core/jni/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ cc_library_static { "BroadcastRadio/convert.cpp", "BroadcastRadio/regions.cpp", "stats/PowerStatsPuller.cpp", "stats/SubsystemSleepStatePuller.cpp", "com_android_server_am_BatteryStatsService.cpp", "com_android_server_connectivity_Vpn.cpp", "com_android_server_ConsumerIrService.cpp", Loading
services/core/jni/com_android_server_stats_pull_StatsPullAtomService.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -24,10 +24,12 @@ #include <statslog.h> #include "stats/PowerStatsPuller.h" #include "stats/SubsystemSleepStatePuller.h" namespace android { static server::stats::PowerStatsPuller gPowerStatsPuller; static server::stats::SubsystemSleepStatePuller gSubsystemSleepStatePuller; static status_pull_atom_return_t onDevicePowerMeasurementCallback(int32_t atom_tag, pulled_stats_event_list* data, Loading @@ -35,6 +37,12 @@ static status_pull_atom_return_t onDevicePowerMeasurementCallback(int32_t atom_t return gPowerStatsPuller.Pull(atom_tag, data); } static status_pull_atom_return_t subsystemSleepStateCallback(int32_t atom_tag, pulled_stats_event_list* data, void* cookie) { return gSubsystemSleepStatePuller.Pull(atom_tag, data); } static void nativeInit(JNIEnv* env, jobject javaObject) { // on device power measurement gPowerStatsPuller = server::stats::PowerStatsPuller(); Loading @@ -42,6 +50,13 @@ static void nativeInit(JNIEnv* env, jobject javaObject) { onDevicePowerMeasurementCallback, /* metadata= */ nullptr, /* cookie= */ nullptr); // subsystem sleep state gSubsystemSleepStatePuller = server::stats::SubsystemSleepStatePuller(); register_stats_pull_atom_callback(android::util::SUBSYSTEM_SLEEP_STATE, subsystemSleepStateCallback, /* metadata= */ nullptr, /* cookie= */ nullptr); } static const JNINativeMethod sMethods[] = {{"nativeInit", "()V", (void*)nativeInit}}; Loading
cmds/statsd/src/external/SubsystemSleepStatePuller.cpp→services/core/jni/stats/SubsystemSleepStatePuller.cpp +107 −118 Original line number Diff line number Diff line Loading @@ -15,7 +15,10 @@ */ #define DEBUG false // STOPSHIP if true #include "Log.h" #define LOG_TAG "SubsystemSleepStatePuller" #include <log/log.h> #include <statslog.h> #include <android/hardware/power/1.0/IPower.h> #include <android/hardware/power/1.1/IPower.h> Loading @@ -32,13 +35,8 @@ #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include "external/SubsystemSleepStatePuller.h" #include "external/StatsPuller.h" #include <unordered_map> #include "SubsystemSleepStatePuller.h" #include "logd/LogEvent.h" #include "statslog.h" #include "stats_log_util.h" using android::hardware::hidl_vec; using android::hardware::power::V1_0::IPower; Loading @@ -53,14 +51,12 @@ using android::hardware::power::stats::V1_0::PowerEntityStateSpace; using android::hardware::Return; using android::hardware::Void; using std::make_shared; using std::shared_ptr; namespace android { namespace os { namespace statsd { namespace server { namespace stats { static std::function<bool(vector<shared_ptr<LogEvent>>* data)> gPuller = {}; static std::function<status_pull_atom_return_t(int32_t atomTag, pulled_stats_event_list* data)> gPuller = {}; static sp<android::hardware::power::V1_0::IPower> gPowerHalV1_0 = nullptr; static sp<android::hardware::power::V1_1::IPower> gPowerHalV1_1 = nullptr; Loading Loading @@ -91,9 +87,7 @@ struct SubsystemSleepStatePullerDeathRecipient : virtual public hardware::hidl_d static sp<SubsystemSleepStatePullerDeathRecipient> gDeathRecipient = new SubsystemSleepStatePullerDeathRecipient(); SubsystemSleepStatePuller::SubsystemSleepStatePuller() : StatsPuller(android::util::SUBSYSTEM_SLEEP_STATE) { } SubsystemSleepStatePuller::SubsystemSleepStatePuller() {} // The caller must be holding gPowerHalMutex. static bool checkResultLocked(const Return<void> &ret, const char* function) { Loading Loading @@ -182,39 +176,35 @@ static bool getPowerStatsHalLocked() { } // The caller must be holding gPowerHalMutex. static bool getIPowerStatsDataLocked(vector<shared_ptr<LogEvent>>* data) { static status_pull_atom_return_t getIPowerStatsDataLocked(int32_t atomTag, pulled_stats_event_list* data) { using android::hardware::power::stats::V1_0::Status; if(!getPowerStatsHalLocked()) { return false; return STATS_PULL_SKIP; } int64_t wallClockTimestampNs = getWallClockNs(); int64_t elapsedTimestampNs = getElapsedRealtimeNs(); // Get power entity state residency data bool success = false; Return<void> ret = gPowerStatsHalV1_0->getPowerEntityStateResidencyData({}, [&data, &success, wallClockTimestampNs, elapsedTimestampNs] (auto results, auto status) { Return<void> ret = gPowerStatsHalV1_0->getPowerEntityStateResidencyData( {}, [&data, &success](auto results, auto status) { if (status == Status::NOT_SUPPORTED) { ALOGW("getPowerEntityStateResidencyData is not supported"); success = false; return; } for (auto result : results) { for (auto stateResidency : result.stateResidencyData) { auto statePtr = make_shared<LogEvent>( android::util::SUBSYSTEM_SLEEP_STATE, wallClockTimestampNs, elapsedTimestampNs); statePtr->write(gEntityNames.at(result.powerEntityId)); statePtr->write(gStateNames.at(result.powerEntityId) .at(stateResidency.powerEntityStateId)); statePtr->write(stateResidency.totalStateEntryCount); statePtr->write(stateResidency.totalTimeInStateMs); statePtr->init(); data->emplace_back(statePtr); stats_event* event = add_stats_event_to_pull_data(data); stats_event_set_atom_id(event, android::util::SUBSYSTEM_SLEEP_STATE); stats_event_write_string8(event, gEntityNames.at(result.powerEntityId).c_str()); stats_event_write_string8(event, gStateNames.at(result.powerEntityId) .at(stateResidency.powerEntityStateId) .c_str()); stats_event_write_int64(event, stateResidency.totalStateEntryCount); stats_event_write_int64(event, stateResidency.totalTimeInStateMs); stats_event_build(event); } } success = true; Loading @@ -222,8 +212,10 @@ static bool getIPowerStatsDataLocked(vector<shared_ptr<LogEvent>>* data) { // Intentionally not returning early here. // bool success determines if this succeeded or not. checkResultLocked(ret, __func__); return success; if (!success) { return STATS_PULL_SKIP; } return STATS_PULL_SUCCESS; } // The caller must be holding gPowerHalMutex. Loading Loading @@ -252,48 +244,43 @@ static bool getPowerHalLocked() { } // The caller must be holding gPowerHalMutex. static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { static status_pull_atom_return_t getIPowerDataLocked(int32_t atomTag, pulled_stats_event_list* data) { using android::hardware::power::V1_0::Status; if(!getPowerHalLocked()) { return false; return STATS_PULL_SKIP; } int64_t wallClockTimestampNs = getWallClockNs(); int64_t elapsedTimestampNs = getElapsedRealtimeNs(); Return<void> ret; ret = gPowerHalV1_0->getPlatformLowPowerStats( [&data, wallClockTimestampNs, elapsedTimestampNs] (hidl_vec<PowerStatePlatformSleepState> states, Status status) { [&data](hidl_vec<PowerStatePlatformSleepState> states, Status status) { if (status != Status::SUCCESS) return; for (size_t i = 0; i < states.size(); i++) { const PowerStatePlatformSleepState& state = states[i]; auto statePtr = make_shared<LogEvent>( android::util::SUBSYSTEM_SLEEP_STATE, wallClockTimestampNs, elapsedTimestampNs); statePtr->write(state.name); statePtr->write(""); statePtr->write(state.totalTransitions); statePtr->write(state.residencyInMsecSinceBoot); statePtr->init(); data->push_back(statePtr); VLOG("powerstate: %s, %lld, %lld, %d", state.name.c_str(), stats_event* event = add_stats_event_to_pull_data(data); stats_event_set_atom_id(event, android::util::SUBSYSTEM_SLEEP_STATE); stats_event_write_string8(event, state.name.c_str()); stats_event_write_string8(event, ""); stats_event_write_int64(event, state.totalTransitions); stats_event_write_int64(event, state.residencyInMsecSinceBoot); stats_event_build(event); ALOGV("powerstate: %s, %lld, %lld, %d", state.name.c_str(), (long long)state.residencyInMsecSinceBoot, (long long)state.totalTransitions, state.supportedOnlyInSuspend ? 1 : 0); for (const auto& voter : state.voters) { auto voterPtr = make_shared<LogEvent>( android::util::SUBSYSTEM_SLEEP_STATE, wallClockTimestampNs, elapsedTimestampNs); voterPtr->write(state.name); voterPtr->write(voter.name); voterPtr->write(voter.totalNumberOfTimesVotedSinceBoot); voterPtr->write(voter.totalTimeInMsecVotedForSinceBoot); voterPtr->init(); data->push_back(voterPtr); VLOG("powerstatevoter: %s, %s, %lld, %lld", state.name.c_str(), stats_event* event = add_stats_event_to_pull_data(data); stats_event_set_atom_id(event, android::util::SUBSYSTEM_SLEEP_STATE); stats_event_write_string8(event, state.name.c_str()); stats_event_write_string8(event, voter.name.c_str()); stats_event_write_int64(event, voter.totalNumberOfTimesVotedSinceBoot); stats_event_write_int64(event, voter.totalTimeInMsecVotedForSinceBoot); stats_event_build(event); ALOGV("powerstatevoter: %s, %s, %lld, %lld", state.name.c_str(), voter.name.c_str(), (long long)voter.totalTimeInMsecVotedForSinceBoot, (long long)voter.totalNumberOfTimesVotedSinceBoot); Loading @@ -301,7 +288,7 @@ static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { } }); if (!checkResultLocked(ret, __func__)) { return false; return STATS_PULL_SKIP; } // Trying to cast to IPower 1.1, this will succeed only for devices supporting 1.1 Loading @@ -309,8 +296,7 @@ static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { android::hardware::power::V1_1::IPower::castFrom(gPowerHalV1_0); if (gPowerHal_1_1 != nullptr) { ret = gPowerHal_1_1->getSubsystemLowPowerStats( [&data, wallClockTimestampNs, elapsedTimestampNs] (hidl_vec<PowerStateSubsystem> subsystems, Status status) { [&data](hidl_vec<PowerStateSubsystem> subsystems, Status status) { if (status != Status::SUCCESS) return; if (subsystems.size() > 0) { Loading @@ -319,16 +305,16 @@ static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { for (size_t j = 0; j < subsystem.states.size(); j++) { const PowerStateSubsystemSleepState& state = subsystem.states[j]; auto subsystemStatePtr = make_shared<LogEvent>( android::util::SUBSYSTEM_SLEEP_STATE, wallClockTimestampNs, elapsedTimestampNs); subsystemStatePtr->write(subsystem.name); subsystemStatePtr->write(state.name); subsystemStatePtr->write(state.totalTransitions); subsystemStatePtr->write(state.residencyInMsecSinceBoot); subsystemStatePtr->init(); data->push_back(subsystemStatePtr); VLOG("subsystemstate: %s, %s, %lld, %lld, %lld", stats_event* event = add_stats_event_to_pull_data(data); stats_event_set_atom_id(event, android::util::SUBSYSTEM_SLEEP_STATE); stats_event_write_string8(event, subsystem.name.c_str()); stats_event_write_string8(event, state.name.c_str()); stats_event_write_int64(event, state.totalTransitions); stats_event_write_int64(event, state.residencyInMsecSinceBoot); stats_event_build(event); ALOGV("subsystemstate: %s, %s, %lld, %lld, %lld", subsystem.name.c_str(), state.name.c_str(), (long long)state.residencyInMsecSinceBoot, (long long)state.totalTransitions, Loading @@ -338,12 +324,14 @@ static bool getIPowerDataLocked(vector<shared_ptr<LogEvent>>* data) { } }); } return true; return STATS_PULL_SUCCESS; } // The caller must be holding gPowerHalMutex. std::function<bool(vector<shared_ptr<LogEvent>>* data)> getPullerLocked() { std::function<bool(vector<shared_ptr<LogEvent>>* data)> ret = {}; std::function<status_pull_atom_return_t(int32_t atomTag, pulled_stats_event_list* data)> getPullerLocked() { std::function<status_pull_atom_return_t(int32_t atomTag, pulled_stats_event_list * data)> ret = {}; // First see if power.stats HAL is available. Fall back to power HAL if // power.stats HAL is unavailable. Loading @@ -358,7 +346,8 @@ std::function<bool(vector<shared_ptr<LogEvent>>* data)> getPullerLocked() { return ret; } bool SubsystemSleepStatePuller::PullInternal(vector<shared_ptr<LogEvent>>* data) { status_pull_atom_return_t SubsystemSleepStatePuller::Pull(int32_t atomTag, pulled_stats_event_list* data) { std::lock_guard<std::mutex> lock(gPowerHalMutex); if(!gPuller) { Loading @@ -366,13 +355,13 @@ bool SubsystemSleepStatePuller::PullInternal(vector<shared_ptr<LogEvent>>* data) } if(gPuller) { return gPuller(data); return gPuller(atomTag, data); } ALOGE("Unable to load Power Hal or power.stats HAL"); return false; return STATS_PULL_SKIP; } } // namespace statsd } // namespace os } // namespace stats } // namespace server } // namespace android