manafa.parsing.batteryStats package¶
Submodules¶
manafa.parsing.batteryStats.BatteryStatsConstants module¶
manafa.parsing.batteryStats.BatteryStatsParser module¶
This module contains ENUMs that store state values of batterystats events.
BatteryStatsConstants contains constants associated with batterystats events and respective meaning.
- class manafa.parsing.batteryStats.BatteryStatsParser.BatteryEvent(time=0.0, vals={})[source]¶
Bases:
object
Class to store information information parsed from the lines of batterystats history events.
This class stores information of one or more lines (when consecutive lines have the same timestamp) of batterystats history events.
- time¶
Stores timestamp of event (s.ms).
- Type
float
- updates¶
stores component updates (components referred in power_profile.xml) registered in time timestamp.
- Type
dict
- current¶
stores instant current being consumed by each component.
- Type
dict
- concurrentUpdates¶
consumption.
- Type
dict
- add_events(new_events)[source]¶
Adds a set of events to the current state. :param new_events: set of events. :type new_events: dict
- get_current_of_batStatEvent()[source]¶
gets total current being consumed by the current state of hardware usage. :param state: timestamp of event (s.ms). :type state: str
- Returns
total current being consumed.
- Return type
float
- class manafa.parsing.batteryStats.BatteryStatsParser.BatteryStatsParser(powerProfile=None, timezone='EST', def_file='/Users/ruirua/repos/emanafa/manafa/resources/batteryStats/BatteryStatus.json', android_version=10)[source]¶
Bases:
object
Class that handles parsing of batterystats history events
This class parses and batterystats history events from files parsed using parseFile function. It starts by load information contained in the device power profile file and also the current state values known by the profiler, stored in definitions attribute.
- events¶
stores BatteryEvents by order of occurence.
- Type
list
ofBatteryEvent
- definitions¶
stores definitions ok known states support by batterystats and manafa.
- Type
dict
- powerProfile¶
stores information parsed from power profile file.
- Type
PowerProfile
- android_version¶
Android release version.
- Type
int
- start_time¶
initial timestamp inferred from first line of batstats history.
- Type
int
- timezone¶
current device timezone.
- Type
str
- add_update(time, bat_events)[source]¶
Adds new event updates to current state.
- Parameters
time (int) – timestamp of new events.
bat_events (
list
ofdict
) –
- determinate_component_current(bt_event, comp_name, possible_states)[source]¶
calculates current being consumed during bt_event by component identified by comp_name.
- Parameters
bt_event – event.
comp_name – component name.
possible_states – possible states of the component.
- Returns
current being consumed.
- Return type
float
- estimate_current_consumption(bt_event)[source]¶
estimates current power being consumed by event. :param bt_event: key of the event. :type bt_event: str
- get_CPU_samples_in_between(start_time, end_time)[source]¶
returns cpu states recorded between start and end time. :param start_time: start timestamp. :type start_time: int :param end_time: end timestamp. :type end_time: int
- Returns
states occurred.
- Return type
dict
- get_closest_pair(time)[source]¶
returns closest events of a given timestamp time. :param time: timestamp. :type time: float
- Returns
index of the closest events.
- Return type
int, int
- get_definition_val(key, val='')[source]¶
return value of component from key and opt val. :param key: key that identifies component. :type key: str :param val: optional sub key. :type val: str
- Returns
value.
- Return type
int
- get_events_in_between(start_time, end_time)[source]¶
get batstat events occured between start_time and end_time. :param start_time: start timestamp. :type start_time: int :param end_time: end timestamp. :type end_time: int
- Returns
events occurred.
- Return type
dict
- is_trival(key)[source]¶
check if is a component with more than 2 values associated. :param key: component key.
- Returns
result of check.
- Return type
bool
- static load_definition_file(def_file)[source]¶
loads definitions attribute from json file :param def_file: filepath. :type def_file: str
- parse_file(filepath)[source]¶
parses events ands stores event from file with output from dumpsys batterystats command. :param filepath: output filepath.
Module contents¶
This module contains Classes to parse and manipulate information coming from the BatteryStats Android Service.
BatteryStatsConstants contains constants associated with batterystats events and respective meaning. BatteryStatsParser.py contains BatteryStatsParser and utils to parse dumpsys batterystats output and obtain/filter events occured during given time ranges.