Skip to content

Commit

Permalink
Add --cpus to specify max cpus to be used
Browse files Browse the repository at this point in the history
Sometimes the default behaviour of using all CPUs can
be a bit hostile when the dataset is large.
Let's allow to reduce that number with a new parameter --cpus / -m
  • Loading branch information
mbaldessari committed Aug 4, 2021
1 parent e83efba commit 3657d30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/pcp2pdf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion src/pcp2pdf/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3657d30

Please sign in to comment.