blink_tm 0.1.3 → 0.2.0

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: 3a36bc60afc808cd46592945eebb5522b017af21743da1cdc71eeb381a7367dd
4
- data.tar.gz: 8a5d4c012fdad495381e8fe4caafa39e9b3aafa8490f52dc83460cecc8826296
3
+ metadata.gz: db910772825de89e18bf29aa17905561b275accef99af4ce513f7bdee177b531
4
+ data.tar.gz: d67946a495717d5fb69c0c8a82b0c3af779a59a1afd1384d2a9e2bc172fd2a34
5
5
  SHA512:
6
- metadata.gz: ac2ac55e696cb64a0260057029633e1132255d1956f9a484c841515fb3b9dac92d21ec6b4f7287186396c0c4bd3b54f301b69be88126616ee2ef4c9ffdd1a84c
7
- data.tar.gz: 59454494c4df79ed7918e925c7e9cacf8db35b1e2b698e2192ba1c953829db023fb28d876075d736e9128f1940adc78d20892f3b3e75ec9201c961fad565f114
6
+ metadata.gz: 13d05ea503502ffacdaec63e656dc23bfb11d4f4190a1be9925989d2278d6444547bd659297d8b1f281b421fd8f67ac8ec7ad2a3e80f10ddd5a551838643adbf
7
+ data.tar.gz: 4966f3fe0180f4b7b366dadf621a29a8d3712ee2e8a5b60e6219be5df5b2902b857d8562920f674d136fb60ecadaeeec992ebe1fffc4d24e715c5e399d733973
data/exe/blink-tm CHANGED
@@ -9,9 +9,9 @@ while(!dev)
9
9
  dev = BlinkTM.find_device
10
10
 
11
11
  if dev
12
- puts "#{BlinkTM::BOLD}#{BlinkTM::GREEN}:: Device discovered successfully. Path: #{dev}#{BlinkTM::RESET}"
12
+ puts "#{BlinkTM::BOLD}#{BlinkTM::GREEN}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Device discovered successfully. Path: #{dev}#{BlinkTM::RESET}"
13
13
  else
14
- puts "#{BlinkTM::BOLD}#{BlinkTM::RED}:: No device found. Retrying #{retry_count += 1}#{BlinkTM::RESET}"
14
+ puts "#{BlinkTM::BOLD}#{BlinkTM::RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: No device found. Retrying #{retry_count += 1}#{BlinkTM::RESET}"
15
15
  sleep 0.5
16
16
  end
17
17
  end
@@ -0,0 +1,41 @@
1
+ #include <stdio.h>
2
+ #include <string.h>
3
+
4
+ #include <sys/ioctl.h>
5
+ #include <fcntl.h>
6
+ #include <linux/fs.h>
7
+
8
+ #include "ruby.h"
9
+ #include "sectors.h"
10
+
11
+ VALUE getDiskstats (volatile VALUE obj, volatile VALUE path) {
12
+ FILE *file = fopen("/proc/diskstats", "r") ;
13
+ if(!file) return rb_ary_new() ;
14
+
15
+ char lines[120] ;
16
+ unsigned long long read, write ;
17
+ char *p = StringValuePtr(path) ;
18
+
19
+ while(fgets(lines, 119, file)) {
20
+ sscanf(lines, "%*s %*s %s %*s %*s %llu %*s %*s %*s %llu", lines, &read, &write) ;
21
+
22
+ if(strcmp(lines, p) == 0) {
23
+ fclose(file) ;
24
+
25
+ return rb_ary_new_from_args(
26
+ 2,
27
+ ULL2NUM(read),
28
+ ULL2NUM(write)
29
+ ) ;
30
+ }
31
+ }
32
+
33
+ fclose(file) ;
34
+ return rb_ary_new() ;
35
+ }
36
+
37
+ void Init_diskstats() {
38
+ VALUE blink_tm = rb_define_module("BlinkTM") ;
39
+ rb_define_module_function(blink_tm, "diskstats", getDiskstats, 1) ;
40
+ rb_define_module_function(blink_tm, "get_sector_size", getSectorSize, 1) ;
41
+ }
@@ -0,0 +1,2 @@
1
+ require 'mkmf'
2
+ create_makefile 'blink_tm/diskstats'
@@ -0,0 +1,15 @@
1
+ VALUE getSectorSize (volatile VALUE obj, volatile VALUE path) {
2
+ char *dev = StringValuePtr(path) ;
3
+
4
+ unsigned int fd ;
5
+ unsigned int sSize = 0 ;
6
+
7
+ fd = open(dev, O_RDONLY | O_NONBLOCK) ;
8
+ if(fd < 0) return Qnil ;
9
+
10
+ short status = ioctl(fd, BLKSSZGET, &sSize) ;
11
+ close(fd) ;
12
+ if(status < 0) return Qnil ;
13
+
14
+ return USHORT2NUM(sSize) ;
15
+ }
data/lib/blink_tm.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # Frozen_String_Literal: true
2
2
  require 'blink_tm/baudrate'
3
+ require 'blink_tm/diskstats'
4
+ require 'linux_stat'
3
5
 
4
6
  module BlinkTM
5
7
  # Important Constants
@@ -30,9 +32,17 @@ module BlinkTM
30
32
  ORANGE = "\e[38;2;245;155;20m"
31
33
  BOLD = "\e[1m"
32
34
  RESET = "\e[0m"
35
+
36
+ # Other constants
37
+ ROOT_DEV = ::LinuxStat::Mounts.root
38
+ ROOT = File.split(ROOT_DEV)[-1]
39
+
40
+ SECTORS = get_sector_size(ROOT_DEV)
41
+
42
+ abort "#{BOLD}#{RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Can't get root partition#{RESET}" unless ROOT
43
+ abort "#{BOLD}#{RED}:: #{Time.now.strftime('%H:%M:%S.%2N')}: Can't get sector size#{RESET}" unless SECTORS
33
44
  end
34
45
 
35
46
  require 'blink_tm/version'
36
47
  require 'fcntl'
37
- require 'linux_stat'
38
48
  require 'blink_tm/blink_tm'
@@ -90,12 +90,12 @@ module BlinkTM
90
90
 
91
91
  Thread.new {
92
92
  while true
93
- io_stat1 = iostat()
93
+ io_stat1 = BlinkTM.diskstats(ROOT)
94
94
  sleep POLLING
95
- io_stat2 = iostat()
95
+ io_stat2 = BlinkTM.diskstats(ROOT)
96
96
 
97
- io_r = io_stat2[0].-(io_stat1[0]).fdiv(POLLING)
98
- io_w = io_stat2[1].-(io_stat1[1]).fdiv(POLLING)
97
+ io_r = io_stat2[0].-(io_stat1[0]).*(SECTORS).fdiv(POLLING)
98
+ io_w = io_stat2[1].-(io_stat1[1]).*(SECTORS).fdiv(POLLING)
99
99
  end
100
100
  }
101
101
 
@@ -103,7 +103,7 @@ module BlinkTM
103
103
  raise NoDeviceError unless device
104
104
 
105
105
  in_sync = false
106
- fd = IO.sysopen(device, Fcntl::O_RDWR | Fcntl::O_EXCL)
106
+ fd = IO.sysopen(device, Fcntl::O_RDWR)
107
107
  file = IO.open(fd)
108
108
 
109
109
  until in_sync
@@ -156,7 +156,7 @@ module BlinkTM
156
156
 
157
157
  refresh ^= 1
158
158
 
159
- str = "!##{"%03d" % cpu_u}#{"%03d" % mem_u}#{"%03d" % swap_u}"\
159
+ str = "!##{cpu_u.nan? ? '000' : "%03d" % cpu_u}#{"%03d" % mem_u}#{"%03d" % swap_u}"\
160
160
  "#{convert_bytes(net_u)}#{convert_bytes(net_d)}"\
161
161
  "#{convert_bytes(io_r)}#{convert_bytes(io_w)}#{refresh}~"
162
162
 
@@ -191,31 +191,5 @@ module BlinkTM
191
191
  end
192
192
  end
193
193
 
194
- def iostat
195
- @@root_partition ||= IO.foreach('/proc/mounts').detect {
196
- |x| x.split[1] == ?/
197
- }.to_s.split[0].to_s.split(?/).to_a[-1]
198
-
199
- @@sector_size ||= LS::FS.stat(?/)[:block_size]
200
-
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
- ])
212
-
213
- break
214
- end
215
- }
216
-
217
- io
218
- end
219
-
220
194
  extend(self)
221
195
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlinkTM
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
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.3
4
+ version: 0.2.0
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-28 00:00:00.000000000 Z
11
+ date: 2021-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: linux_stat
@@ -31,11 +31,15 @@ executables:
31
31
  - blink-tm
32
32
  extensions:
33
33
  - ext/baudrate/extconf.rb
34
+ - ext/diskstats/extconf.rb
34
35
  extra_rdoc_files: []
35
36
  files:
36
37
  - exe/blink-tm
37
38
  - ext/baudrate/baudrate.c
38
39
  - ext/baudrate/extconf.rb
40
+ - ext/diskstats/diskstats.c
41
+ - ext/diskstats/extconf.rb
42
+ - ext/diskstats/sectors.h
39
43
  - lib/blink_tm.rb
40
44
  - lib/blink_tm/blink_tm.rb
41
45
  - lib/blink_tm/version.rb