droid-monitor 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aef56fedb46e23d522c96993e6483336d1795c90
4
- data.tar.gz: feaac7d08ac24f78b7966a892e9f92978803c45b
3
+ metadata.gz: 02eee5274833c846a081808dbe9cb53fc99b27d8
4
+ data.tar.gz: faa85f1b13ce37f96e8f7071b67594ce8e121237
5
5
  SHA512:
6
- metadata.gz: ff2c665d11fcbe4f1cd2a91ef498a5db136c39822d6655881792b19509c828862c086a741167cba2060ecd43d9f15c0e0129347160c8e595d12b4e85dace9f7b
7
- data.tar.gz: 06db6ca23ab91c2a9992eae1b7c33a16b44fe2912c2b206087dc0a3a78e4b14041b279a3c7f5d8943a067ccb575b73a259e558aaa502a76eed0d58b947c3b97d
6
+ metadata.gz: 1094b2ebefe73f913f4ac8f6602a3d1417902c5287a779b138eecff051da8b5e41dca02be6e4c2953e6ba36f0f4df2eedc8d789093454a9682773aead5d41315
7
+ data.tar.gz: 3809202998a053b9ad5d31ba6fffa7235c0455631d104b3c59fc72b3e2d9a43df282995779b6a82d7b8c94c0212d2fd80b583550e51f6b79c3f532d203023831
data/README.md CHANGED
@@ -38,6 +38,7 @@ Followings are only storing data.
38
38
  They don't include cron like clockwork.
39
39
 
40
40
  ### CPU
41
+ #### with cpuinfo
41
42
 
42
43
  ```ruby
43
44
  require "droid/monitor/cpu"
@@ -61,6 +62,30 @@ graph_opts = { title: "Example", header1: "this graph is just sample"}
61
62
  @cpu.clear_cpu_usage
62
63
  ```
63
64
 
65
+ #### with top command
66
+
67
+ ```ruby
68
+ require "droid/monitor/cpu"
69
+
70
+ # initialize
71
+ @cpu = Droid::Monitor::Cpu.new( { package: "com.android.chrome" } )
72
+
73
+ # save data into @cpu.cpu_usage
74
+ @cpu.store_dumped_cpu_usage_with_top
75
+
76
+ # export data into filename as google api format
77
+ filename = "sample_data.txt"
78
+ @cpu.save_cpu_usage_as_google_api_with_top(filename)
79
+
80
+ # export data into filename which is used the above command.
81
+ output_file_path = "sample.html"
82
+ graph_opts = { title: "Example", header1: "this graph is just sample"}
83
+ @cpu.create_graph(filename, graph_opts, output_file_path)
84
+
85
+ #clear @cpu.cpu_usage
86
+ @cpu.clear_cpu_usage
87
+ ```
88
+
64
89
  #### Graph
65
90
 
66
91
  ![](https://github.com/KazuCocoa/droid-monitor/blob/master/doc/images/Screen%20Shot%202015-05-23%20at%2019.46.08.png)
@@ -72,7 +97,7 @@ require "droid/monitor/memory"
72
97
 
73
98
  # initialize
74
99
  # You can specify target devices with providing device serial which is provided via adb devices.
75
- @memory = Droid::Monitor::Cpu.new( { package: "com.android.chrome", device_serial: "device_serials"} )
100
+ @memory = Droid::Monitor::Memory.new( { package: "com.android.chrome", device_serial: "device_serials"} )
76
101
 
77
102
  # save data into @memory.memory_usage
78
103
  @memory.store_dumped_memory_details_usage
@@ -96,6 +121,8 @@ graph_opts = { title: "Example", header1: "this graph is just sample"}
96
121
 
97
122
  ### Net
98
123
 
124
+ **Android 5.x can't get netstats**.
125
+
99
126
  ```ruby
100
127
  require "droid/monitor/net"
101
128
 
@@ -22,11 +22,22 @@ module Droid
22
22
  run_adb("#{adb_shell} getprop ro.build.version.sdk").to_i
23
23
  end
24
24
 
25
+ # @return [String] message from adb command
26
+ def dump_package_info
27
+ run_adb("#{adb_shell} dumpsys package #{@package}")
28
+ end
29
+
25
30
  # @return [String] message from adb command
26
31
  def dump_cpuinfo
27
32
  run_adb("#{adb_shell} dumpsys cpuinfo")
28
33
  end
29
34
 
35
+ # @return [String] message from adb command
36
+ # "17742 1 15% S 55 2279532K 128100K fg u0_a124 your.cpackage\r\n"
37
+ def dump_cpuinfo_with_top
38
+ run_adb("#{adb_shell} top -d 0.5 -n 1 | grep #{@package}")
39
+ end
40
+
30
41
  # @return [String] message from adb command
31
42
  def dump_meminfo
32
43
  run_adb("#{adb_shell} dumpsys meminfo #{@package}")
@@ -32,19 +32,45 @@ module Droid
32
32
  []
33
33
  end
34
34
 
35
+ def dump_cpu_usage_with_top(dump_data)
36
+ return [] if dump_data.nil?
37
+
38
+ dump = dump_data.split(/\s/).reject(&:empty?)
39
+ fail 'no package' if /^Load:$/ =~ dump[0]
40
+
41
+ puts dump
42
+
43
+ dump
44
+ rescue StandardError => e
45
+ puts e
46
+ []
47
+ end
48
+
35
49
  # called directory
36
50
  def store_dumped_cpu_usage
37
51
  self.store_cpu_usage(self.dump_cpu_usage(self.dump_cpuinfo))
38
52
  end
39
53
 
54
+ def store_dumped_cpu_usage_with_top
55
+ self.store_cpu_usage_with_top(self.dump_cpu_usage_with_top(self.dump_cpuinfo_with_top))
56
+ end
57
+
40
58
  def save_cpu_usage_as_google_api(file_path)
41
59
  self.save(export_as_google_api_format(@cpu_usage), file_path)
42
60
  end
43
61
 
62
+ def save_cpu_usage_as_google_api_with_top(file_path)
63
+ self.save(export_as_google_api_format_with_top(@cpu_usage), file_path)
64
+ end
65
+
44
66
  def store_cpu_usage(dumped_cpu)
45
67
  @cpu_usage.push self.merge_current_time(transfer_total_cpu_to_hash(dumped_cpu))
46
68
  end
47
69
 
70
+ def store_cpu_usage_with_top(dumped_cpu)
71
+ @cpu_usage.push self.merge_current_time(transfer_total_cpu_with_top_to_hash(dumped_cpu))
72
+ end
73
+
48
74
  def transfer_total_cpu_to_hash(dump_cpu_array)
49
75
  if dump_cpu_array.length <= 1
50
76
  {
@@ -65,6 +91,22 @@ module Droid
65
91
  end
66
92
  end
67
93
 
94
+ def transfer_total_cpu_with_top_to_hash(dump_cpu_array)
95
+ if dump_cpu_array.length <= 1
96
+ {
97
+ total_cpu: '0%',
98
+ process: 'no package process',
99
+ time: dump_cpu_array.last,
100
+ }
101
+ else
102
+ {
103
+ total_cpu: dump_cpu_array[2],
104
+ process: dump_cpu_array[0],
105
+ time: dump_cpu_array.last,
106
+ }
107
+ end
108
+ end
109
+
68
110
  def export_as_google_api_format(from_cpu_usage)
69
111
  google_api_data_format = empty_google_api_format
70
112
 
@@ -84,6 +126,23 @@ module Droid
84
126
  JSON.generate google_api_data_format
85
127
  end
86
128
 
129
+ def export_as_google_api_format_with_top(from_cpu_usage)
130
+ google_api_data_format = empty_google_api_format_with_top
131
+
132
+ from_cpu_usage.each do |hash|
133
+
134
+ a_google_api_data_format = {
135
+ c: [
136
+ { v: hash[:time] },
137
+ { v: hash[:total_cpu].delete('%').to_f },
138
+ ]
139
+ }
140
+ google_api_data_format[:rows].push(a_google_api_data_format)
141
+ end
142
+
143
+ JSON.generate google_api_data_format
144
+ end
145
+
87
146
  # @params [String] data_file_path A path to data.
88
147
  # @params [Hash] graph_opts A hash regarding graph settings.
89
148
  # @params [String] output_file_path A path you would like to export data.
@@ -107,6 +166,16 @@ module Droid
107
166
  }
108
167
  end
109
168
 
169
+ def empty_google_api_format_with_top
170
+ {
171
+ cols: [
172
+ { label: 'time', type: 'string' },
173
+ { label: 'total_cpu', type: 'number' },
174
+ ],
175
+ rows: [
176
+ ],
177
+ }
178
+ end
110
179
  end # class Cpu
111
180
  end # module Monitor
112
181
  end # module Droid
@@ -1,5 +1,5 @@
1
1
  module Droid
2
2
  module Monitor
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -34,6 +34,10 @@ CPU usage from 7077ms to 1571ms ago:
34
34
  96% TOTAL: 49% user + 20% kernel + 26% iowait + 0.5% softirq
35
35
  EOS
36
36
 
37
+ TOP_CPU = <<-EOS
38
+ 17742 0 4.7% S 82 2929372K 212464K fg u0_a124 com.android.chrome
39
+ EOS
40
+
37
41
  class CpuTest < Test::Unit::TestCase
38
42
 
39
43
  def setup
@@ -63,6 +67,16 @@ class CpuTest < Test::Unit::TestCase
63
67
  assert_equal(expected, @cpu.dump_cpu_usage(SAMPLE_CPU_DATA_44))
64
68
  end
65
69
 
70
+ def test_dump_cpu_usage_with_top_empty
71
+ expected = []
72
+ assert_equal(expected, @cpu.dump_cpu_usage(''))
73
+ end
74
+
75
+ def test_dump_cpu_usage_with_top
76
+ expected = %w(17742 0 4.7% S 82 2929372K 212464K fg u0_a124 com.android.chrome)
77
+ assert_equal(expected, @cpu.dump_cpu_usage(TOP_CPU))
78
+ end
79
+
66
80
  def test_transfer_from_hash_empty_to_json
67
81
  dummy_array = %w(13:43:32.556)
68
82
 
@@ -82,6 +96,22 @@ class CpuTest < Test::Unit::TestCase
82
96
  assert_equal(expected_json, JSON.generate(@cpu.cpu_usage))
83
97
  end
84
98
 
99
+ def test_transfer_from_hash_empty_to_json_with_top
100
+ dummy_array = %w(13:43:32.556)
101
+
102
+ @cpu.store_cpu_usage_with_top(dummy_array)
103
+ expected_json = "[{\"total_cpu\":\"0%\",\"process\":\"no package process\",\"time\":\"#{@cpu.cpu_usage[0][:time]}\"}]"
104
+ assert_equal(expected_json, JSON.generate(@cpu.cpu_usage))
105
+ end
106
+
107
+ def test_transfer_from_hash_correct_to_json_with_top
108
+ dummy_array = %w(17742 0 4.7% S 82 2929372K 212464K fg u0_a124 com.sample.package 13:43:32.55)
109
+
110
+ @cpu.store_cpu_usage_with_top(dummy_array)
111
+ expected_json = "[{\"total_cpu\":\"4.7%\",\"process\":\"17742\",\"time\":\"#{@cpu.cpu_usage[0][:time]}\"}]"
112
+ assert_equal(expected_json, JSON.generate(@cpu.cpu_usage))
113
+ end
114
+
85
115
  def test_convert_to_google_data_api_format_one
86
116
  dummy_array = %w(4.7% 2273/com.sample.package:sample: 3.3% user + 1.3% kernel 13:43:32.556)
87
117
 
@@ -106,4 +136,26 @@ class CpuTest < Test::Unit::TestCase
106
136
  assert_equal(@cpu.export_as_google_api_format(@cpu.cpu_usage), expected_json)
107
137
  end
108
138
 
139
+ def test_convert_to_google_data_api_format_with_top_one
140
+ dummy_array = %w(17742 0 4.7% S 82 2929372K 212464K fg u0_a124 com.sample.package 13:43:32.55)
141
+
142
+ @cpu.store_cpu_usage_with_top(dummy_array)
143
+ expected_json = "{\"cols\":[{\"label\":\"time\",\"type\":\"string\"}," +
144
+ "{\"label\":\"total_cpu\",\"type\":\"number\"}],\"rows\":[{\"c\":[{\"v\":\"#{@cpu.cpu_usage[0][:time]}\"}," +
145
+ "{\"v\":4.7}]}]}"
146
+ assert_equal(@cpu.export_as_google_api_format_with_top(@cpu.cpu_usage), expected_json)
147
+ end
148
+
149
+ def test_convert_to_google_data_api_format_with_top_many
150
+ dummy_array = %w(17742 0 4.7% S 82 2929372K 212464K fg u0_a124 com.sample.package 13:43:32.55)
151
+
152
+ @cpu.store_cpu_usage_with_top(dummy_array)
153
+ @cpu.store_cpu_usage_with_top(dummy_array)
154
+ expected_json = "{\"cols\":[{\"label\":\"time\",\"type\":\"string\"}," +
155
+ "{\"label\":\"total_cpu\",\"type\":\"number\"}],\"rows\":[{\"c\":[{\"v\":\"#{@cpu.cpu_usage[0][:time]}\"}," +
156
+ "{\"v\":4.7}]},{\"c\":[{\"v\":\"#{@cpu.cpu_usage[1][:time]}\"}," +
157
+ "{\"v\":4.7}]}]}"
158
+ assert_equal(@cpu.export_as_google_api_format_with_top(@cpu.cpu_usage), expected_json)
159
+ end
160
+
109
161
  end
@@ -82,6 +82,68 @@ Uptime: 76485937 Realtime: 238763696
82
82
  zip:/data/app/com.sample.package.apk:/assets/sample.ttf: 132K
83
83
  EOS
84
84
 
85
+ SAMPLE_DATA_60 = <<-EOS
86
+ Applications Memory Usage (kB):
87
+ Uptime: 166891747 Realtime: 445776902
88
+
89
+ ** MEMINFO in pid 22861 [com.sample.package] **
90
+ Pss Private Private Swapped Heap Heap Heap
91
+ Total Dirty Clean Dirty Size Alloc Free
92
+ ------ ------ ------ ------ ------ ------ ------
93
+ Native Heap 24501 24240 0 13968 60416 56957 3458
94
+ Dalvik Heap 16434 16400 0 484 34525 31331 3194
95
+ Dalvik Other 14130 14108 0 5072
96
+ Stack 1316 1316 0 0
97
+ Ashmem 207 112 0 0
98
+ Other dev 9 0 8 0
99
+ .so mmap 18500 444 12540 2504
100
+ .apk mmap 1964 0 1520 0
101
+ .ttf mmap 643 0 580 0
102
+ .dex mmap 18523 8 18156 4
103
+ .oat mmap 2657 0 500 0
104
+ .art mmap 1881 1560 16 92
105
+ Other mmap 1725 12 1020 4
106
+ EGL mtrack 7962 7962 0 0
107
+ GL mtrack 32867 32867 0 0
108
+ Unknown 2672 2672 0 108
109
+ TOTAL 145991 101701 34340 22236 94941 88288 6652
110
+
111
+ App Summary
112
+ Pss(KB)
113
+ ------
114
+ Java Heap: 17976
115
+ Native Heap: 24240
116
+ Code: 33748
117
+ Stack: 1316
118
+ Graphics: 40829
119
+ Private Other: 17932
120
+ System: 9950
121
+
122
+ TOTAL: 145991 TOTAL SWAP (KB): 22236
123
+
124
+ Objects
125
+ Views: 553 ViewRootImpl: 1
126
+ AppContexts: 2 Activities: 1
127
+ Assets: 5 AssetManagers: 2
128
+ Local Binders: 37 Proxy Binders: 29
129
+ Parcel memory: 11 Parcel count: 46
130
+ Death Recipients: 2 OpenSSL Sockets: 10
131
+
132
+ SQL
133
+ MEMORY_USED: 468
134
+ PAGECACHE_OVERFLOW: 113 MALLOC_SIZE: 62
135
+
136
+ DATABASES
137
+ pgsz dbsz Lookaside(b) cache Dbname
138
+ 4 20 25 36/17/3 /data/data/com.sample.package/databases/sample1.db
139
+ 4 28 62 17/26/8 /data/data/com.sample.package/databases/sample2.db
140
+ 4 104 19 6/21/3 /data/data/com.sample.package/databases/sample3.db
141
+ 4 104 22 2/18/3 /data/data/com.sample.package/databases/sample4.db
142
+
143
+ Asset Allocations
144
+ zip:/data/app/com.sample.package/base.apk:/assets/sample.ttf: 76K
145
+ EOS
146
+
85
147
  class MemoryTest < Test::Unit::TestCase
86
148
 
87
149
  def setup
@@ -172,6 +234,22 @@ class MemoryTest < Test::Unit::TestCase
172
234
  assert_equal(result, expected)
173
235
  end
174
236
 
237
+ def test_memory_details_api_level23
238
+ @memory.api_level = 23
239
+
240
+ expected = {
241
+ pss_total: 145991,
242
+ private_dirty: 101701,
243
+ private_clean: 34340,
244
+ swapped_dirty: 22236,
245
+ heap_size: 94941,
246
+ heap_alloc: 88288,
247
+ heap_free: 6652,
248
+ }
249
+ result = @memory.transfer_total_memory_details_to_hash(@memory.dump_memory_details_usage(SAMPLE_DATA_60))
250
+ assert_equal(result, expected)
251
+ end
252
+
175
253
  def test_transfer_from_hash_empty_to_json_memory_api_level18
176
254
  @memory.api_level = 18
177
255
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: droid-monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuaki MATSUO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-16 00:00:00.000000000 Z
11
+ date: 2017-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faml
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  version: '0'
147
147
  requirements: []
148
148
  rubyforge_project:
149
- rubygems_version: 2.5.1
149
+ rubygems_version: 2.6.8
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: Monitoring Android cpu or memory usage and create their simple graph with