droid-monitor 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +16 -0
- data/.travis.yml +14 -9
- data/Gemfile +2 -0
- data/README.md +2 -0
- data/Rakefile +10 -1
- data/droid-monitor.gemspec +18 -16
- data/lib/droid/monitor.rb +23 -16
- data/lib/droid/monitor/common/commons.rb +4 -2
- data/lib/droid/monitor/common/timer.rb +2 -0
- data/lib/droid/monitor/common/utils.rb +2 -0
- data/lib/droid/monitor/cpu.rb +39 -42
- data/lib/droid/monitor/executor/executor.rb +2 -0
- data/lib/droid/monitor/gfxinfo.rb +43 -45
- data/lib/droid/monitor/memory.rb +32 -32
- data/lib/droid/monitor/net.rb +21 -25
- data/lib/droid/monitor/report/google_api_template.rb +4 -2
- data/lib/droid/monitor/version.rb +3 -1
- data/sample/Gemfile +5 -3
- data/sample/example_cpu.rb +11 -9
- data/sample/example_gfxinfo.rb +14 -12
- data/sample/example_memory.rb +11 -9
- data/sample/example_net.rb +12 -10
- data/test/cpu_test.rb +67 -67
- data/test/gfxinfo_test.rb +249 -251
- data/test/memory_test.rb +206 -208
- data/test/monitor/timer_test.rb +2 -0
- data/test/monitor_test.rb +9 -9
- data/test/net_test.rb +10 -9
- data/test/run_test.rb +2 -0
- metadata +31 -17
- data/sample/Gemfile.lock +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '019f451202097810f6434f9f093815f4b4796c592c1e2abd917bf96d64d3265b'
|
4
|
+
data.tar.gz: 77a5c9a451a42fd2ff660cd2d2848ec686408a05a0bae99f1eda1db1c639cf09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3faf985803dc5babcd3c40578972b4e539e57e4fb618ca731d7ff18e3a0e3c4cc49a653bceef415fee69f820a6dae1ffa8c7e38131ccdd271a3ecf35d00b481
|
7
|
+
data.tar.gz: fb8a76c3264134608f41ce4c41a591e2617419f76016aa40fc87481c9ccfa4b285508d2f63ffffec65fd0e9c4740e7bc1a34b87b48f826bd9bd7a784198556f6
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
Metrics/LineLength:
|
4
|
+
Enabled: false
|
5
|
+
Metrics/AbcSize:
|
6
|
+
Enabled: false
|
7
|
+
Metrics/MethodLength:
|
8
|
+
Enabled: false
|
9
|
+
Metrics/ClassLength:
|
10
|
+
Enabled: false
|
11
|
+
Style/Documentation:
|
12
|
+
Enabled: false
|
13
|
+
Style/CommentedKeyword:
|
14
|
+
Enabled: false
|
15
|
+
Naming/HeredocDelimiterNaming:
|
16
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,16 +1,21 @@
|
|
1
|
+
sudo: false
|
2
|
+
#cache: bundler
|
1
3
|
language: ruby
|
2
4
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
|
7
|
-
sudo: false
|
8
|
-
cache: bundler
|
5
|
+
- 2.3
|
6
|
+
- 2.4
|
7
|
+
- 2.5
|
8
|
+
- 2.6
|
9
9
|
|
10
|
-
|
10
|
+
env:
|
11
|
+
- ANDROID_HOME='~' # dummy
|
11
12
|
|
12
|
-
|
13
|
-
-
|
13
|
+
before_install:
|
14
|
+
- gem update --system
|
15
|
+
- gem update bundler
|
16
|
+
- mkdir ~/platform-tools
|
17
|
+
- touch ~/platform-tools/adb
|
14
18
|
|
15
19
|
script:
|
20
|
+
- bundle exec rubocop
|
16
21
|
- ruby test/run_test.rb
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,8 @@ Monitoring Android cpu or memory usage and create their simple graph with Google
|
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/droid-monitor.svg)](http://badge.fury.io/rb/droid-monitor)
|
6
6
|
|
7
|
+
Read also: https://developer.android.com/training/testing/performance
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
data/Rakefile
CHANGED
@@ -1,2 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rubocop/rake_task'
|
5
|
+
|
6
|
+
desc('Execute RuboCop static code analysis')
|
7
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
8
|
+
t.patterns = %w[lib test sample]
|
9
|
+
t.options = %w[-D]
|
10
|
+
t.fail_on_error = true
|
11
|
+
end
|
data/droid-monitor.gemspec
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'droid/monitor/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'droid-monitor'
|
8
9
|
spec.version = Droid::Monitor::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
10
|
+
spec.authors = ['Kazuaki MATSUO']
|
11
|
+
spec.email = ['fly.49.89.over@gmail.com']
|
12
|
+
spec.summary = 'Monitoring Android cpu or memory usage and create their simple graph with Google API.'
|
13
|
+
spec.description = 'Monitoring connected Android devices via adb command. And you can create simple http graph wth Google API.'
|
14
|
+
spec.homepage = 'https://github.com/KazuCocoa/droid-monitor'
|
15
|
+
spec.license = 'MIT'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
20
|
-
spec.required_ruby_version =
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
spec.required_ruby_version = '>= 2.3'
|
21
22
|
|
22
|
-
spec.add_dependency
|
23
|
-
spec.add_dependency
|
24
|
-
spec.add_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
23
|
+
spec.add_dependency 'faml', '~> 0.8'
|
24
|
+
spec.add_dependency 'haml', '~> 5.0' # for using faml to tilt
|
25
|
+
spec.add_dependency 'tilt', '~> 2.0'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'rubocop', '0.61.0'
|
28
|
+
spec.add_development_dependency 'test-unit'
|
27
29
|
end
|
data/lib/droid/monitor.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
require_relative "monitor/common/timer"
|
3
|
-
require_relative "monitor/executor/executor"
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
3
|
+
require_relative 'monitor/version'
|
4
|
+
require_relative 'monitor/common/timer'
|
5
|
+
require_relative 'monitor/executor/executor'
|
6
|
+
|
7
|
+
require 'open3'
|
6
8
|
|
7
9
|
module Droid
|
8
10
|
module Monitor
|
@@ -10,10 +12,11 @@ module Droid
|
|
10
12
|
attr_accessor :package, :device_serial, :api_level
|
11
13
|
|
12
14
|
def initialize(opts = {})
|
13
|
-
raise
|
14
|
-
raise
|
15
|
+
raise 'opts must be a hash' unless opts.is_a? Hash
|
16
|
+
raise 'Package name is required.' unless opts[:package]
|
17
|
+
|
15
18
|
@package = opts[:package]
|
16
|
-
@device_serial = opts[:device_serial] ||
|
19
|
+
@device_serial = opts[:device_serial] || ''
|
17
20
|
@api_level = device_sdk_version
|
18
21
|
@debug = opts[:debug]
|
19
22
|
end
|
@@ -46,15 +49,17 @@ module Droid
|
|
46
49
|
end
|
47
50
|
|
48
51
|
def dump_tcp_rec
|
49
|
-
pid =
|
52
|
+
pid = user_pid
|
50
53
|
return 0 if pid == -1
|
54
|
+
|
51
55
|
puts "pid is #{pid}" if @debug
|
52
56
|
run_adb("#{adb_shell} cat proc/uid_stat/#{pid}/tcp_rcv").to_i
|
53
57
|
end
|
54
58
|
|
55
59
|
def dump_tcp_snd
|
56
|
-
pid =
|
60
|
+
pid = user_pid
|
57
61
|
return 0 if pid == -1
|
62
|
+
|
58
63
|
puts "pid is #{pid}" if @debug
|
59
64
|
run_adb("#{adb_shell} cat proc/uid_stat/#{pid}/tcp_snd").to_i
|
60
65
|
end
|
@@ -66,12 +71,14 @@ module Droid
|
|
66
71
|
private
|
67
72
|
|
68
73
|
def adb
|
69
|
-
raise
|
70
|
-
|
74
|
+
raise 'ANDROID_HOME is not set' unless ENV['ANDROID_HOME']
|
75
|
+
|
76
|
+
"#{ENV['ANDROID_HOME']}/platform-tools/adb"
|
71
77
|
end
|
72
78
|
|
73
79
|
def device_serial_option
|
74
|
-
return
|
80
|
+
return '' unless @device_serial && @device_serial != ''
|
81
|
+
|
75
82
|
"-s \"#{@device_serial}\""
|
76
83
|
end
|
77
84
|
|
@@ -80,19 +87,19 @@ module Droid
|
|
80
87
|
end
|
81
88
|
|
82
89
|
# @return [String] line of packages regarding pid and so on
|
83
|
-
def
|
90
|
+
def user_pid
|
84
91
|
dump = run_adb("#{adb_shell} dumpsys package #{@package}")
|
85
92
|
return -1 if dump.nil?
|
86
93
|
|
87
94
|
userid = dump.scan(/userId=[0-9]+/)
|
88
95
|
return -1 if userid.empty?
|
89
96
|
|
90
|
-
userid.uniq.first.delete(
|
97
|
+
userid.uniq.first.delete('userId=')
|
91
98
|
end
|
92
99
|
|
93
100
|
def run_adb(cmd)
|
94
|
-
out_s, out_e,
|
95
|
-
puts "error: device not found which serial is #{@device_serial}" if out_e.include?(
|
101
|
+
out_s, out_e, _status = Open3.capture3(cmd)
|
102
|
+
puts "error: device not found which serial is #{@device_serial}" if out_e.include?('error: device not found')
|
96
103
|
out_s.chomp unless out_s.nil? || out_s.empty?
|
97
104
|
end
|
98
105
|
end # class Adb
|
data/lib/droid/monitor/cpu.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
require_relative "common/commons"
|
3
|
-
require_relative "report/google_api_template"
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
3
|
+
require_relative '../monitor'
|
4
|
+
require_relative 'common/commons'
|
5
|
+
require_relative 'report/google_api_template'
|
6
|
+
|
7
|
+
require 'json'
|
6
8
|
|
7
9
|
module Droid
|
8
10
|
module Monitor
|
@@ -21,11 +23,12 @@ module Droid
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def dump_cpu_usage(dump_data)
|
24
|
-
scanned_dump = dump_data.scan(/^.*#{
|
26
|
+
scanned_dump = dump_data.scan(/^.*#{package}.*$/).map(&:strip).first
|
25
27
|
return [] if scanned_dump.nil?
|
26
28
|
|
27
29
|
dump = scanned_dump.split(/\s/).reject(&:empty?)
|
28
|
-
|
30
|
+
raise 'no package' if /^Load:$/ =~ dump[0]
|
31
|
+
|
29
32
|
dump
|
30
33
|
rescue StandardError => e
|
31
34
|
puts e
|
@@ -36,9 +39,7 @@ module Droid
|
|
36
39
|
return [] if dump_data.nil?
|
37
40
|
|
38
41
|
dump = dump_data.split(/\s/).reject(&:empty?)
|
39
|
-
|
40
|
-
|
41
|
-
puts dump
|
42
|
+
raise 'no package' if /^Load:$/ =~ dump[0]
|
42
43
|
|
43
44
|
dump
|
44
45
|
rescue StandardError => e
|
@@ -48,27 +49,27 @@ module Droid
|
|
48
49
|
|
49
50
|
# called directory
|
50
51
|
def store_dumped_cpu_usage
|
51
|
-
|
52
|
+
store_cpu_usage(dump_cpu_usage(dump_cpuinfo))
|
52
53
|
end
|
53
54
|
|
54
55
|
def store_dumped_cpu_usage_with_top
|
55
|
-
|
56
|
+
store_cpu_usage_with_top(dump_cpu_usage_with_top(dump_cpuinfo_with_top))
|
56
57
|
end
|
57
58
|
|
58
59
|
def save_cpu_usage_as_google_api(file_path)
|
59
|
-
|
60
|
+
save(export_as_google_api_format(@cpu_usage), file_path)
|
60
61
|
end
|
61
62
|
|
62
63
|
def save_cpu_usage_as_google_api_with_top(file_path)
|
63
|
-
|
64
|
+
save(export_as_google_api_format_with_top(@cpu_usage), file_path)
|
64
65
|
end
|
65
66
|
|
66
67
|
def store_cpu_usage(dumped_cpu)
|
67
|
-
@cpu_usage.push
|
68
|
+
@cpu_usage.push merge_current_time(transfer_total_cpu_to_hash(dumped_cpu))
|
68
69
|
end
|
69
70
|
|
70
71
|
def store_cpu_usage_with_top(dumped_cpu)
|
71
|
-
@cpu_usage.push
|
72
|
+
@cpu_usage.push merge_current_time(transfer_total_cpu_with_top_to_hash(dumped_cpu))
|
72
73
|
end
|
73
74
|
|
74
75
|
def transfer_total_cpu_to_hash(dump_cpu_array)
|
@@ -78,7 +79,7 @@ module Droid
|
|
78
79
|
process: 'no package process',
|
79
80
|
user: '0%',
|
80
81
|
kernel: '0%',
|
81
|
-
time: dump_cpu_array.last
|
82
|
+
time: dump_cpu_array.last
|
82
83
|
}
|
83
84
|
else
|
84
85
|
{
|
@@ -86,7 +87,7 @@ module Droid
|
|
86
87
|
process: dump_cpu_array[1],
|
87
88
|
user: dump_cpu_array[2],
|
88
89
|
kernel: dump_cpu_array[5],
|
89
|
-
time: dump_cpu_array.last
|
90
|
+
time: dump_cpu_array.last
|
90
91
|
}
|
91
92
|
end
|
92
93
|
end
|
@@ -94,15 +95,15 @@ module Droid
|
|
94
95
|
def transfer_total_cpu_with_top_to_hash(dump_cpu_array)
|
95
96
|
if dump_cpu_array.length <= 1
|
96
97
|
{
|
97
|
-
|
98
|
-
|
99
|
-
|
98
|
+
total_cpu: '0%',
|
99
|
+
process: 'no package process',
|
100
|
+
time: dump_cpu_array.last
|
100
101
|
}
|
101
102
|
else
|
102
103
|
{
|
103
|
-
|
104
|
-
|
105
|
-
|
104
|
+
total_cpu: dump_cpu_array[2],
|
105
|
+
process: dump_cpu_array[0],
|
106
|
+
time: dump_cpu_array.last
|
106
107
|
}
|
107
108
|
end
|
108
109
|
end
|
@@ -111,13 +112,12 @@ module Droid
|
|
111
112
|
google_api_data_format = empty_google_api_format
|
112
113
|
|
113
114
|
from_cpu_usage.each do |hash|
|
114
|
-
|
115
115
|
a_google_api_data_format = {
|
116
116
|
c: [
|
117
117
|
{ v: hash[:time] },
|
118
118
|
{ v: hash[:total_cpu].delete('%').to_f },
|
119
119
|
{ v: hash[:user].delete('%').to_f },
|
120
|
-
{ v: hash[:kernel].delete('%').to_f }
|
120
|
+
{ v: hash[:kernel].delete('%').to_f }
|
121
121
|
]
|
122
122
|
}
|
123
123
|
google_api_data_format[:rows].push(a_google_api_data_format)
|
@@ -130,12 +130,11 @@ module Droid
|
|
130
130
|
google_api_data_format = empty_google_api_format_with_top
|
131
131
|
|
132
132
|
from_cpu_usage.each do |hash|
|
133
|
-
|
134
133
|
a_google_api_data_format = {
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
134
|
+
c: [
|
135
|
+
{ v: hash[:time] },
|
136
|
+
{ v: hash[:total_cpu].delete('%').to_f }
|
137
|
+
]
|
139
138
|
}
|
140
139
|
google_api_data_format[:rows].push(a_google_api_data_format)
|
141
140
|
end
|
@@ -146,9 +145,9 @@ module Droid
|
|
146
145
|
# @params [String] data_file_path A path to data.
|
147
146
|
# @params [Hash] graph_opts A hash regarding graph settings.
|
148
147
|
# @params [String] output_file_path A path you would like to export data.
|
149
|
-
def create_graph(data_file_path, graph_opts = {}, output_file_path)
|
150
|
-
|
151
|
-
|
148
|
+
def create_graph(data_file_path, graph_opts = {}, output_file_path) # rubocop:disable Style/OptionalArguments
|
149
|
+
save(Droid::Monitor::GoogleApiTemplate.create_graph(data_file_path, graph_opts),
|
150
|
+
output_file_path)
|
152
151
|
end
|
153
152
|
|
154
153
|
private
|
@@ -159,21 +158,19 @@ module Droid
|
|
159
158
|
{ label: 'time', type: 'string' },
|
160
159
|
{ label: 'total_cpu', type: 'number' },
|
161
160
|
{ label: 'user', type: 'number' },
|
162
|
-
{ label: 'kernel', type: 'number' }
|
163
|
-
],
|
164
|
-
rows: [
|
161
|
+
{ label: 'kernel', type: 'number' }
|
165
162
|
],
|
163
|
+
rows: []
|
166
164
|
}
|
167
165
|
end
|
168
166
|
|
169
167
|
def empty_google_api_format_with_top
|
170
168
|
{
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
],
|
169
|
+
cols: [
|
170
|
+
{ label: 'time', type: 'string' },
|
171
|
+
{ label: 'total_cpu', type: 'number' }
|
172
|
+
],
|
173
|
+
rows: []
|
177
174
|
}
|
178
175
|
end
|
179
176
|
end # class Cpu
|