From a6cb92e83b6f09e3b13c38e1bec8f375fddb8a60 Mon Sep 17 00:00:00 2001 From: sitaramshelke Date: Wed, 6 Jul 2016 17:38:56 +0530 Subject: [PATCH 1/3] pcp-pidstat: Override and use -p to match original pidstat Since original pidstat uses -p option to list the processes to be filtered, now pcp-pidstat -p matches with it. --- src/pcp/pidstat/pcp-pidstat.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pcp/pidstat/pcp-pidstat.py b/src/pcp/pidstat/pcp-pidstat.py index 0aa0062b1..007f42daf 100644 --- a/src/pcp/pidstat/pcp-pidstat.py +++ b/src/pcp/pidstat/pcp-pidstat.py @@ -460,7 +460,7 @@ def extraOptions(self, opt,optarg, index): elif opt == 'U': PidstatOptions.show_process_user = True PidstatOptions.filtered_process_user = optarg - elif opt == 'P': + elif opt == 'p': if optarg == "ALL" or optarg == "SELF": PidstatOptions.pid_filter = optarg else: @@ -471,9 +471,16 @@ def extraOptions(self, opt,optarg, index): print ("Invalid Process Id List: use comma separated pids without whitespaces") sys.exit(1) + def override(self, opt): + """ Override standard PCP options to match pidstat(1) """ + if (opt == 'p'): + return 1 + return 0 + def __init__(self): - pmapi.pmOptions.__init__(self,"a:s:t:G:IU::P:RrkV?") + pmapi.pmOptions.__init__(self,"a:s:t:G:IU::p:RrkV?") self.pmSetOptionCallback(self.extraOptions) + self.pmSetOverrideCallback(self.override) self.pmSetLongOptionHeader("General options") self.pmSetLongOptionArchive() self.pmSetLongOptionSamples() @@ -481,7 +488,7 @@ def __init__(self): self.pmSetLongOption("process-name",1,"G","NAME","Select process names using regular expression.") self.pmSetLongOption("",0,"I","","In SMP environment, show CPU usage per processor.") self.pmSetLongOption("user-name",2,"U","[USERNAME]","Show real user name of the tasks and optionally filter by user name.") - self.pmSetLongOption("pid-list",1,"P","PID1,PID2.. ","Show stats for specified pids, Use SELF for current process and ALL for all processes.") + self.pmSetLongOption("pid-list",1,"p","PID1,PID2.. ","Show stats for specified pids, Use SELF for current process and ALL for all processes.") self.pmSetLongOption("",0,"R","","Report realtime priority and scheduling policy information.") self.pmSetLongOption("",0,"r","","Report page faults and memory utilization.") self.pmSetLongOption("",0,"k","","Report stack utilization.") From 5641945a7f834c6231547ee224ad201ec5dde28c Mon Sep 17 00:00:00 2001 From: sitaramshelke Date: Wed, 6 Jul 2016 17:56:28 +0530 Subject: [PATCH 2/3] pcp-pidstat: Use list() when parsing pid_list pcp uses python3 and from python3, map() returns an iterator instead. --- src/pcp/pidstat/pcp-pidstat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pcp/pidstat/pcp-pidstat.py b/src/pcp/pidstat/pcp-pidstat.py index 007f42daf..03df39af5 100644 --- a/src/pcp/pidstat/pcp-pidstat.py +++ b/src/pcp/pidstat/pcp-pidstat.py @@ -466,7 +466,7 @@ def extraOptions(self, opt,optarg, index): else: PidstatOptions.pid_filter = "ALL" try: - PidstatOptions.pid_list = map(lambda x:int(x),optarg.split(',')) + PidstatOptions.pid_list = list(map(lambda x:int(x),optarg.split(','))) except ValueError as e: print ("Invalid Process Id List: use comma separated pids without whitespaces") sys.exit(1) From d76327ea642bf06c51e24fafac4102c2ce5b4caf Mon Sep 17 00:00:00 2001 From: sitaramshelke Date: Wed, 6 Jul 2016 18:12:53 +0530 Subject: [PATCH 3/3] pcp-pidstat: fix floating point precision for total_percent --- src/pcp/pidstat/pcp-pidstat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pcp/pidstat/pcp-pidstat.py b/src/pcp/pidstat/pcp-pidstat.py index 03df39af5..4f3bf494d 100644 --- a/src/pcp/pidstat/pcp-pidstat.py +++ b/src/pcp/pidstat/pcp-pidstat.py @@ -131,7 +131,7 @@ def system_percent(self): def total_percent(self): if self.user_percent() is not None and self.guest_percent() is not None and self.system_percent() is not None: - return self.user_percent()+self.guest_percent()+self.system_percent() + return float("%.2f"%(self.user_percent()+self.guest_percent()+self.system_percent())) else: return None