Class: DeviceAPI::Android::Plugin::Memory
- Inherits:
-
Object
- Object
- DeviceAPI::Android::Plugin::Memory
- Defined in:
- lib/device_api/android/plugins/memory.rb
Overview
Class used to provide information about process memory usage and device memory usage
Defined Under Namespace
Instance Attribute Summary collapse
-
#mem_info ⇒ Object
Returns the value of attribute mem_info.
-
#processes ⇒ Object
Returns the value of attribute processes.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Memory
constructor
A new instance of Memory.
- #process_data(memory_info) ⇒ Object
-
#process_ram_info(data) ⇒ Object
Processes memory used by the device.
-
#process_total_pss_by_process(data) ⇒ Object
Processes memory used by each running process.
- #update ⇒ Object
Constructor Details
Instance Attribute Details
#mem_info ⇒ Object
Returns the value of attribute mem_info.
31 32 33 |
# File 'lib/device_api/android/plugins/memory.rb', line 31 def mem_info @mem_info end |
#processes ⇒ Object
Returns the value of attribute processes.
31 32 33 |
# File 'lib/device_api/android/plugins/memory.rb', line 31 def processes @processes end |
Instance Method Details
#process_data(memory_info) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/device_api/android/plugins/memory.rb', line 39 def process_data(memory_info) groups = memory_info.chunk { |a| a == '' }.reject { |a,_| a }.map { |_,b| b } raise 'A different ADB result has been received' unless groups[1].first == 'Total PSS by process:' @processes = [] process_total_pss_by_process(groups[1]) process_ram_info(groups[4]) end |
#process_ram_info(data) ⇒ Object
Processes memory used by the device
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/device_api/android/plugins/memory.rb', line 63 def process_ram_info(data) ram_info = {} data.each do |l| if /Tuning:\s+(.*)/.match(l) ram_info['tuning'] = Regexp.last_match[1] elsif /(.*):\s(-?[0-9]*\s\S*)/.match(l) ram_info[Regexp.last_match[1].downcase] = Regexp.last_match[2] end end @mem_info = RAM.new(total: ram_info['total ram'], free: ram_info['free ram'], used: ram_info['used ram'], lost: ram_info['lost'], tuning: ram_info['tuning']) end |
#process_total_pss_by_process(data) ⇒ Object
Processes memory used by each running process
54 55 56 57 58 59 60 |
# File 'lib/device_api/android/plugins/memory.rb', line 54 def process_total_pss_by_process(data) data.each do |l| if /(.*):\s+(.*)\s+\(.*pid\s+(\S*).*\)/.match(l) @processes << MemInfo.new(process: Regexp.last_match[2], memory: Regexp.last_match[1], pid: Regexp.last_match[3] ) end end end |