blink_tm 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79578d594763d5de1330239dd259bf7eec1fdc08a617710f4229f7fa0f3c8dfc
4
- data.tar.gz: b96f080cfa95f9eaa26549a88d32e8054773524a4218dacd1e70e8b552fbca82
3
+ metadata.gz: 3a36bc60afc808cd46592945eebb5522b017af21743da1cdc71eeb381a7367dd
4
+ data.tar.gz: 8a5d4c012fdad495381e8fe4caafa39e9b3aafa8490f52dc83460cecc8826296
5
5
  SHA512:
6
- metadata.gz: f4e8827f0b2ca289a5b723c3b8756ba762ea2e114155a94d836c9e290ad0be3905d6debffcadc76673cc2bcbab7477f5137e1ceafbcb05a2eb54a70c5920669c
7
- data.tar.gz: ad1ca0d05c0284908e303719c310961c4123d3ede63910c635520a014a62eb3247eb9015634edb7d3124d364b1f4f9df164a26a306a93e908d5c9704c389af92
6
+ metadata.gz: ac2ac55e696cb64a0260057029633e1132255d1956f9a484c841515fb3b9dac92d21ec6b4f7287186396c0c4bd3b54f301b69be88126616ee2ef4c9ffdd1a84c
7
+ data.tar.gz: 59454494c4df79ed7918e925c7e9cacf8db35b1e2b698e2192ba1c953829db023fb28d876075d736e9128f1940adc78d20892f3b3e75ec9201c961fad565f114
data/lib/blink_tm.rb CHANGED
@@ -5,10 +5,13 @@ module BlinkTM
5
5
  # Important Constants
6
6
  BAUDRATE = BlinkTM::B57600
7
7
  SCANID = 'BTM'
8
+
9
+ # POLLING time, how often should CPU, Net, IO usages should be updated.
10
+ # Should always be a float.
8
11
  POLLING = 0.375
9
12
 
10
- # Refresh should always get subtracted with 0.05
11
- REFRESH = 0.5 - 0.05
13
+ # Refresh time, how often the main loop should run
14
+ REFRESH = 0.5
12
15
 
13
16
  # Errors
14
17
  NoDeviceError = Class.new(StandardError)
@@ -30,4 +33,6 @@ module BlinkTM
30
33
  end
31
34
 
32
35
  require 'blink_tm/version'
36
+ require 'fcntl'
37
+ require 'linux_stat'
33
38
  require 'blink_tm/blink_tm'
@@ -1,9 +1,6 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # Frozen_String_Literal: true
3
3
 
4
- require 'fcntl'
5
- require 'linux_stat'
6
-
7
4
  module BlinkTM
8
5
  # Detect device
9
6
  def find_device
@@ -97,8 +94,8 @@ module BlinkTM
97
94
  sleep POLLING
98
95
  io_stat2 = iostat()
99
96
 
100
- io_r = io_stat2[0].-(io_stat1[0]) / POLLING
101
- io_w = io_stat2[1].-(io_stat1[1]) / POLLING
97
+ io_r = io_stat2[0].-(io_stat1[0]).fdiv(POLLING)
98
+ io_w = io_stat2[1].-(io_stat1[1]).fdiv(POLLING)
102
99
  end
103
100
  }
104
101
 
@@ -132,6 +129,7 @@ module BlinkTM
132
129
  end
133
130
 
134
131
  puts "#{BlinkTM::BOLD}#{BlinkTM::GREEN}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Device ready!#{BlinkTM::RESET}"
132
+ refresh = 0
135
133
 
136
134
  while true
137
135
  # cpu(01234) memUsed(999993) swapUsed(999992) io_active(0)
@@ -156,23 +154,15 @@ module BlinkTM
156
154
  # "#{convert_bytes(net_u)} #{convert_bytes(net_d)} "\
157
155
  # "#{convert_bytes(io_r)} #{convert_bytes(io_w)}"
158
156
 
159
- str = "#{"%03d" % cpu_u}#{"%03d" % mem_u}#{"%03d" % swap_u}"\
157
+ refresh ^= 1
158
+
159
+ str = "!##{"%03d" % cpu_u}#{"%03d" % mem_u}#{"%03d" % swap_u}"\
160
160
  "#{convert_bytes(net_u)}#{convert_bytes(net_d)}"\
161
- "#{convert_bytes(io_r)}#{convert_bytes(io_w)}"
161
+ "#{convert_bytes(io_r)}#{convert_bytes(io_w)}#{refresh}~"
162
162
 
163
163
  # Rescuing from suspend
164
- file.syswrite('#')
165
-
166
- file.syswrite('!')
167
- file.flush
168
- sleep 0.025
169
-
170
164
  file.syswrite(str)
171
165
  file.flush
172
- sleep 0.025
173
-
174
- file.syswrite('~')
175
- file.flush
176
166
 
177
167
  sleep REFRESH
178
168
  end
@@ -208,14 +198,23 @@ module BlinkTM
208
198
 
209
199
  @@sector_size ||= LS::FS.stat(?/)[:block_size]
210
200
 
211
- io_stat = IO.foreach('/proc/diskstats'.freeze).find { |x|
212
- x.split[2] == @@root_partition
213
- } &.split.to_a
201
+ io = []
202
+
203
+ IO.foreach('/proc/diskstats') { |x|
204
+ splitted = x.split
205
+
206
+ if splitted[2] == @@root_partition
207
+ # IO read / write
208
+ io.replace([
209
+ splitted[5].to_i * @@sector_size,
210
+ splitted[9].to_i * @@sector_size
211
+ ])
214
212
 
215
- _io_r = io_stat[5].to_f.*(@@sector_size).round
216
- _io_w = io_stat[9].to_f.*(@@sector_size).round
213
+ break
214
+ end
215
+ }
217
216
 
218
- [_io_r, _io_w]
217
+ io
219
218
  end
220
219
 
221
220
  extend(self)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlinkTM
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blink_tm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourav Goswami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-26 00:00:00.000000000 Z
11
+ date: 2021-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: linux_stat