droid-monitor 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -0
- data/doc/images/Screen Shot 2015-07-01 10.18.57.png +0 -0
- data/doc/images/Screen Shot 2015-07-01 10.19.11.png +0 -0
- data/lib/droid/monitor.rb +13 -0
- data/lib/droid/monitor/net.rb +139 -0
- data/lib/droid/monitor/version.rb +1 -1
- data/sample/example_net.rb +26 -0
- data/test/net_test.rb +89 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57e8e14b629c3491612d6694bd1303b147258e49
|
4
|
+
data.tar.gz: 57491e27df2bfb6883c7834fadf76de937fc52cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9835127db21a61910610a3f98c5b2fd85c0458e823fcb860887c345d7b03e2b8429ac6e76fe5c3b5b18a4392d975be5e109741b4fa50014c6582b283650cf09c
|
7
|
+
data.tar.gz: a9cd88bb4b1b1df4c7c0b56d58c5d45cf6dbb43852213efe453f6d4b6c285a7e73828bbfaf505f949ff386b7823bbd7299f1fd2fa4cda4520f26100a755b8d29
|
data/README.md
CHANGED
@@ -73,6 +73,43 @@ graph_opts = { title: "Example", header1: "this graph is just sample"}
|
|
73
73
|
|
74
74
|
![](https://github.com/KazuCocoa/droid-monitor/blob/master/doc/images/Screen%20Shot%202015-05-23%20at%2019.56.41.png)
|
75
75
|
|
76
|
+
### Net
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
# initialize
|
80
|
+
@net = Droid::Monitor::Net.new( { package: "com.android.chrome" } )
|
81
|
+
|
82
|
+
@data_file = "sample.txt"
|
83
|
+
@data_file2 = "sample2.txt"
|
84
|
+
|
85
|
+
# save data into @net.tcp_rec, @net.tcp_snd
|
86
|
+
@net.store_dumped_tcp_rcv
|
87
|
+
@net.store_dumped_tcp_snd
|
88
|
+
|
89
|
+
# export data into filename as google api format
|
90
|
+
finename1 = "sample_data1.txt"
|
91
|
+
finename2 = "sample_data2.txt"
|
92
|
+
@net.save_cpu_usage_as_google_api_rec(finename1)
|
93
|
+
@net.save_cpu_usage_as_google_api_snd(finename2)
|
94
|
+
|
95
|
+
# export data into filename which is used the above command.
|
96
|
+
output_file_path1 = "sample1.html"
|
97
|
+
output_file_path2 = "sample2.html"
|
98
|
+
graph_opts = { title: "Example", header1: "this graph is just sample"}
|
99
|
+
@net.create_graph(@data_file, graph_opts, output_file_path1)
|
100
|
+
@net.create_graph(@data_file2, graph_opts, output_file_path2)
|
101
|
+
```
|
102
|
+
|
103
|
+
#### Graph
|
104
|
+
|
105
|
+
- receive tcp
|
106
|
+
|
107
|
+
![](https://github.com/KazuCocoa/droid-monitor/blob/master/doc/images/Screen%20Shot%202015-07-01%2010.18.57.png?raw=true)
|
108
|
+
|
109
|
+
- send tcp
|
110
|
+
|
111
|
+
![](https://github.com/KazuCocoa/droid-monitor/blob/master/doc/images/Screen%20Shot%202015-07-01%2010.19.11.png?raw=true)
|
112
|
+
|
76
113
|
## Notice
|
77
114
|
|
78
115
|
1. Some browser, like Google Chrome, can't see local file via page. So, you should see report html file via FireFox as example.
|
Binary file
|
Binary file
|
data/lib/droid/monitor.rb
CHANGED
@@ -29,6 +29,19 @@ module Droid
|
|
29
29
|
`#{adb_shell} dumpsys meminfo #{@package}`.chomp
|
30
30
|
end
|
31
31
|
|
32
|
+
# @return [String] line of packages regarding pid and so on
|
33
|
+
def get_pid
|
34
|
+
`#{adb_shell} dumpsys package #{@package} | grep userId=`.chomp.scan(/userId=[0-9]+/).uniq.first.delete("userId=")
|
35
|
+
end
|
36
|
+
|
37
|
+
def dump_tcp_rcv
|
38
|
+
`#{adb_shell} cat proc/uid_stat/#{get_pid}/tcp_rcv`
|
39
|
+
end
|
40
|
+
|
41
|
+
def dump_tcp_snd
|
42
|
+
`#{adb_shell} cat proc/uid_stat/#{get_pid}/tcp_snd`
|
43
|
+
end
|
44
|
+
|
32
45
|
private
|
33
46
|
|
34
47
|
def adb
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require_relative "../monitor"
|
2
|
+
require_relative "common/commons"
|
3
|
+
require_relative "report/google_api_template"
|
4
|
+
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module Droid
|
8
|
+
module Monitor
|
9
|
+
class Net < Droid::Monitor::Adb
|
10
|
+
attr_reader :tcp_rec, :tcp_snd
|
11
|
+
|
12
|
+
include Droid::Monitor::Utils
|
13
|
+
|
14
|
+
def initialize(opts = {})
|
15
|
+
super(opts)
|
16
|
+
@tcp_rec = []
|
17
|
+
@tcp_snd = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def clear_tcps
|
21
|
+
@tcp_rec = []
|
22
|
+
@tcp_snd = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def dump_tcp_rcv_usage(dump_data)
|
26
|
+
[dump_data.to_i]
|
27
|
+
end
|
28
|
+
|
29
|
+
def dump_tcp_snd_usage(dump_data)
|
30
|
+
[dump_data.to_i]
|
31
|
+
end
|
32
|
+
|
33
|
+
# called directory
|
34
|
+
def store_dumped_tcp_rcv
|
35
|
+
self.store_tcp_rec(self.dump_tcp_rcv_usage(self.dump_tcp_rcv))
|
36
|
+
end
|
37
|
+
|
38
|
+
def store_dumped_tcp_snd
|
39
|
+
self.store_tcp_snd(self.dump_tcp_snd_usage(self.dump_tcp_snd))
|
40
|
+
end
|
41
|
+
|
42
|
+
def save_cpu_usage_as_google_api_rec(file_path)
|
43
|
+
self.save(export_as_google_api_format_rec(@tcp_rec), file_path)
|
44
|
+
end
|
45
|
+
|
46
|
+
def save_cpu_usage_as_google_api_snd(file_path)
|
47
|
+
self.save(export_as_google_api_format_snd(@tcp_snd), file_path)
|
48
|
+
end
|
49
|
+
|
50
|
+
def store_tcp_rec(dumped_tcp_rec)
|
51
|
+
@tcp_rec.push self.merge_current_time(transfer_tcp_rec_to_hash_rec(dumped_tcp_rec))
|
52
|
+
end
|
53
|
+
|
54
|
+
def store_tcp_snd(dumped_tcp_snd)
|
55
|
+
@tcp_snd.push self.merge_current_time(transfer_tcp_rec_to_hash_snd(dumped_tcp_snd))
|
56
|
+
end
|
57
|
+
|
58
|
+
def transfer_tcp_rec_to_hash_rec(dumped_tcp_rec)
|
59
|
+
{
|
60
|
+
tcp_rec: dumped_tcp_rec[0]
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def transfer_tcp_rec_to_hash_snd(dumped_tcp_snd)
|
65
|
+
{
|
66
|
+
tcp_snd: dumped_tcp_snd[0]
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def export_as_google_api_format_rec(from_tcp_rec)
|
71
|
+
google_api_data_format = empty_google_api_format_rec
|
72
|
+
|
73
|
+
from_tcp_rec.each do |hash|
|
74
|
+
|
75
|
+
a_google_api_data_format = {
|
76
|
+
c: [
|
77
|
+
{ v: hash[:time] },
|
78
|
+
{ v: hash[:tcp_rec] },
|
79
|
+
]
|
80
|
+
}
|
81
|
+
google_api_data_format[:rows].push(a_google_api_data_format)
|
82
|
+
end
|
83
|
+
|
84
|
+
JSON.generate google_api_data_format
|
85
|
+
end
|
86
|
+
|
87
|
+
def export_as_google_api_format_snd(from_tcp_snd)
|
88
|
+
google_api_data_format = empty_google_api_format_snd
|
89
|
+
|
90
|
+
from_tcp_snd.each do |hash|
|
91
|
+
|
92
|
+
a_google_api_data_format = {
|
93
|
+
c: [
|
94
|
+
{ v: hash[:time] },
|
95
|
+
{ v: hash[:tcp_snd] },
|
96
|
+
]
|
97
|
+
}
|
98
|
+
google_api_data_format[:rows].push(a_google_api_data_format)
|
99
|
+
end
|
100
|
+
|
101
|
+
JSON.generate google_api_data_format
|
102
|
+
end
|
103
|
+
|
104
|
+
# @params [String] data_file_path A path to data.
|
105
|
+
# @params [Hash] graph_opts A hash regarding graph settings.
|
106
|
+
# @params [String] output_file_path A path you would like to export data.
|
107
|
+
def create_graph(data_file_path, graph_opts = {}, output_file_path)
|
108
|
+
self.save(Droid::Monitor::GoogleApiTemplate.create_graph(data_file_path, graph_opts),
|
109
|
+
output_file_path)
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def empty_google_api_format_rec
|
115
|
+
{
|
116
|
+
cols: [
|
117
|
+
{ label: 'time', type: 'string' },
|
118
|
+
{ label: 'tcp_rec', type: 'number' },
|
119
|
+
],
|
120
|
+
rows: [
|
121
|
+
],
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
125
|
+
def empty_google_api_format_snd
|
126
|
+
{
|
127
|
+
cols: [
|
128
|
+
{ label: 'time', type: 'string' },
|
129
|
+
{ label: 'tcp_snd', type: 'number' },
|
130
|
+
],
|
131
|
+
rows: [
|
132
|
+
],
|
133
|
+
}
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
end # class Cpu
|
138
|
+
end # module Monitor
|
139
|
+
end # module Droid
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative "../lib/droid/monitor/net"
|
2
|
+
require "clockwork"
|
3
|
+
|
4
|
+
module Clockwork
|
5
|
+
@net = Droid::Monitor::Net.new( { package: "com.android.chrome" } )
|
6
|
+
@time = 0
|
7
|
+
@data_file = "sample.txt"
|
8
|
+
@data_file2 = "sample2.txt"
|
9
|
+
|
10
|
+
every(0.5.seconds, "capture nets usage") do
|
11
|
+
@net.store_dumped_tcp_rcv
|
12
|
+
@net.store_dumped_tcp_snd
|
13
|
+
@time += 1
|
14
|
+
|
15
|
+
if @time == 40
|
16
|
+
@net.save_cpu_usage_as_google_api_rec(@data_file)
|
17
|
+
@net.save_cpu_usage_as_google_api_snd(@data_file2)
|
18
|
+
graph_opts = { title: "Example", header1: "this graph is just sample"}
|
19
|
+
@net.create_graph(@data_file, graph_opts, "result.html")
|
20
|
+
@net.create_graph(@data_file2, graph_opts, "result2.html")
|
21
|
+
|
22
|
+
@net.clear_tcps
|
23
|
+
puts "saved"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/test/net_test.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require './lib/droid/monitor/net'
|
4
|
+
|
5
|
+
PACKAGE_PID = <<-EOS
|
6
|
+
userId=10475 gids=[1028, 1015, 3003]
|
7
|
+
EOS
|
8
|
+
|
9
|
+
TCP_RCV = "174934"
|
10
|
+
|
11
|
+
TCP_SND = "374934"
|
12
|
+
|
13
|
+
class MemoryTest < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@net = Droid::Monitor::Net.new( { package: "com.android.chrome" } )
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
@net.clear_tcps
|
21
|
+
@net = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_initialize
|
25
|
+
assert_instance_of(Droid::Monitor::Net, @net)
|
26
|
+
|
27
|
+
assert_equal("com.android.chrome", @net.package)
|
28
|
+
assert_equal([], @net.tcp_rec)
|
29
|
+
assert_equal([], @net.tcp_snd)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_push_current_time
|
33
|
+
assert_equal(@net.merge_current_time({}).length, 1)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_dump_net_recive_once
|
37
|
+
expected = [174934]
|
38
|
+
assert_equal(expected, @net.dump_tcp_rcv_usage(TCP_RCV))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_dump_net_recive_zero
|
42
|
+
dummy_array = [0]
|
43
|
+
|
44
|
+
@net.store_tcp_rec(dummy_array)
|
45
|
+
|
46
|
+
expected_json = "[{\"tcp_rec\":0,\"time\":\"#{@net.tcp_rec[0][:time]}\"}]"
|
47
|
+
assert_equal(expected_json, JSON.generate(@net.tcp_rec))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_dump_net_recive_twice
|
51
|
+
dummy_array = [0]
|
52
|
+
|
53
|
+
@net.store_tcp_rec(dummy_array)
|
54
|
+
|
55
|
+
result = @net.dump_tcp_rcv_usage(TCP_RCV)
|
56
|
+
|
57
|
+
@net.store_tcp_rec(result)
|
58
|
+
|
59
|
+
expected_json = "[{\"tcp_rec\":0,\"time\":\"#{@net.tcp_rec[0][:time]}\"},{\"tcp_rec\":174934,\"time\":\"#{@net.tcp_rec[1][:time]}\"}]"
|
60
|
+
assert_equal(expected_json, JSON.generate(@net.tcp_rec))
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_dump_net_send_once
|
64
|
+
expected = [374934]
|
65
|
+
assert_equal(expected, @net.dump_tcp_snd_usage(TCP_SND))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_dump_net_send_zero
|
69
|
+
dummy_array = [0]
|
70
|
+
|
71
|
+
@net.store_tcp_snd(dummy_array)
|
72
|
+
|
73
|
+
expected_json = "[{\"tcp_snd\":0,\"time\":\"#{@net.tcp_snd[0][:time]}\"}]"
|
74
|
+
assert_equal(expected_json, JSON.generate(@net.tcp_snd))
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_dump_net_send_twice
|
78
|
+
dummy_array = [0]
|
79
|
+
|
80
|
+
@net.store_tcp_snd(dummy_array)
|
81
|
+
|
82
|
+
result = @net.dump_tcp_snd_usage(TCP_SND)
|
83
|
+
|
84
|
+
@net.store_tcp_snd(result)
|
85
|
+
|
86
|
+
expected_json = "[{\"tcp_snd\":0,\"time\":\"#{@net.tcp_snd[0][:time]}\"},{\"tcp_snd\":374934,\"time\":\"#{@net.tcp_snd[1][:time]}\"}]"
|
87
|
+
assert_equal(expected_json, JSON.generate(@net.tcp_snd))
|
88
|
+
end
|
89
|
+
end
|
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
|
+
version: 0.2.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: 2015-
|
11
|
+
date: 2015-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faml
|
@@ -95,12 +95,15 @@ files:
|
|
95
95
|
- Rakefile
|
96
96
|
- doc/images/Screen Shot 2015-05-23 at 19.46.08.png
|
97
97
|
- doc/images/Screen Shot 2015-05-23 at 19.56.41.png
|
98
|
+
- doc/images/Screen Shot 2015-07-01 10.18.57.png
|
99
|
+
- doc/images/Screen Shot 2015-07-01 10.19.11.png
|
98
100
|
- droid-monitor.gemspec
|
99
101
|
- lib/droid/monitor.rb
|
100
102
|
- lib/droid/monitor/common/commons.rb
|
101
103
|
- lib/droid/monitor/common/utils.rb
|
102
104
|
- lib/droid/monitor/cpu.rb
|
103
105
|
- lib/droid/monitor/memory.rb
|
106
|
+
- lib/droid/monitor/net.rb
|
104
107
|
- lib/droid/monitor/report/google_api_template.rb
|
105
108
|
- lib/droid/monitor/report/templates/template_google_api_format.haml
|
106
109
|
- lib/droid/monitor/version.rb
|
@@ -108,11 +111,13 @@ files:
|
|
108
111
|
- sample/Gemfile.lock
|
109
112
|
- sample/example_cpu.rb
|
110
113
|
- sample/example_memory.rb
|
114
|
+
- sample/example_net.rb
|
111
115
|
- sample/result.html
|
112
116
|
- sample/sample.txt
|
113
117
|
- test/cpu_test.rb
|
114
118
|
- test/memory_test.rb
|
115
119
|
- test/monitor_test.rb
|
120
|
+
- test/net_test.rb
|
116
121
|
- test/run_test.rb
|
117
122
|
homepage: https://github.com/KazuCocoa/droid-monitor
|
118
123
|
licenses:
|
@@ -143,4 +148,5 @@ test_files:
|
|
143
148
|
- test/cpu_test.rb
|
144
149
|
- test/memory_test.rb
|
145
150
|
- test/monitor_test.rb
|
151
|
+
- test/net_test.rb
|
146
152
|
- test/run_test.rb
|