droid-monitor 0.5.1 → 0.6.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: 2cb86c37a079c2bbf1d9e91c8142ce9f0c144996
4
- data.tar.gz: 943c16826b77c447846ee4e6e337e4cc7d6ea048
3
+ metadata.gz: e89fb94f493d1e714a085b2802651c25557907b2
4
+ data.tar.gz: 824ac015895dfba0555ad9c0c30c3236fb7a8583
5
5
  SHA512:
6
- metadata.gz: e53173202d67e70316d6adc8fed54d6b3704602d62317984961cb52545d39184e69aed1ef88ed4b0f2c314835770287ef3f30a9881a778402f0c637fd98d5ec3
7
- data.tar.gz: 556ebbefc43e68a3dd3066b890919fe22249541953380c4492e47091fc8744f0add3b78e1a3a70b815f8b8e652a189e5f5a290c63df1e0c76aa7ebb329d8ff7f
6
+ metadata.gz: 491c735e8d6407ea5642a3cdf3528b53f3036583f5c8edffaa5b443e513a7f75b8b1dba09a301885dbdd14d9441b9904c9f5b9734641238b7a55a1c2d2b0004c
7
+ data.tar.gz: c8acf9d717f88e49272709b3523218690e12a314413b7d52f3671b2b0311ff28ae6e60aed0913e41438b29be6cacef84093a1e541c6382394721200bf256282f
@@ -1,4 +1,6 @@
1
1
  require_relative "monitor/version"
2
+ require_relative "monitor/common/timer"
3
+ require_relative "monitor/executor/executor"
2
4
 
3
5
  require "Open3"
4
6
 
@@ -8,8 +10,8 @@ module Droid
8
10
  attr_accessor :package, :device_serial, :api_level
9
11
 
10
12
  def initialize(opts = {})
11
- fail "opts must be a hash" unless opts.is_a? Hash
12
- fail "Package name is required." unless opts[:package]
13
+ raise "opts must be a hash" unless opts.is_a? Hash
14
+ raise "Package name is required." unless opts[:package]
13
15
  @package = opts[:package]
14
16
  @device_serial = opts[:device_serial] || ""
15
17
  @api_level = device_sdk_version
@@ -64,7 +66,7 @@ module Droid
64
66
  private
65
67
 
66
68
  def adb
67
- fail "ANDROID_HOME is not set" unless ENV["ANDROID_HOME"]
69
+ raise "ANDROID_HOME is not set" unless ENV["ANDROID_HOME"]
68
70
  "#{ENV["ANDROID_HOME"]}/platform-tools/adb"
69
71
  end
70
72
 
@@ -0,0 +1,52 @@
1
+ module Droid
2
+ module Monitor
3
+ module Timer
4
+ class Executor
5
+ attr_reader :interval
6
+
7
+ # @param [int] interval Interval to wait
8
+ def initialize(interval)
9
+ @interval = interval
10
+ end
11
+
12
+ # @param [Block] &block Yield the block after sleep @interval
13
+ # @return [Symbol] :finished
14
+ def execute
15
+ sleep interval
16
+ yield
17
+
18
+ :finished
19
+ end
20
+
21
+ # Loop `execute` until stopping its process
22
+ # @param [Block] &block Yield the block after sleep @interval
23
+ # @return [Symbol] :finished
24
+ def execute_loop(&block)
25
+ loop { execute(&block) }
26
+ end
27
+
28
+ # Start
29
+ # t = timer.execute_loop_thread { puts "#{Time.now}" }
30
+ # Stop
31
+ # timer.kill_thread t
32
+ #
33
+ # Loop `execute` until stopping its process on the other thread
34
+ # @param [Block] &block Yield the block after sleep @interval
35
+ # @return [Symbol] :finished
36
+ def execute_loop_thread(&block)
37
+ Thread.new { loop { execute(&block) } }
38
+ end
39
+
40
+ # @param [Thread] thread Kill the thread
41
+ def kill_thread(thread)
42
+ Thread.kill thread
43
+ end
44
+
45
+ # @return [Array[Thread]] Return a list running thread on the process
46
+ def thread_list
47
+ Thread.list
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,19 @@
1
+ module Droid
2
+ module Monitor
3
+ class Executor
4
+ class Base
5
+ def execute(_timer)
6
+ raise NotImplementedError
7
+ end
8
+
9
+ def save
10
+ raise NotImplementedError
11
+ end
12
+
13
+ def kill
14
+ raise NotImplementedError
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  module Droid
2
2
  module Monitor
3
- VERSION = "0.5.1"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -0,0 +1,24 @@
1
+ require 'test/unit'
2
+
3
+ require './lib/droid/monitor/common/timer'
4
+
5
+ module Droid
6
+ module Monitor
7
+ class TimerTest < Test::Unit::TestCase
8
+ def test_timer
9
+ timer = Timer::Executor.new(0.1)
10
+ assert_equal(0.1, timer.interval)
11
+
12
+ thread_size = Thread.list.size
13
+ thread = timer.execute_loop_thread { 1 }
14
+ assert_equal(thread_size + 1, Thread.list.size)
15
+ assert_equal('run', thread.status)
16
+
17
+ timer.kill_thread thread
18
+ sleep 0.1
19
+ assert_equal(false, thread.status)
20
+ assert_equal(thread_size, Thread.list.size)
21
+ end
22
+ end
23
+ end
24
+ 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.5.1
4
+ version: 0.6.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: 2017-05-30 00:00:00.000000000 Z
11
+ date: 2017-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faml
@@ -104,8 +104,10 @@ files:
104
104
  - droid-monitor.gemspec
105
105
  - lib/droid/monitor.rb
106
106
  - lib/droid/monitor/common/commons.rb
107
+ - lib/droid/monitor/common/timer.rb
107
108
  - lib/droid/monitor/common/utils.rb
108
109
  - lib/droid/monitor/cpu.rb
110
+ - lib/droid/monitor/executor/executor.rb
109
111
  - lib/droid/monitor/gfxinfo.rb
110
112
  - lib/droid/monitor/memory.rb
111
113
  - lib/droid/monitor/net.rb
@@ -123,6 +125,7 @@ files:
123
125
  - test/cpu_test.rb
124
126
  - test/gfxinfo_test.rb
125
127
  - test/memory_test.rb
128
+ - test/monitor/timer_test.rb
126
129
  - test/monitor_test.rb
127
130
  - test/net_test.rb
128
131
  - test/run_test.rb
@@ -155,6 +158,7 @@ test_files:
155
158
  - test/cpu_test.rb
156
159
  - test/gfxinfo_test.rb
157
160
  - test/memory_test.rb
161
+ - test/monitor/timer_test.rb
158
162
  - test/monitor_test.rb
159
163
  - test/net_test.rb
160
164
  - test/run_test.rb