Move total_to_diff transform from script to function
authorSiraaj Khandkar <siraaj@khandkar.net>
Thu, 16 Aug 2018 16:20:26 +0000 (12:20 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Thu, 16 Aug 2018 16:20:26 +0000 (12:20 -0400)
bin/khatus
bin/khatus_bar
bin/khatus_transform_total_to_diff [deleted file]

index 371b15c..283ef31 100755 (executable)
@@ -209,26 +209,6 @@ main() {
     fork_poller "${opts['--interval_inp_mem']}"        "$perf" "$pipe" "$bin" "$cmd_sens_memory"
 
     stdbuf -o L tail -f "$pipe" \
-    | stdbuf -o L "$bin"/khatus_transform_total_to_diff \
-        -F "$MSG_FS" \
-        -v status='OK' \
-        -v src='khatus_sensor_net_addr_io' \
-        -v key_prefix='bytes_read' \
-    | stdbuf -o L "$bin"/khatus_transform_total_to_diff \
-        -F "$MSG_FS" \
-        -v status='OK' \
-        -v src='khatus_sensor_net_addr_io' \
-        -v key_prefix='bytes_written' \
-    | stdbuf -o L "$bin"/khatus_transform_total_to_diff \
-        -F "$MSG_FS" \
-        -v status='OK' \
-        -v src='khatus_sensor_disk_io' \
-        -v key_prefix='sectors_read' \
-    | stdbuf -o L "$bin"/khatus_transform_total_to_diff \
-        -F "$MSG_FS" \
-        -v status='OK' \
-        -v src='khatus_sensor_disk_io' \
-        -v key_prefix='sectors_written' \
     | stdbuf -o L "$bin"/khatus_bar \
         -F "$MSG_FS" \
         -v opt_debug=""${opts['--debug']}"" \
index fed9b11..e2e505c 100755 (executable)
@@ -4,6 +4,11 @@ BEGIN {
      FS = msg_fs ? msg_fs : "|"
     OFS = msg_fs ? msg_fs : "|"
     Kfs = key_fs ? key_fs : ":"
+
+    _total_to_diff["khatus_sensor_net_addr_io", "bytes_read"     ] = 1
+    _total_to_diff["khatus_sensor_net_addr_io", "bytes_written"  ] = 1
+    _total_to_diff["khatus_sensor_disk_io"    , "sectors_read"   ] = 1
+    _total_to_diff["khatus_sensor_disk_io"    , "sectors_written"] = 1
 }
 
 # -----------------------------------------------------------------------------
@@ -36,7 +41,7 @@ function Data_update(    src, key, val, len_line, len_head, len_val, time) {
     len_val  = len_line - len_head
     val = substr($0, len_head + 1, len_val)
 
-    Data[src, key] = val
+    Data[src, key] = Data_maybe_total_to_diff(src, key, val)
     time = Data_get_time()
     M_time[src, key] = time
 
@@ -73,6 +78,17 @@ function Data_gc(    src_and_key, unused_for) {
     }
 }
 
+function Data_maybe_total_to_diff(src, key, val,    key_parts) {
+    split(key, key_parts, Kfs)
+    if (_total_to_diff[src, key_parts[1]]) {
+        _prev[src, key] = _curr[src, key]
+        _curr[src, key] = val
+        return (_curr[src, key] - _prev[src, key])
+    } else {
+        return val
+    }
+}
+
 # -----------------------------------------------------------------------------
 # Status bar
 # -----------------------------------------------------------------------------
diff --git a/bin/khatus_transform_total_to_diff b/bin/khatus_transform_total_to_diff
deleted file mode 100755 (executable)
index 59894c0..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#! /usr/bin/awk -f
-
-BEGIN {
-     FS = msg_fs ? msg_fs : "|"
-    OFS = msg_fs ? msg_fs : "|"
-    Kfs = key_fs ? key_fs : ":"
-}
-
-# Modify the record we're interested in
-$1 == status && $2 == src && ($3 ~ ("^" key_prefix)) {
-    key = $3
-    val = $4
-    prev[key] = curr[key]
-    curr[key] = val
-    diff[key] = curr[key] - prev[key]
-    print($1, $2, $3, diff[key])
-    next
-}
-
-# Let everything else through untouched
-//
This page took 0.033696 seconds and 4 git commands to generate.