diff --git a/src/pcp2pdf/__main__.py b/src/pcp2pdf/__main__.py index d3b037b..6f102e4 100755 --- a/src/pcp2pdf/__main__.py +++ b/src/pcp2pdf/__main__.py @@ -44,6 +44,8 @@ def __init__(self): self.labels = {} self.dpi = None self.histogram = False + # max nr of CPUs to use. None == All available CPUs + self.max_cpus = None self.opts = self.setup() configfiles = [] path = os.path.join(pmapi.pmContext.pmGetConfig('PCP_SYSCONF_DIR'), @@ -101,6 +103,7 @@ def setup(self): opts.pmSetLongOption("dpi", 1, 'd', '', "Sets the DPI used to create the images for the graph. Default is 200") opts.pmSetLongOptionText(t + "unless overridden in the configuration. The lower the value, the less memory the process will need") opts.pmSetLongOptionText(t + "and the less quality the graphs will have.") + opts.pmSetLongOption("cpus", 1, 'm', '', "Maximum nr of CPUs to use when rendering (default: all available CPUs)") opts.pmSetLongOptionStart() opts.pmSetLongOptionFinish() opts.pmSetLongOptionInterval() @@ -135,6 +138,11 @@ def option_callback(self, opt, optarg, index): sys.exit(1) elif opt == "t": self.interval = optarg + elif opt == "m": + if int(optarg) == 0: + self.max_cpus = None + else: + self.max_cpus = int(optarg) elif opt == "e": self.exclude.append(optarg) elif opt == "c": diff --git a/src/pcp2pdf/stats.py b/src/pcp2pdf/stats.py index 02d8716..96b9b78 100644 --- a/src/pcp2pdf/stats.py +++ b/src/pcp2pdf/stats.py @@ -853,7 +853,7 @@ def output(self): progress_total = len(self.all_graphs) # Set this to False to disable multiprocessing if True: - pool = multiprocessing.Pool(None) + pool = multiprocessing.Pool(self.opts.max_cpus) l = zip(itertools.repeat(self), self.all_graphs) metrics_rets = pool.map(graph_wrapper, l) (metrics, rets) = zip(*metrics_rets)