Loading healthd/BatteryMonitor.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -348,6 +348,7 @@ int BatteryMonitor::getChargeStatus() { status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) { status_t ret = BAD_VALUE; std::string buf; val->valueInt64 = LONG_MIN; Loading Loading @@ -400,6 +401,15 @@ status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) { } break; case BATTERY_PROP_BATTERY_STATUS: if (mAlwaysPluggedDevice) { val->valueInt64 = BATTERY_STATUS_CHARGING; } else { val->valueInt64 = getChargeStatus(); } ret = NO_ERROR; break; default: break; } Loading storaged/Android.mk +16 −7 Original line number Diff line number Diff line Loading @@ -2,11 +2,21 @@ LOCAL_PATH := $(call my-dir) LIBSTORAGED_SHARED_LIBRARIES := libbinder libbase libutils libcutils liblog libsysutils libcap libpackagelistparser LIBSTORAGED_SHARED_LIBRARIES := \ libbinder \ libbase \ libutils \ libcutils \ liblog \ libsysutils \ libcap \ libpackagelistparser \ libbatteryservice \ include $(CLEAR_VARS) LOCAL_SRC_FILES := storaged.cpp \ LOCAL_SRC_FILES := \ storaged.cpp \ storaged_service.cpp \ storaged_utils.cpp \ storaged_uid_monitor.cpp \ Loading @@ -17,7 +27,6 @@ LOCAL_CFLAGS := -Werror LOCAL_C_INCLUDES := $(LOCAL_PATH)/include external/googletest/googletest/include LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include LOCAL_SHARED_LIBRARIES := $(LIBSTORAGED_SHARED_LIBRARIES) include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) Loading storaged/include/storaged.h +11 −4 Original line number Diff line number Diff line Loading @@ -26,8 +26,12 @@ #include <unordered_map> #include <vector> #include <batteryservice/IBatteryPropertiesListener.h> #include "storaged_uid_monitor.h" using namespace android; #define FRIEND_TEST(test_case_name, test_name) \ friend class test_case_name##_##test_name##_Test Loading Loading @@ -268,7 +272,7 @@ struct storaged_config { int event_time_check_usec; // check how much cputime spent in event loop }; class storaged_t { class storaged_t : public BnBatteryPropertiesListener { private: time_t mTimer; storaged_config mConfig; Loading @@ -294,11 +298,14 @@ public: } std::unordered_map<uint32_t, struct uid_info> get_uids(void) { return mUidm.get_uids(); return mUidm.get_uid_io_stats(); } std::vector<struct uid_event> get_uid_events(int hours) { return mUidm.dump_events(hours); std::map<uint64_t, std::vector<struct uid_record>> get_uid_records(int hours) { return mUidm.dump(hours); } void init_battery_service(); virtual void batteryPropertiesChanged(struct BatteryProperties props); }; // Eventlog tag Loading storaged/include/storaged_uid_monitor.h +50 −26 Original line number Diff line number Diff line Loading @@ -23,10 +23,22 @@ #include <unordered_map> #include <vector> enum { UID_FOREGROUND = 0, UID_BACKGROUND = 1, UID_STATS_SIZE = 2 enum uid_stat_t { FOREGROUND = 0, BACKGROUND = 1, UID_STATS = 2 }; enum charger_stat_t { CHARGER_OFF = 0, CHARGER_ON = 1, CHARGER_STATS = 2 }; enum io_type_t { READ = 0, WRITE = 1, IO_TYPES = 2 }; struct uid_io_stats { Loading @@ -39,39 +51,51 @@ struct uid_io_stats { struct uid_info { uint32_t uid; // user id std::string name; // package name struct uid_io_stats io[UID_STATS_SIZE]; // [0]:foreground [1]:background struct uid_io_stats io[UID_STATS]; // [0]:foreground [1]:background }; struct uid_event { struct uid_io_usage { uint64_t bytes[IO_TYPES][UID_STATS][CHARGER_STATS]; }; struct uid_record { std::string name; uint64_t fg_read_bytes; uint64_t fg_write_bytes; uint64_t bg_read_bytes; uint64_t bg_write_bytes; uint64_t ts; bool operator< (const struct uid_event& e) const { return ts < e.ts; } struct uid_io_usage ios; }; class uid_monitor { private: std::unordered_map<uint32_t, struct uid_info> last_uids; std::vector<struct uid_event> events; sem_t events_lock; void set_last_uids(std::unordered_map<uint32_t, struct uid_info>&& uids, uint64_t ts); int interval; // monitor interval in seconds int threshold; // monitor threshold in bytes uint64_t last_report_ts; // timestamp of last report in nsec // last dump from /proc/uid_io/stats, uid -> uid_info std::unordered_map<uint32_t, struct uid_info> last_uid_io_stats; // current io usage for next report, app name -> uid_io_usage std::unordered_map<std::string, struct uid_io_usage> curr_io_stats; // io usage records, timestamp -> vector of events std::map<uint64_t, std::vector<struct uid_record>> records; // charger ON/OFF charger_stat_t charger_stat; // protects curr_io_stats, last_uid_io_stats, records and charger_stat sem_t um_lock; // reads from /proc/uid_io/stats std::unordered_map<uint32_t, struct uid_info> get_uid_io_stats_locked(); // flushes curr_io_stats to records void add_records_locked(uint64_t curr_ts); // updates curr_io_stats and set last_uid_io_stats void update_curr_io_stats_locked(); public: uid_monitor(); ~uid_monitor(); void set_periodic_chores_params(int intvl, int thold) { interval = intvl; threshold = thold; } int get_periodic_chores_interval() { return interval; } std::unordered_map<uint32_t, struct uid_info> get_uids(); // called by storaged main thread void init(charger_stat_t stat); // called by storaged -u std::unordered_map<uint32_t, struct uid_info> get_uid_io_stats(); // called by dumpsys std::map<uint64_t, std::vector<struct uid_record>> dump(int hours); // called by battery properties listener void set_charger_state(charger_stat_t stat); // called by storaged periodic_chore void report(); void add_events(const std::vector<struct uid_event>& new_events, uint64_t curr_ts); std::vector<struct uid_event> dump_events(int hours); }; #endif /* _STORAGED_UID_MONITOR_H_ */ storaged/main.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -88,6 +88,8 @@ static int drop_privs() { void* storaged_main(void* s) { storaged_t* storaged = (storaged_t*)s; storaged->init_battery_service(); LOG_TO(SYSTEM, INFO) << "storaged: Start"; for (;;) { Loading Loading
healthd/BatteryMonitor.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -348,6 +348,7 @@ int BatteryMonitor::getChargeStatus() { status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) { status_t ret = BAD_VALUE; std::string buf; val->valueInt64 = LONG_MIN; Loading Loading @@ -400,6 +401,15 @@ status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) { } break; case BATTERY_PROP_BATTERY_STATUS: if (mAlwaysPluggedDevice) { val->valueInt64 = BATTERY_STATUS_CHARGING; } else { val->valueInt64 = getChargeStatus(); } ret = NO_ERROR; break; default: break; } Loading
storaged/Android.mk +16 −7 Original line number Diff line number Diff line Loading @@ -2,11 +2,21 @@ LOCAL_PATH := $(call my-dir) LIBSTORAGED_SHARED_LIBRARIES := libbinder libbase libutils libcutils liblog libsysutils libcap libpackagelistparser LIBSTORAGED_SHARED_LIBRARIES := \ libbinder \ libbase \ libutils \ libcutils \ liblog \ libsysutils \ libcap \ libpackagelistparser \ libbatteryservice \ include $(CLEAR_VARS) LOCAL_SRC_FILES := storaged.cpp \ LOCAL_SRC_FILES := \ storaged.cpp \ storaged_service.cpp \ storaged_utils.cpp \ storaged_uid_monitor.cpp \ Loading @@ -17,7 +27,6 @@ LOCAL_CFLAGS := -Werror LOCAL_C_INCLUDES := $(LOCAL_PATH)/include external/googletest/googletest/include LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include LOCAL_SHARED_LIBRARIES := $(LIBSTORAGED_SHARED_LIBRARIES) include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) Loading
storaged/include/storaged.h +11 −4 Original line number Diff line number Diff line Loading @@ -26,8 +26,12 @@ #include <unordered_map> #include <vector> #include <batteryservice/IBatteryPropertiesListener.h> #include "storaged_uid_monitor.h" using namespace android; #define FRIEND_TEST(test_case_name, test_name) \ friend class test_case_name##_##test_name##_Test Loading Loading @@ -268,7 +272,7 @@ struct storaged_config { int event_time_check_usec; // check how much cputime spent in event loop }; class storaged_t { class storaged_t : public BnBatteryPropertiesListener { private: time_t mTimer; storaged_config mConfig; Loading @@ -294,11 +298,14 @@ public: } std::unordered_map<uint32_t, struct uid_info> get_uids(void) { return mUidm.get_uids(); return mUidm.get_uid_io_stats(); } std::vector<struct uid_event> get_uid_events(int hours) { return mUidm.dump_events(hours); std::map<uint64_t, std::vector<struct uid_record>> get_uid_records(int hours) { return mUidm.dump(hours); } void init_battery_service(); virtual void batteryPropertiesChanged(struct BatteryProperties props); }; // Eventlog tag Loading
storaged/include/storaged_uid_monitor.h +50 −26 Original line number Diff line number Diff line Loading @@ -23,10 +23,22 @@ #include <unordered_map> #include <vector> enum { UID_FOREGROUND = 0, UID_BACKGROUND = 1, UID_STATS_SIZE = 2 enum uid_stat_t { FOREGROUND = 0, BACKGROUND = 1, UID_STATS = 2 }; enum charger_stat_t { CHARGER_OFF = 0, CHARGER_ON = 1, CHARGER_STATS = 2 }; enum io_type_t { READ = 0, WRITE = 1, IO_TYPES = 2 }; struct uid_io_stats { Loading @@ -39,39 +51,51 @@ struct uid_io_stats { struct uid_info { uint32_t uid; // user id std::string name; // package name struct uid_io_stats io[UID_STATS_SIZE]; // [0]:foreground [1]:background struct uid_io_stats io[UID_STATS]; // [0]:foreground [1]:background }; struct uid_event { struct uid_io_usage { uint64_t bytes[IO_TYPES][UID_STATS][CHARGER_STATS]; }; struct uid_record { std::string name; uint64_t fg_read_bytes; uint64_t fg_write_bytes; uint64_t bg_read_bytes; uint64_t bg_write_bytes; uint64_t ts; bool operator< (const struct uid_event& e) const { return ts < e.ts; } struct uid_io_usage ios; }; class uid_monitor { private: std::unordered_map<uint32_t, struct uid_info> last_uids; std::vector<struct uid_event> events; sem_t events_lock; void set_last_uids(std::unordered_map<uint32_t, struct uid_info>&& uids, uint64_t ts); int interval; // monitor interval in seconds int threshold; // monitor threshold in bytes uint64_t last_report_ts; // timestamp of last report in nsec // last dump from /proc/uid_io/stats, uid -> uid_info std::unordered_map<uint32_t, struct uid_info> last_uid_io_stats; // current io usage for next report, app name -> uid_io_usage std::unordered_map<std::string, struct uid_io_usage> curr_io_stats; // io usage records, timestamp -> vector of events std::map<uint64_t, std::vector<struct uid_record>> records; // charger ON/OFF charger_stat_t charger_stat; // protects curr_io_stats, last_uid_io_stats, records and charger_stat sem_t um_lock; // reads from /proc/uid_io/stats std::unordered_map<uint32_t, struct uid_info> get_uid_io_stats_locked(); // flushes curr_io_stats to records void add_records_locked(uint64_t curr_ts); // updates curr_io_stats and set last_uid_io_stats void update_curr_io_stats_locked(); public: uid_monitor(); ~uid_monitor(); void set_periodic_chores_params(int intvl, int thold) { interval = intvl; threshold = thold; } int get_periodic_chores_interval() { return interval; } std::unordered_map<uint32_t, struct uid_info> get_uids(); // called by storaged main thread void init(charger_stat_t stat); // called by storaged -u std::unordered_map<uint32_t, struct uid_info> get_uid_io_stats(); // called by dumpsys std::map<uint64_t, std::vector<struct uid_record>> dump(int hours); // called by battery properties listener void set_charger_state(charger_stat_t stat); // called by storaged periodic_chore void report(); void add_events(const std::vector<struct uid_event>& new_events, uint64_t curr_ts); std::vector<struct uid_event> dump_events(int hours); }; #endif /* _STORAGED_UID_MONITOR_H_ */
storaged/main.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -88,6 +88,8 @@ static int drop_privs() { void* storaged_main(void* s) { storaged_t* storaged = (storaged_t*)s; storaged->init_battery_service(); LOG_TO(SYSTEM, INFO) << "storaged: Start"; for (;;) { Loading