Skip to content

Commit

Permalink
Emit multiple reports like pidstat does
Browse files Browse the repository at this point in the history
  • Loading branch information
portante committed May 4, 2022
1 parent 8ac6dcc commit f2f1f48
Showing 1 changed file with 47 additions and 73 deletions.
120 changes: 47 additions & 73 deletions src/pcp/pidstat/pcp-pidstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,27 +795,9 @@ class PidstatOptions(pmapi.pmOptions):
timefmt = "%H:%M:%S"

def checkOptions(self):
if self.show_process_priority and self.show_process_memory_util:
print("Error: -R is incompatible with -r")
return False
elif self.show_process_priority and self.show_process_stack_util:
print("Error: -R is incompatible with -k")
return False
elif self.show_process_priority and self.show_process_cpu_util:
print("Error: -R is incompatible with -u")
return False
elif self.show_process_memory_util and self.show_process_stack_util:
print("Error: -r is incompatible with -k")
return False
elif self.show_process_memory_util and self.show_process_cpu_util:
print("Error: -r is incompatible with -u")
return False
elif self.show_process_cpu_util and self.show_process_stack_util:
print("Error: -u is incompatible with -k")
return False
elif (self.show_process_memory_util or self.show_process_stack_util or
self.show_process_priority or self.show_process_cpu_util) and
self.show_process_state:
if ((self.show_process_memory_util or self.show_process_stack_util or
self.show_process_priority or self.show_process_cpu_util) and
self.show_process_state):
print("Error: Incompatible flags provided")
return False
elif self.flag_error:
Expand All @@ -824,12 +806,12 @@ def checkOptions(self):
elif self.ps_args_flag:
print("Error: Incorrect usage of the -l flag")
return False

if not self.show_process_state and not self.show_process_cpu_util:
# Determine if we are defaulting to -u.
if not any(self.show_process_memory_util, self.show_process_stack_util,
self.show_process_priority):
self.show_process_cpu_util = True
elif self.show_process_state or self.show_process_cpu_util:
return True
# Determine if we are defaulting to -u.
if not any(self.show_process_memory_util, self.show_process_stack_util,
self.show_process_priority):
self.show_process_cpu_util = True
return True

def extraOptions(self, opt, optarg, index):
Expand Down Expand Up @@ -989,60 +971,52 @@ def report(self,manager):

metric_repository = ReportingMetricRepository(group)

if PidstatOptions.show_process_stack_util:
process_stack_util = CpuProcessStackUtil(metric_repository)
process_filter = ProcessFilter(PidstatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
report = CpuProcessStackUtilReporter(process_stack_util, process_filter,
printdecorator.Print, PidstatOptions)

report.print_report(timestamp, header_indentation, value_indentation)

#===========================================================================================================
elif PidstatOptions.show_process_memory_util:
process_memory_util = CpuProcessMemoryUtil(metric_repository)
process_filter = ProcessFilter(PidstatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
report = CpuProcessMemoryUtilReporter(process_memory_util, process_filter,
interval_in_seconds,
printdecorator.Print, PidstatOptions)

report.print_report(timestamp, header_indentation, value_indentation)

#===========================================================================================================
elif PidstatOptions.show_process_priority:
process_priority = CpuProcessPriorities(metric_repository)
process_filter = ProcessFilter(PidstatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
report = CpuProcessPrioritiesReporter(process_priority, process_filter,
printdecorator.Print, PidstatOptions)

report.print_report(timestamp, header_indentation, value_indentation)

#===========================================================================================================
elif PidstatOptions.show_process_state:
if PidstatOptions.show_process_state:
process_state = CpuProcessState(metric_repository)
process_filter = ProcessFilter(PidstatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
report = CpuProcessStateReporter(process_state, process_filter,
interval_in_seconds,
printdecorator.Print, PidstatOptions)

report.print_report(timestamp, header_indentation, value_indentation)

#===========================================================================================================
elif PidstatOptions.show_process_cpu_util:
cpu_usage = CpuUsage(metric_repository)
process_filter = ProcessFilter(PidstatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
report = CpuUsageReporter(cpu_usage, process_filter, interval_in_seconds,
printdecorator.Print, PidstatOptions)
report.print_report(timestamp, ncpu, header_indentation, value_indentation)
else:
if PidstatOptions.show_process_stack_util:
process_stack_util = CpuProcessStackUtil(metric_repository)
process_filter = ProcessFilter(PidstatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
report = CpuProcessStackUtilReporter(process_stack_util, process_filter,
printdecorator.Print, PidstatOptions)
report.print_report(timestamp, header_indentation, value_indentation)

if PidstatOptions.show_process_memory_util:
process_memory_util = CpuProcessMemoryUtil(metric_repository)
process_filter = ProcessFilter(PidstatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
report = CpuProcessMemoryUtilReporter(process_memory_util, process_filter,
interval_in_seconds,
printdecorator.Print, PidstatOptions)
report.print_report(timestamp, header_indentation, value_indentation)

if PidstatOptions.show_process_priority:
process_priority = CpuProcessPriorities(metric_repository)
process_filter = ProcessFilter(PidstatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
report = CpuProcessPrioritiesReporter(process_priority, process_filter,
printdecorator.Print, PidstatOptions)
report.print_report(timestamp, header_indentation, value_indentation)

if PidstatOptions.show_process_cpu_util:
cpu_usage = CpuUsage(metric_repository)
process_filter = ProcessFilter(PidstatOptions)
stdout = StdoutPrinter()
printdecorator = NoneHandlingPrinterDecorator(stdout)
report = CpuUsageReporter(cpu_usage, process_filter, interval_in_seconds,
printdecorator.Print, PidstatOptions)
report.print_report(timestamp, ncpu, header_indentation, value_indentation)


if __name__ == "__main__":
Expand Down

0 comments on commit f2f1f48

Please sign in to comment.