droid-monitor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ require 'tilt/haml'
2
+
3
+ module Droid
4
+ module Monitor
5
+ module GoogleApiTemplate
6
+ class << self
7
+ def create_graph( data_file_path, graph_opts = {})
8
+ template_path = File.expand_path("../templates/template_google_api_format.haml", __FILE__)
9
+ default_graph_settings = { miniValue: 0, maxValue: 400, width: 800, height: 480 }
10
+
11
+ template = Tilt::HamlTemplate.new(template_path)
12
+ template.render(Object.new,
13
+ title: graph_opts[:title],
14
+ header1: graph_opts[:header1],
15
+ data_file_path: data_file_path,
16
+ graph_settings: graph_opts[:graph_settings] || default_graph_settings)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{charset: 'UTF-8'}
5
+ %script{type: 'text/javascript', src: 'https://www.google.com/jsapi'}
6
+ %script{type: 'text/javascript', src: 'https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'}
7
+ :javascript
8
+ google.load('visualization', '1', {'packages':['corechart']});
9
+
10
+ // Set a callback to run when the Google Visualization API is loaded.
11
+ google.setOnLoadCallback(drawChart);
12
+
13
+ function drawChart() {
14
+ var jsonData = $.ajax({
15
+ url: data_path(),
16
+ dataType:"json",
17
+ async: false
18
+ }).responseText;
19
+
20
+ // Create our data table out of JSON data loaded from server.
21
+ var data = new google.visualization.DataTable(jsonData);
22
+
23
+ var options = {
24
+ title: "#{header1}",
25
+ vAxis: { miniValue: #{graph_settings[:miniValue]}, maxValue: #{graph_settings[:maxValue]} },
26
+ width: #{graph_settings[:width]},
27
+ height: #{graph_settings[:height]}
28
+ }
29
+
30
+ // Instantiate and draw our chart, passing in some options.
31
+ var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
32
+ chart.draw(data, options);
33
+ }
34
+
35
+ function data_path() {
36
+ return '#{data_file_path}';
37
+ }
38
+
39
+ %title #{title}
40
+ %body
41
+ %h1 #{header1}
42
+ %div{id: 'chart_div'}
@@ -0,0 +1,5 @@
1
+ module Droid
2
+ module Monitor
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "clockwork"
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.2.1)
5
+ i18n (~> 0.7)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.3, >= 0.3.4)
9
+ tzinfo (~> 1.1)
10
+ clockwork (1.2.0)
11
+ activesupport
12
+ tzinfo
13
+ i18n (0.7.0)
14
+ json (1.8.2)
15
+ minitest (5.6.1)
16
+ thread_safe (0.3.5)
17
+ tzinfo (1.2.2)
18
+ thread_safe (~> 0.1)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ clockwork
@@ -0,0 +1,21 @@
1
+ require "../lib/droid/monitor/cpu"
2
+ require "clockwork"
3
+
4
+ module Clockwork
5
+ @cpu = Droid::Monitor::Cpu.new( { package: "com.android.chrome" } )
6
+ @time = 0
7
+ @data_file = "sample.txt"
8
+
9
+ every(0.5.seconds, "capture cpu usage") do
10
+ @cpu.store_dumped_cpu_usage
11
+ @time += 1
12
+
13
+ if @time == 40
14
+ @cpu.save_cpu_usage_as_google_api(@data_file)
15
+ graph_opts = { title: "Example", header1: "this graph is just sample"}
16
+ @cpu.create_graph(@data_file, graph_opts, "result.html")
17
+ @cpu.clear_cpu_usage
18
+ puts "saved"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require "../lib/droid/monitor/memory"
2
+ require "clockwork"
3
+
4
+ module Clockwork
5
+ @memory = Droid::Monitor::Memory.new( { package: "com.android.chrome" } )
6
+ @time = 0
7
+ @data_file = "sample.txt"
8
+
9
+ every(0.5.seconds, "capture memory usage") do
10
+ @memory.store_dumped_memory_details_usage
11
+ @time += 1
12
+
13
+ if @time == 40
14
+ @memory.save_memory_details_as_google_api(@data_file)
15
+ graph_opts = { title: "Example", header1: "this graph is just sample"}
16
+ @memory.create_graph(@data_file, graph_opts, "result.html")
17
+ @memory.clear_memory_detail_usage
18
+ puts "saved"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='UTF-8'>
5
+ <script src='https://www.google.com/jsapi' type='text/javascript'></script>
6
+ <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js' type='text/javascript'></script>
7
+ <script>
8
+ google.load('visualization', '1', {'packages':['corechart']});
9
+
10
+ // Set a callback to run when the Google Visualization API is loaded.
11
+ google.setOnLoadCallback(drawChart);
12
+
13
+ function drawChart() {
14
+ var jsonData = $.ajax({
15
+ url: data_path(),
16
+ dataType:"json",
17
+ async: false
18
+ }).responseText;
19
+
20
+ // Create our data table out of JSON data loaded from server.
21
+ var data = new google.visualization.DataTable(jsonData);
22
+
23
+ var options = {
24
+ title: "this graph is just sample",
25
+ vAxis: { miniValue: 0, maxValue: 400 },
26
+ width: 800,
27
+ height: 480
28
+ }
29
+
30
+ // Instantiate and draw our chart, passing in some options.
31
+ var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
32
+ chart.draw(data, options);
33
+ }
34
+
35
+ function data_path() {
36
+ return 'sample.txt';
37
+ }
38
+ </script>
39
+ <title>Example</title>
40
+ </head>
41
+ <body>
42
+ <h1>this graph is just sample</h1>
43
+ <div id='chart_div'></div>
44
+ </body>
45
+ </html>
@@ -0,0 +1 @@
1
+ {"cols":[{"label":"time","type":"string"},{"label":"pss_total","type":"number"},{"label":"private_dirty","type":"number"},{"label":"private_clean","type":"number"},{"label":"swapped_dirty","type":"number"},{"label":"heap_size","type":"number"},{"label":"heap_alloc","type":"number"},{"label":"heap_free","type":"number"}],"rows":[{"c":[{"v":"19:53:47.118"},{"v":122246},{"v":98120},{"v":14212},{"v":0},{"v":74026},{"v":64649},{"v":45226}]},{"c":[{"v":"19:53:48.393"},{"v":122174},{"v":98048},{"v":14212},{"v":0},{"v":73716},{"v":64289},{"v":45492}]},{"c":[{"v":"19:53:49.400"},{"v":121958},{"v":97832},{"v":14212},{"v":0},{"v":73570},{"v":64143},{"v":45638}]},{"c":[{"v":"19:53:50.417"},{"v":121934},{"v":97808},{"v":14212},{"v":0},{"v":73552},{"v":64125},{"v":45656}]},{"c":[{"v":"19:53:51.442"},{"v":121654},{"v":97528},{"v":14212},{"v":0},{"v":73517},{"v":64090},{"v":45691}]},{"c":[{"v":"19:53:52.477"},{"v":121766},{"v":97640},{"v":14212},{"v":0},{"v":73525},{"v":64098},{"v":45683}]},{"c":[{"v":"19:53:53.409"},{"v":121838},{"v":97712},{"v":14212},{"v":0},{"v":73483},{"v":64056},{"v":45725}]},{"c":[{"v":"19:53:54.427"},{"v":121998},{"v":97872},{"v":14212},{"v":0},{"v":73618},{"v":64191},{"v":45590}]},{"c":[{"v":"19:53:55.445"},{"v":121906},{"v":97780},{"v":14212},{"v":0},{"v":73618},{"v":64191},{"v":45590}]},{"c":[{"v":"19:53:56.437"},{"v":121898},{"v":97772},{"v":14212},{"v":0},{"v":73541},{"v":64114},{"v":45667}]},{"c":[{"v":"19:53:57.486"},{"v":121498},{"v":97372},{"v":14212},{"v":0},{"v":73499},{"v":64072},{"v":45709}]},{"c":[{"v":"19:53:58.514"},{"v":121778},{"v":97652},{"v":14212},{"v":0},{"v":73761},{"v":64337},{"v":45444}]},{"c":[{"v":"19:53:59.499"},{"v":121761},{"v":97640},{"v":14204},{"v":0},{"v":74013},{"v":65294},{"v":45511}]},{"c":[{"v":"19:54:00.500"},{"v":124079},{"v":99888},{"v":14224},{"v":0},{"v":75188},{"v":65968},{"v":46899}]},{"c":[{"v":"19:54:01.409"},{"v":113271},{"v":89068},{"v":14232},{"v":0},{"v":75421},{"v":66128},{"v":46768}]},{"c":[{"v":"19:54:02.398"},{"v":105174},{"v":81008},{"v":14208},{"v":0},{"v":73218},{"v":63899},{"v":46957}]},{"c":[{"v":"19:54:03.475"},{"v":128320},{"v":104024},{"v":14204},{"v":0},{"v":76301},{"v":69075},{"v":43825}]},{"c":[{"v":"19:54:04.405"},{"v":128730},{"v":104008},{"v":14204},{"v":0},{"v":79125},{"v":70443},{"v":45181}]},{"c":[{"v":"19:54:05.551"},{"v":111603},{"v":86972},{"v":14204},{"v":0},{"v":78743},{"v":67480},{"v":48127}]},{"c":[{"v":"19:54:06.458"},{"v":118883},{"v":94252},{"v":14204},{"v":0},{"v":78807},{"v":67458},{"v":48152}]},{"c":[{"v":"19:54:07.430"},{"v":119003},{"v":94372},{"v":14204},{"v":0},{"v":78788},{"v":67440},{"v":48168}]},{"c":[{"v":"19:54:08.475"},{"v":127496},{"v":102292},{"v":14220},{"v":0},{"v":78606},{"v":67292},{"v":48316}]},{"c":[{"v":"19:54:09.483"},{"v":122472},{"v":97388},{"v":14220},{"v":0},{"v":72454},{"v":63461},{"v":46258}]},{"c":[{"v":"19:54:10.515"},{"v":121497},{"v":96680},{"v":14000},{"v":0},{"v":72280},{"v":64645},{"v":45094}]},{"c":[{"v":"19:54:11.431"},{"v":121521},{"v":96708},{"v":14000},{"v":0},{"v":72203},{"v":63251},{"v":46477}]},{"c":[{"v":"19:54:12.424"},{"v":104432},{"v":79620},{"v":14000},{"v":0},{"v":72427},{"v":63749},{"v":45977}]},{"c":[{"v":"19:54:13.515"},{"v":122870},{"v":98060},{"v":14000},{"v":0},{"v":72175},{"v":64085},{"v":45685}]},{"c":[{"v":"19:54:14.490"},{"v":125194},{"v":100372},{"v":14012},{"v":0},{"v":74710},{"v":65833},{"v":45976}]},{"c":[{"v":"19:54:15.429"},{"v":114644},{"v":89816},{"v":14024},{"v":0},{"v":72434},{"v":72032},{"v":37699}]},{"c":[{"v":"19:54:16.557"},{"v":113941},{"v":89108},{"v":14024},{"v":0},{"v":72338},{"v":63346},{"v":46383}]},{"c":[{"v":"19:54:17.377"},{"v":125368},{"v":100536},{"v":14024},{"v":0},{"v":74626},{"v":65833},{"v":45955}]},{"c":[{"v":"19:54:18.441"},{"v":125303},{"v":99664},{"v":14248},{"v":0},{"v":73891},{"v":65001},{"v":46797}]},{"c":[{"v":"19:54:19.520"},{"v":105880},{"v":80216},{"v":14272},{"v":0},{"v":71286},{"v":62475},{"v":47011}]},{"c":[{"v":"19:54:20.439"},{"v":106132},{"v":80468},{"v":14272},{"v":0},{"v":71147},{"v":62358},{"v":47136}]},{"c":[{"v":"19:54:21.524"},{"v":129151},{"v":102572},{"v":14320},{"v":0},{"v":73947},{"v":67207},{"v":44330}]},{"c":[{"v":"19:54:22.493"},{"v":127232},{"v":100664},{"v":14320},{"v":0},{"v":73997},{"v":64165},{"v":47661}]},{"c":[{"v":"19:54:23.433"},{"v":126880},{"v":100312},{"v":14320},{"v":0},{"v":73760},{"v":63960},{"v":47869}]},{"c":[{"v":"19:54:24.650"},{"v":126017},{"v":99500},{"v":14316},{"v":0},{"v":73481},{"v":64068},{"v":47760}]},{"c":[{"v":"19:54:25.536"},{"v":124462},{"v":98184},{"v":14272},{"v":0},{"v":70692},{"v":62400},{"v":46776}]},{"c":[{"v":"19:54:26.421"},{"v":124714},{"v":98440},{"v":14272},{"v":0},{"v":70682},{"v":62088},{"v":47102}]}]}
@@ -0,0 +1,109 @@
1
+ require 'test/unit'
2
+
3
+ require './lib/droid/monitor/cpu'
4
+
5
+ SAMPLE_CPU_DATA_44 = <<-EOS
6
+ Load: 20.88 / 17.57 / 10.31
7
+ CPU usage from 7077ms to 1571ms ago:
8
+ 47% 844/system_server: 37% user + 10% kernel / faults: 2947 minor
9
+ 23% 3031/com.facebook.orca: 22% user + 0.3% kernel / faults: 553 minor
10
+ 18% 24281/android.process.media: 12% user + 5.2% kernel / faults: 910 minor
11
+ 9.2% 15887/com.linkbubble.playstore: 7.4% user + 1.8% kernel / faults: 137 minor
12
+ 7.4% 1038/com.android.systemui: 4.1% user + 3.2% kernel / faults: 23 minor
13
+ 6.1% 125/mmcqd/0: 0% user + 6.1% kernel
14
+ 6.1% 161/surfaceflinger: 2% user + 4.1% kernel
15
+ 6% 24263/com.android.chrome: 4.7% user + 1.2% kernel / faults: 1361 minor 17 major
16
+ 5.2% 20938/com.facebook.katana: 2.1% user + 3% kernel / faults: 64 minor
17
+ 2.7% 194/sdcard: 0.1% user + 2.5% kernel
18
+ 1.2% 60/kswapd0: 0% user + 1.2% kernel
19
+ 1.2% 11502/kworker/u:13: 0% user + 1.2% kernel
20
+ 1% 289/sensors.qcom: 0.1% user + 0.9% kernel
21
+ 0.9% 21403/com.mailboxapp: 0.7% user + 0.1% kernel / faults: 303 minor
22
+ 0.7% 144/jbd2/mmcblk0p19: 0% user + 0.7% kernel
23
+ 0.7% 1162/com.google.android.gms.persistent: 0.3% user + 0.3% kernel / faults: 37 minor
24
+ 0.3% 1762/mpdecision: 0% user + 0.3% kernel
25
+ 0.1% 18301/kworker/0:2: 0% user + 0.1% kernel
26
+ 0.3% 25698/com.google.android.gms.wearable: 0.3% user + 0% kernel / faults: 354 minor
27
+ 0% 158/netd: 0% user + 0% kernel / faults: 38 minor
28
+ 0.1% 191/logcat: 0.1% user + 0% kernel
29
+ 0% 1024/MC_Thread: 0% user + 0% kernel
30
+ 0.1% 1239/com.tul.aviate: 0.1% user + 0% kernel / faults: 4 minor
31
+ 0.1% 6799/kworker/0:0: 0% user + 0.1% kernel
32
+ 0% 14728/com.google.android.googlequicksearchbox:search: 0% user + 0% kernel / faults: 13 minor
33
+ 0% 24205/kworker/1:1: 0% user + 0% kernel
34
+ 96% TOTAL: 49% user + 20% kernel + 26% iowait + 0.5% softirq
35
+ EOS
36
+
37
+ class CpuTest < Test::Unit::TestCase
38
+
39
+ def setup
40
+ @cpu = Droid::Monitor::Cpu.new( { package: "com.android.chrome" } )
41
+ end
42
+
43
+ def teardown
44
+ @cpu = nil
45
+ end
46
+
47
+ def test_initialize
48
+ assert_instance_of(Droid::Monitor::Cpu, @cpu)
49
+
50
+ @cpu.api_level = 18
51
+ assert_equal("com.android.chrome", @cpu.package)
52
+ assert_equal("", @cpu.device_serial)
53
+ assert_equal(18, @cpu.api_level)
54
+ assert_equal([], @cpu.cpu_usage)
55
+ end
56
+
57
+ def test_push_current_time
58
+ assert_equal(@cpu.merge_current_time({}).length, 1)
59
+ end
60
+
61
+ def test_dump_cpu_usage
62
+ expected = %w(6% 24263/com.android.chrome: 4.7% user + 1.2% kernel / faults: 1361 minor 17 major)
63
+ assert_equal(expected, @cpu.dump_cpu_usage(SAMPLE_CPU_DATA_44))
64
+ end
65
+
66
+ def test_transfer_from_hash_empty_to_json
67
+ dummy_array = %w(13:43:32.556)
68
+
69
+ @cpu.store_cpu_usage(dummy_array)
70
+ expected_json = "[{\"total_cpu\":\"0%\",\"process\":\"no package process\",\"user\":\"0%\"," +
71
+ "\"kernel\":\"0%\",\"time\":\"#{@cpu.cpu_usage[0][:time]}\"}]"
72
+
73
+ assert_equal(expected_json, JSON.generate(@cpu.cpu_usage))
74
+ end
75
+
76
+ def test_transfer_from_hash_correct_to_json
77
+ dummy_array = %w(4.7% 2273/com.sample.package:sample: 3.3% user + 1.3% kernel 13:43:32.556)
78
+
79
+ @cpu.store_cpu_usage(dummy_array)
80
+ expected_json = "[{\"total_cpu\":\"4.7%\",\"process\":\"2273/com.sample.package:sample:\"," +
81
+ "\"user\":\"3.3%\",\"kernel\":\"1.3%\",\"time\":\"#{@cpu.cpu_usage[0][:time]}\"}]"
82
+ assert_equal(expected_json, JSON.generate(@cpu.cpu_usage))
83
+ end
84
+
85
+ def test_convert_to_google_data_api_format_one
86
+ dummy_array = %w(4.7% 2273/com.sample.package:sample: 3.3% user + 1.3% kernel 13:43:32.556)
87
+
88
+ @cpu.store_cpu_usage(dummy_array)
89
+ expected_json = "{\"cols\":[{\"label\":\"time\",\"type\":\"string\"}," +
90
+ "{\"label\":\"total_cpu\",\"type\":\"number\"},{\"label\":\"user\",\"type\":\"number\"}," +
91
+ "{\"label\":\"kernel\",\"type\":\"number\"}],\"rows\":[{\"c\":[{\"v\":\"#{@cpu.cpu_usage[0][:time]}\"}," +
92
+ "{\"v\":4.7},{\"v\":3.3},{\"v\":1.3}]}]}"
93
+ assert_equal(@cpu.export_as_google_api_format(@cpu.cpu_usage), expected_json)
94
+ end
95
+
96
+ def test_convert_to_google_data_api_format_many
97
+ dummy_array = %w(4.7% 2273/com.sample.package:sample: 3.3% user + 1.3% kernel 13:43:32.556)
98
+
99
+ @cpu.store_cpu_usage(dummy_array)
100
+ @cpu.store_cpu_usage(dummy_array)
101
+ expected_json = "{\"cols\":[{\"label\":\"time\",\"type\":\"string\"}," +
102
+ "{\"label\":\"total_cpu\",\"type\":\"number\"},{\"label\":\"user\",\"type\":\"number\"}," +
103
+ "{\"label\":\"kernel\",\"type\":\"number\"}],\"rows\":[{\"c\":[{\"v\":\"#{@cpu.cpu_usage[0][:time]}\"}," +
104
+ "{\"v\":4.7},{\"v\":3.3},{\"v\":1.3}]},{\"c\":[{\"v\":\"#{@cpu.cpu_usage[1][:time]}\"}," +
105
+ "{\"v\":4.7},{\"v\":3.3},{\"v\":1.3}]}]}"
106
+ assert_equal(@cpu.export_as_google_api_format(@cpu.cpu_usage), expected_json)
107
+ end
108
+
109
+ end
@@ -0,0 +1,269 @@
1
+ require 'test/unit'
2
+
3
+ require './lib/droid/monitor/memory'
4
+
5
+ SAMPLE_DATA_43 = <<-EOS
6
+ Applications Memory Usage (kB):
7
+ Uptime: 69627589 Realtime: 376894346
8
+
9
+ ** MEMINFO in pid 29607 [com.sample.package] **
10
+ Shared Private Heap Heap Heap
11
+ Pss Dirty Dirty Size Alloc Free
12
+ ------ ------ ------ ------ ------ ------
13
+ Native 24 8 24 11296 7927 408
14
+ Dalvik 11976 4696 11916 13388 7454 5934
15
+ Cursor 0 0 0
16
+ Ashmem 0 0 0
17
+ Other dev 56 56 0
18
+ .so mmap 2507 2028 620
19
+ .jar mmap 0 0 0
20
+ .apk mmap 49 0 0
21
+ .ttf mmap 3 0 0
22
+ .dex mmap 628 0 12
23
+ Other mmap 592 16 296
24
+ Unknown 13094 504 13092
25
+ TOTAL 28929 7308 25960 24684 15381 6342
26
+
27
+ Objects
28
+ Views: 115 ViewRootImpl: 1
29
+ AppContexts: 6 Activities: 1
30
+ Assets: 6 AssetManagers: 6
31
+ Local Binders: 15 Proxy Binders: 23
32
+ Death Recipients: 0
33
+ OpenSSL Sockets: 3
34
+
35
+ SQL
36
+ MEMORY_USED: 462
37
+ PAGECACHE_OVERFLOW: 83 MALLOC_SIZE: 62
38
+
39
+ DATABASES
40
+ pgsz dbsz Lookaside(b) cache Dbname
41
+ 4 48 37 11/22/4 /data/data/com.sample.package/databases/sample.db
42
+ EOS
43
+
44
+ SAMPLE_DATA_44 = <<-EOS
45
+ Applications Memory Usage (kB):
46
+ Uptime: 76485937 Realtime: 238763696
47
+
48
+ ** MEMINFO in pid 30125 [com.sample.package] **
49
+ Pss Private Private Swapped Heap Heap Heap
50
+ Total Dirty Clean Dirty Size Alloc Free
51
+ ------ ------ ------ ------ ------ ------ ------
52
+ Native Heap 0 0 0 0 8948 8520 271
53
+ Dalvik Heap 23195 22764 0 0 31772 29998 1774
54
+ Dalvik Other 3875 3820 0 0
55
+ Stack 272 272 0 0
56
+ Cursor 4 4 0 0
57
+ Other dev 4014 3136 20 0
58
+ .so mmap 1429 1028 12 0
59
+ .apk mmap 712 0 368 0
60
+ .ttf mmap 594 0 308 0
61
+ .dex mmap 5099 44 4648 0
62
+ Other mmap 40 4 16 0
63
+ Unknown 5329 5324 0 0
64
+ TOTAL 44563 36396 5372 0 40720 38518 2045
65
+
66
+ Objects
67
+ Views: 690 ViewRootImpl: 1
68
+ AppContexts: 3 Activities: 1
69
+ Assets: 4 AssetManagers: 4
70
+ Local Binders: 15 Proxy Binders: 23
71
+ Death Recipients: 1
72
+ OpenSSL Sockets: 7
73
+
74
+ SQL
75
+ MEMORY_USED: 329
76
+ PAGECACHE_OVERFLOW: 82 MALLOC_SIZE: 62
77
+
78
+ DATABASES
79
+ pgsz dbsz Lookaside(b) cache Dbname
80
+ 4 20 58 21/26/9 /data/data/com.sample.package/databases/sample.db
81
+ Asset Allocations
82
+ zip:/data/app/com.sample.package.apk:/assets/sample.ttf: 132K
83
+ EOS
84
+
85
+ class MemoryTest < Test::Unit::TestCase
86
+
87
+ def setup
88
+ @memory = Droid::Monitor::Memory.new( { package: "com.android.chrome" } )
89
+ end
90
+
91
+ def teardown
92
+ @memory = nil
93
+ end
94
+
95
+ def test_initialize
96
+ assert_instance_of(Droid::Monitor::Memory, @memory)
97
+
98
+ @memory.api_level = 19
99
+ assert_equal("com.android.chrome", @memory.package)
100
+ assert_equal("", @memory.device_serial)
101
+ assert_equal(19, @memory.api_level)
102
+ assert_equal([], @memory.memory_usage)
103
+ assert_equal([], @memory.memory_detail_usage)
104
+ end
105
+
106
+ def test_push_current_time
107
+ assert_equal(@memory.merge_current_time({}).length, 1)
108
+ end
109
+
110
+ def test_dump_memory_usage_under_api_level18
111
+ expected = %w(Uptime: 69627589 Realtime: 376894346)
112
+ assert_equal(expected,@memory.dump_memory_usage(SAMPLE_DATA_43))
113
+ end
114
+
115
+ def test_dump_memory_usage_over_api_level18
116
+ expected = %w(Uptime: 76485937 Realtime: 238763696)
117
+ assert_equal(expected,@memory.dump_memory_usage(SAMPLE_DATA_44))
118
+ end
119
+
120
+ def test_dump_memory_detail_usage_under_api_level18
121
+ expected = %w(TOTAL 28929 7308 25960 24684 15381 6342)
122
+ assert_equal(expected,@memory.dump_memory_details_usage(SAMPLE_DATA_43))
123
+ end
124
+
125
+ def test_dump_memory_detail_usage_over_api_level18
126
+ expected = %w(TOTAL 44563 36396 5372 0 40720 38518 2045)
127
+ assert_equal(expected,@memory.dump_memory_details_usage(SAMPLE_DATA_44))
128
+ end
129
+
130
+ def test_memory_usage
131
+ @memory.api_level = 18
132
+
133
+ expected = {
134
+ realtime: 376894346,
135
+ uptime: 69627589,
136
+ }
137
+
138
+ result = @memory.transfer_total_memory_to_hash(@memory.dump_memory_usage(SAMPLE_DATA_43))
139
+ assert_equal(result, expected)
140
+ end
141
+
142
+
143
+ def test_memory_details_api_level18
144
+ @memory.api_level = 18
145
+
146
+ expected = {
147
+ pss_total: 28929,
148
+ shared_dirty: 7308,
149
+ private_dirty: 25960,
150
+ heap_size: 24684,
151
+ heap_alloc: 15381,
152
+ heap_free: 6342,
153
+ }
154
+
155
+ result = @memory.transfer_total_memory_details_to_hash(@memory.dump_memory_details_usage(SAMPLE_DATA_43))
156
+ assert_equal(result, expected)
157
+ end
158
+
159
+ def test_memory_details_api_level19
160
+ @memory.api_level = 19
161
+
162
+ expected = {
163
+ pss_total: 44563,
164
+ private_dirty: 36396,
165
+ private_clean: 5372,
166
+ swapped_dirty: 0,
167
+ heap_size: 40720,
168
+ heap_alloc: 38518,
169
+ heap_free: 2045,
170
+ }
171
+ result = @memory.transfer_total_memory_details_to_hash(@memory.dump_memory_details_usage(SAMPLE_DATA_44))
172
+ assert_equal(result, expected)
173
+ end
174
+
175
+ def test_transfer_from_hash_empty_to_json_memory_api_level18
176
+ @memory.api_level = 18
177
+
178
+ dummy_array = %w()
179
+
180
+ @memory.store_memory_usage(dummy_array)
181
+
182
+ expected_json = "[{\"uptime\":0,\"realtime\":0,\"time\":\"#{@memory.memory_usage[0][:time]}\"}]"
183
+ assert_equal(expected_json, JSON.generate(@memory.memory_usage))
184
+ end
185
+
186
+ def test_transfer_from_hash_empty_to_json_memory_details_api_level18
187
+ @memory.api_level = 18
188
+
189
+ dummy_array = %w()
190
+
191
+ @memory.store_memory_details_usage(dummy_array)
192
+
193
+ expected_json = "[{\"pss_total\":0,\"shared_dirty\":0,\"private_dirty\":0," +
194
+ "\"heap_size\":0,\"heap_alloc\":0,\"heap_free\":0,\"time\":\"#{@memory.memory_detail_usage[0][:time]}\"}]"
195
+ assert_equal(expected_json, JSON.generate(@memory.memory_detail_usage))
196
+ end
197
+
198
+ def test_transfer_from_hash_empty_to_json_memory_details_api_level18_twice
199
+ @memory.api_level = 18
200
+
201
+ result = @memory.dump_memory_details_usage(SAMPLE_DATA_43)
202
+
203
+ @memory.store_memory_details_usage(result)
204
+ @memory.store_memory_details_usage(result)
205
+
206
+ expected_json = "[{\"pss_total\":28929,\"shared_dirty\":7308,\"private_dirty\":25960," +
207
+ "\"heap_size\":24684,\"heap_alloc\":15381,\"heap_free\":6342," +
208
+ "\"time\":\"#{@memory.memory_detail_usage[0][:time]}\"}," +
209
+ "{\"pss_total\":28929,\"shared_dirty\":7308,\"private_dirty\":25960," +
210
+ "\"heap_size\":24684,\"heap_alloc\":15381,\"heap_free\":6342," +
211
+ "\"time\":\"#{@memory.memory_detail_usage[1][:time]}\"}]"
212
+
213
+ assert_equal(expected_json, JSON.generate(@memory.memory_detail_usage))
214
+
215
+ expected_google = "{\"cols\":[{\"label\":\"time\",\"type\":\"string\"},{\"label\":\"pss_total\"," +
216
+ "\"type\":\"number\"},{\"label\":\"shared_dirty\",\"type\":\"number\"},{\"label\":\"private_dirty\"," +
217
+ "\"type\":\"number\"},{\"label\":\"heap_size\",\"type\":\"number\"},{\"label\":\"heap_alloc\"," +
218
+ "\"type\":\"number\"},{\"label\":\"heap_free\",\"type\":\"number\"}]," +
219
+ "\"rows\":[{\"c\":[{\"v\":\"#{@memory.memory_detail_usage[0][:time]}\"},{\"v\":28929}," +
220
+ "{\"v\":7308},{\"v\":25960},{\"v\":24684},{\"v\":15381},{\"v\":6342}]}," +
221
+ "{\"c\":[{\"v\":\"#{@memory.memory_detail_usage[1][:time]}\"},{\"v\":28929},{\"v\":7308},{\"v\":25960}," +
222
+ "{\"v\":24684},{\"v\":15381},{\"v\":6342}]}]}"
223
+ assert_equal(expected_google, @memory.export_as_google_api_format(@memory.memory_detail_usage))
224
+ end
225
+
226
+
227
+ def test_transfer_from_hash_empty_to_json_memory_details_api_level19
228
+ @memory.api_level = 19
229
+
230
+ dummy_array = %w(13:43:32.556)
231
+
232
+ @memory.store_memory_details_usage(dummy_array)
233
+ expected_json = "[{\"pss_total\":0,\"private_dirty\":0,\"private_clean\":0," +
234
+ "\"swapped_dirty\":0,\"heap_size\":0,\"heap_alloc\":0,\"heap_free\":0," +
235
+ "\"time\":\"#{@memory.memory_detail_usage[0][:time]}\"}]"
236
+ assert_equal(expected_json, JSON.generate(@memory.memory_detail_usage))
237
+ end
238
+
239
+ def test_transfer_from_hash_empty_to_json_memory_details_api_level19_twice
240
+ @memory.api_level = 19
241
+
242
+ result = @memory.dump_memory_details_usage(SAMPLE_DATA_44)
243
+
244
+ @memory.store_memory_details_usage(result)
245
+ @memory.store_memory_details_usage(result)
246
+
247
+ expected_json = "[{\"pss_total\":44563,\"private_dirty\":36396,\"private_clean\":5372,\"swapped_dirty\":0," +
248
+ "\"heap_size\":40720,\"heap_alloc\":38518,\"heap_free\":2045," +
249
+ "\"time\":\"#{@memory.memory_detail_usage[0][:time]}\"}," +
250
+ "{\"pss_total\":44563,\"private_dirty\":36396," +
251
+ "\"private_clean\":5372,\"swapped_dirty\":0," +
252
+ "\"heap_size\":40720,\"heap_alloc\":38518,\"heap_free\":2045," +
253
+ "\"time\":\"#{@memory.memory_detail_usage[1][:time]}\"}]"
254
+
255
+ assert_equal(expected_json, JSON.generate(@memory.memory_detail_usage))
256
+
257
+ expected_google = "{\"cols\":[{\"label\":\"time\",\"type\":\"string\"},{\"label\":\"pss_total\"," +
258
+ "\"type\":\"number\"},{\"label\":\"private_dirty\",\"type\":\"number\"},{\"label\":\"private_clean\"," +
259
+ "\"type\":\"number\"},{\"label\":\"swapped_dirty\",\"type\":\"number\"},{\"label\":\"heap_size\"," +
260
+ "\"type\":\"number\"},{\"label\":\"heap_alloc\",\"type\":\"number\"},{\"label\":\"heap_free\"," +
261
+ "\"type\":\"number\"}],\"rows\":[{\"c\":[{\"v\":\"#{@memory.memory_detail_usage[0][:time]}\"}," +
262
+ "{\"v\":44563},{\"v\":36396},{\"v\":5372},{\"v\":0},{\"v\":40720},{\"v\":38518},{\"v\":2045}]}," +
263
+ "{\"c\":[{\"v\":\"#{@memory.memory_detail_usage[1][:time]}\"},{\"v\":44563},{\"v\":36396}," +
264
+ "{\"v\":5372},{\"v\":0},{\"v\":40720},{\"v\":38518},{\"v\":2045}]}]}"
265
+
266
+ assert_equal(expected_google, @memory.export_as_google_api_format(@memory.memory_detail_usage))
267
+ end
268
+
269
+ end