Blame SOURCES/0015-Move-block_in_bytes-entirely-to-the-presentation-lay.patch

59834e
From 10660e29ea19a0e290e28afe0425f63afd0abd58 Mon Sep 17 00:00:00 2001
fbac9f
From: "Richard W.M. Jones" <rjones@redhat.com>
fbac9f
Date: Mon, 27 Mar 2017 21:22:52 +0100
59834e
Subject: [PATCH 15/23] Move block_in_bytes entirely to the presentation layer.
fbac9f
fbac9f
Simplifies and updates commit dbef8dd3bf00417e75a12c851b053e49c9e1a79e.
fbac9f
---
fbac9f
 src/collect.ml       | 19 +++----------------
fbac9f
 src/collect.mli      |  6 +-----
fbac9f
 src/csv_output.ml    | 14 ++++++++++----
fbac9f
 src/csv_output.mli   |  2 +-
fbac9f
 src/redraw.ml        | 10 +++++++---
fbac9f
 src/stream_output.ml | 14 ++++++++++----
fbac9f
 src/top.ml           |  4 ++--
fbac9f
 7 files changed, 34 insertions(+), 35 deletions(-)
fbac9f
fbac9f
diff --git a/src/collect.ml b/src/collect.ml
fbac9f
index f856067..448ce8c 100644
fbac9f
--- a/src/collect.ml
fbac9f
+++ b/src/collect.ml
fbac9f
@@ -57,12 +57,8 @@ and rd_active = {
fbac9f
   (* The following are since the last slice, or None if cannot be calc'd: *)
fbac9f
   rd_block_rd_reqs : int64 option;      (* Number of block device read rqs. *)
fbac9f
   rd_block_wr_reqs : int64 option;      (* Number of block device write rqs. *)
fbac9f
-  rd_block_rd_bytes : int64 option;   (* Number of bytes block device read *)
fbac9f
-  rd_block_wr_bytes : int64 option;   (* Number of bytes block device write *)
fbac9f
-  (* _info fields includes the number considering --block_in_bytes option *)
fbac9f
-  rd_block_rd_info : int64 option;    (* Block device read info for user *)
fbac9f
-  rd_block_wr_info : int64 option;    (* Block device read info for user *)
fbac9f
-
fbac9f
+  rd_block_rd_bytes : int64 option;     (* Number of bytes block device read *)
fbac9f
+  rd_block_wr_bytes : int64 option;     (* Number of bytes block device write *)
fbac9f
   rd_net_rx_bytes : int64 option;	(* Number of bytes received. *)
fbac9f
   rd_net_tx_bytes : int64 option;	(* Number of bytes transmitted. *)
fbac9f
 }
fbac9f
@@ -114,7 +110,7 @@ let last_pcpu_usages = Hashtbl.create 13
fbac9f
 let clear_pcpu_display_data () =
fbac9f
   Hashtbl.clear last_pcpu_usages
fbac9f
 
fbac9f
-let collect (conn, _, _, _, _, node_info, _, _) block_in_bytes =
fbac9f
+let collect (conn, _, _, _, _, node_info, _, _) =
fbac9f
   (* Number of physical CPUs (some may be disabled). *)
fbac9f
   let nr_pcpus = C.maxcpus_of_node_info node_info in
fbac9f
 
fbac9f
@@ -178,7 +174,6 @@ let collect (conn, _, _, _, _, node_info, _, _) block_in_bytes =
fbac9f
                       rd_mem_bytes = 0L; rd_mem_percent = 0L;
fbac9f
 		      rd_block_rd_reqs = None; rd_block_wr_reqs = None;
fbac9f
                       rd_block_rd_bytes = None; rd_block_wr_bytes = None;
fbac9f
-                      rd_block_rd_info = None; rd_block_wr_info = None;
fbac9f
 		      rd_net_rx_bytes = None; rd_net_tx_bytes = None;
fbac9f
 		    })
fbac9f
 	  with
fbac9f
@@ -256,14 +251,6 @@ let collect (conn, _, _, _, _, node_info, _, _) block_in_bytes =
fbac9f
                     rd_block_rd_bytes = Some read_bytes;
fbac9f
                     rd_block_wr_bytes = Some write_bytes;
fbac9f
          } in
fbac9f
-         let rd = { rd with
fbac9f
-                    rd_block_rd_info =
fbac9f
-                      if block_in_bytes then
fbac9f
-                        rd.rd_block_rd_bytes else rd.rd_block_rd_reqs;
fbac9f
-                    rd_block_wr_info =
fbac9f
-                      if block_in_bytes then
fbac9f
-                        rd.rd_block_wr_bytes else rd.rd_block_wr_reqs;
fbac9f
-         } in
fbac9f
 	 name, Active rd
fbac9f
       (* For all other domains we can't calculate it, so leave as None. *)
fbac9f
       | rd -> rd
fbac9f
diff --git a/src/collect.mli b/src/collect.mli
fbac9f
index 440859b..9ad3dcb 100644
fbac9f
--- a/src/collect.mli
fbac9f
+++ b/src/collect.mli
fbac9f
@@ -48,10 +48,6 @@ and rd_active = {
fbac9f
   rd_block_wr_reqs : int64 option;      (* Number of block device write rqs. *)
fbac9f
   rd_block_rd_bytes : int64 option;     (* Number of bytes block device read *)
fbac9f
   rd_block_wr_bytes : int64 option;     (* Number of bytes block device write *)
fbac9f
-  (* _info fields includes the number considering --block_in_bytes option *)
fbac9f
-  rd_block_rd_info : int64 option;      (* Block device read info for user *)
fbac9f
-  rd_block_wr_info : int64 option;      (* Block device read info for user *)
fbac9f
-
fbac9f
   rd_net_rx_bytes : int64 option;	(* Number of bytes received. *)
fbac9f
   rd_net_tx_bytes : int64 option;	(* Number of bytes transmitted. *)
fbac9f
 }
fbac9f
@@ -75,7 +71,7 @@ type pcpu_stats = {
fbac9f
   rd_pcpu_pcpus_cpu_time : float array
fbac9f
 }
fbac9f
 
fbac9f
-val collect : Types.setup -> bool -> stats
fbac9f
+val collect : Types.setup -> stats
fbac9f
 (** Collect statistics. *)
fbac9f
 
fbac9f
 val collect_pcpu : stats -> pcpu_stats
fbac9f
diff --git a/src/csv_output.ml b/src/csv_output.ml
fbac9f
index 9496ca8..f23d673 100644
fbac9f
--- a/src/csv_output.ml
fbac9f
+++ b/src/csv_output.ml
fbac9f
@@ -56,6 +56,7 @@ let write_csv_header (csv_cpu, csv_mem, csv_block, csv_net) block_in_bytes =
fbac9f
 (* Write summary data to CSV file. *)
fbac9f
 let append_csv (_, _, _, _, _, node_info, hostname, _) (* setup *)
fbac9f
                (csv_cpu, csv_mem, csv_block, csv_net)
fbac9f
+               block_in_bytes
fbac9f
                { rd_doms = doms;
fbac9f
                  rd_printable_time = printable_time;
fbac9f
                  rd_nr_pcpus = nr_pcpus; rd_total_cpu = total_cpu;
fbac9f
@@ -104,10 +105,15 @@ let append_csv (_, _, _, _, _, node_info, hostname, _) (* setup *)
fbac9f
         (if csv_mem then [
fbac9f
             Int64.to_string rd.rd_mem_bytes; Int64.to_string rd.rd_mem_percent
fbac9f
          ] else []) @
fbac9f
-	(if csv_block then [
fbac9f
-	   string_of_int64_option rd.rd_block_rd_info;
fbac9f
-	   string_of_int64_option rd.rd_block_wr_info;
fbac9f
-	 ] else []) @
fbac9f
+	(if csv_block then
fbac9f
+           if block_in_bytes then [
fbac9f
+	     string_of_int64_option rd.rd_block_rd_bytes;
fbac9f
+	     string_of_int64_option rd.rd_block_wr_bytes;
fbac9f
+	   ] else [
fbac9f
+	     string_of_int64_option rd.rd_block_rd_reqs;
fbac9f
+	     string_of_int64_option rd.rd_block_wr_reqs;
fbac9f
+           ]
fbac9f
+         else []) @
fbac9f
 	(if csv_net then [
fbac9f
 	   string_of_int64_option rd.rd_net_rx_bytes;
fbac9f
 	   string_of_int64_option rd.rd_net_tx_bytes;
fbac9f
diff --git a/src/csv_output.mli b/src/csv_output.mli
fbac9f
index d5eab0f..4064be5 100644
fbac9f
--- a/src/csv_output.mli
fbac9f
+++ b/src/csv_output.mli
fbac9f
@@ -24,4 +24,4 @@ val csv_write : (string list -> unit) ref
fbac9f
 
fbac9f
 val write_csv_header : bool * bool * bool * bool -> bool -> unit
fbac9f
 
fbac9f
-val append_csv : Types.setup -> bool * bool * bool * bool -> Collect.stats -> unit
fbac9f
+val append_csv : Types.setup -> bool * bool * bool * bool -> bool -> Collect.stats -> unit
fbac9f
diff --git a/src/redraw.ml b/src/redraw.ml
fbac9f
index 9ce889b..0403158 100644
fbac9f
--- a/src/redraw.ml
fbac9f
+++ b/src/redraw.ml
fbac9f
@@ -155,8 +155,12 @@ let redraw display_mode sort_order
fbac9f
 	| (name, Active rd) :: doms ->
fbac9f
 	   if lineno < lines then (
fbac9f
 	     let state = show_state rd.rd_info.D.state in
fbac9f
-	     let rd_req = Show.int64_option rd.rd_block_rd_info in
fbac9f
-	     let wr_req = Show.int64_option rd.rd_block_wr_info in
fbac9f
+	     let rd_info =
fbac9f
+               if block_in_bytes then Show.int64_option rd.rd_block_rd_bytes
fbac9f
+               else Show.int64_option rd.rd_block_rd_reqs in
fbac9f
+	     let wr_info =
fbac9f
+               if block_in_bytes then Show.int64_option rd.rd_block_wr_bytes
fbac9f
+               else Show.int64_option rd.rd_block_wr_reqs in
fbac9f
 	     let rx_bytes = Show.int64_option rd.rd_net_rx_bytes in
fbac9f
 	     let tx_bytes = Show.int64_option rd.rd_net_tx_bytes in
fbac9f
 	     let percent_cpu = Show.percent rd.rd_percent_cpu in
fbac9f
@@ -166,7 +170,7 @@ let redraw display_mode sort_order
fbac9f
 
fbac9f
 	     let line =
fbac9f
                sprintf "%5d %c %s %s %s %s %s %s %s %s"
fbac9f
-		       rd.rd_domid state rd_req wr_req rx_bytes tx_bytes
fbac9f
+		       rd.rd_domid state rd_info wr_info rx_bytes tx_bytes
fbac9f
 		       percent_cpu percent_mem time name in
fbac9f
 	     let line = pad cols line in
fbac9f
 	     mvaddstr lineno 0 line;
fbac9f
diff --git a/src/stream_output.ml b/src/stream_output.ml
fbac9f
index bf7b114..c3af99b 100644
fbac9f
--- a/src/stream_output.ml
fbac9f
+++ b/src/stream_output.ml
fbac9f
@@ -59,10 +59,16 @@ let append_stream (_, _, _, _, _, node_info, hostname, _) (* setup *)
fbac9f
   let dump_domain = fun name rd
fbac9f
   -> begin
fbac9f
     let state = Screen.show_state rd.rd_info.D.state in
fbac9f
-         let rd_req = if rd.rd_block_rd_info = None then "   0"
fbac9f
-                      else Show.int64_option rd.rd_block_rd_info in
fbac9f
-         let wr_req = if rd.rd_block_wr_info = None then "   0"
fbac9f
-                      else Show.int64_option rd.rd_block_wr_info in
fbac9f
+         let rd_req =
fbac9f
+           if rd.rd_block_rd_reqs = None then "   0"
fbac9f
+           else
fbac9f
+             if block_in_bytes then Show.int64_option rd.rd_block_rd_bytes
fbac9f
+             else Show.int64_option rd.rd_block_rd_reqs in
fbac9f
+         let wr_req =
fbac9f
+           if rd.rd_block_wr_reqs = None then "   0"
fbac9f
+           else
fbac9f
+             if block_in_bytes then Show.int64_option rd.rd_block_wr_bytes
fbac9f
+             else Show.int64_option rd.rd_block_wr_reqs in
fbac9f
     let rx_bytes = if rd.rd_net_rx_bytes = None then "   0"
fbac9f
     else Show.int64_option rd.rd_net_rx_bytes in
fbac9f
     let tx_bytes = if rd.rd_net_tx_bytes = None then "   0"
fbac9f
diff --git a/src/top.ml b/src/top.ml
fbac9f
index 204f3b6..e2a93d6 100644
fbac9f
--- a/src/top.ml
fbac9f
+++ b/src/top.ml
fbac9f
@@ -319,7 +319,7 @@ let rec main_loop ((_, batch_mode, script_mode, csv_enabled, stream_mode, _, _,
fbac9f
 
fbac9f
   while not !quit do
fbac9f
     (* Collect stats. *)
fbac9f
-    let state = collect setup !block_in_bytes in
fbac9f
+    let state = collect setup in
fbac9f
     let pcpu_display =
fbac9f
       if !display_mode = PCPUDisplay then Some (collect_pcpu state)
fbac9f
       else None in
fbac9f
@@ -331,7 +331,7 @@ let rec main_loop ((_, batch_mode, script_mode, csv_enabled, stream_mode, _, _,
fbac9f
 
fbac9f
     (* Update CSV file. *)
fbac9f
     if csv_enabled then
fbac9f
-      Csv_output.append_csv setup csv_flags state;
fbac9f
+      Csv_output.append_csv setup csv_flags !block_in_bytes state;
fbac9f
 
fbac9f
     (* Append to stream output file. *)
fbac9f
     if stream_mode then
fbac9f
-- 
59834e
2.31.1
fbac9f