pcp
[Top] [All Lists]

Fix pmrep infinity handling

To: pcp developers <pcp@xxxxxxxxxxx>
Subject: Fix pmrep infinity handling
From: Marko Myllynen <myllynen@xxxxxxxxxx>
Date: Thu, 19 May 2016 14:21:52 +0300
Delivered-to: pcp@xxxxxxxxxxx
Organization: Red Hat
Reply-to: Marko Myllynen <myllynen@xxxxxxxxxx>
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0
Hi,

pmrep(1) does not handle infinite values properly like other clients,
for example:

tst = proc.memory.vmrss / 0

Below is a fix I believe should be pretty optimal.

---
 src/pmrep/pmrep.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/pmrep/pmrep.py b/src/pmrep/pmrep.py
index 5dd0827..b330ca6 100755
--- a/src/pmrep/pmrep.py
+++ b/src/pmrep/pmrep.py
@@ -56,6 +56,7 @@ import socket
 import struct
 import errno
 import time
+import math
 import copy
 import sys
 import os
@@ -1277,7 +1278,7 @@ class PMReporter(object):
                         #fmt[k] = "{:" + str(l) + "d}"
                         fmt[k] = "{X:" + str(l) + "d}"

-                if type(value) is float:
+                if type(value) is float and not math.isinf(value):
                     c = self.precision
                     s = len(str(int(value)))
                     if s > l:

Thanks,

-- 
Marko Myllynen

<Prev in Thread] Current Thread [Next in Thread>
  • Fix pmrep infinity handling, Marko Myllynen <=