]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/iostat: use correct types
authorKefu Chai <kchai@redhat.com>
Sun, 17 Jan 2021 01:35:36 +0000 (09:35 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 26 Jan 2021 10:01:59 +0000 (18:01 +0800)
for better readability and for the sake of correctness.

* do not cast denominator to float before diving by it
* use '//' for divding an int
* cast int to str as it will be used as an element in a list of str

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/mgr/iostat/module.py

index 5a765a151cd87c79f864d0cc59126c5ab8b91e3e..220bf928097b1c07dd646e09ad7e9c7693a1011a 100644 (file)
@@ -30,17 +30,17 @@ class Module(MgrModule):
 
         r = self.get('io_rate')
 
-        stamp_delta = float(r['pg_stats_delta']['stamp_delta'])
+        stamp_delta = int(float(r['pg_stats_delta']['stamp_delta']))
         if (stamp_delta > 0):
-            rd = int(r['pg_stats_delta']['stat_sum']['num_read_kb']) / stamp_delta
-            wr = int(r['pg_stats_delta']['stat_sum']['num_write_kb']) / stamp_delta
+            rd = r['pg_stats_delta']['stat_sum']['num_read_kb'] // stamp_delta
+            wr = r['pg_stats_delta']['stat_sum']['num_write_kb'] // stamp_delta
             # The values are in kB, but to_pretty_iec() requires them to be in bytes
-            rd = int(rd) << 10
-            wr = int(wr) << 10
+            rd = rd << 10
+            wr = wr << 10
             total = rd + wr
 
-            rd_ops = int(r['pg_stats_delta']['stat_sum']['num_read']) / stamp_delta
-            wr_ops = int(r['pg_stats_delta']['stat_sum']['num_write']) / stamp_delta
+            rd_ops = r['pg_stats_delta']['stat_sum']['num_read'] // stamp_delta
+            wr_ops = r['pg_stats_delta']['stat_sum']['num_write'] // stamp_delta
             total_ops = rd_ops + wr_ops
 
         if print_header:
@@ -51,9 +51,9 @@ class Module(MgrModule):
             self.to_pretty_iec(rd) + 'B/s',
             self.to_pretty_iec(wr) + 'B/s',
             self.to_pretty_iec(total) + 'B/s',
-            int(rd_ops),
-            int(wr_ops),
-            int(total_ops)
+            str(rd_ops),
+            str(wr_ops),
+            str(total_ops)
             ]
         ret += self.get_pretty_row(elems, width)