11#!/usr/bin/env python3
22# -*- coding: utf-8 -*-
33#
4- # Copyright (c) 2021-2022 The WfCommons Team.
4+ # Copyright (c) 2021-2023 The WfCommons Team.
55#
66# This program is free software: you can redistribute it and/or modify
77# it under the terms of the GNU General Public License as published by
1414import subprocess
1515import time
1616import json
17- from io import StringIO
17+ import signal
18+ import sys
1819import pandas as pd
1920
21+ from io import StringIO
22+
2023from filelock import FileLock
2124from typing import List , Optional
2225
@@ -147,6 +150,7 @@ def get_parser() -> argparse.ArgumentParser:
147150 help = "Path to cores file." )
148151 parser .add_argument ("--cpu-work" , default = None , help = "Amount of CPU work." )
149152 parser .add_argument ("--gpu-work" , default = None , help = "Amount of GPU work." )
153+ parser .add_argument ("--time" , default = None , help = "Time limit (in seconds) to complete the task (overrides CPU and GPU works)" )
150154 parser .add_argument ("--mem" , default = None , help = "Max amount (in MB) of memory consumption." )
151155 parser .add_argument ("--out" , help = "output files name." )
152156 return parser
@@ -193,7 +197,7 @@ def main():
193197 else :
194198 device = available_gpus [0 ]
195199 print (f"Running on GPU { device } " )
196- gpu_benchmark (args .gpu_work , device )
200+ gpu_benchmark (args .gpu_work , device , time = args . time )
197201
198202 if args .cpu_work :
199203 print ("[WfBench] Starting CPU and Memory Benchmarks..." )
@@ -202,11 +206,18 @@ def main():
202206
203207 cpu_procs = cpu_mem_benchmark (cpu_threads = int (10 * args .percent_cpu ),
204208 mem_threads = int (10 - 10 * args .percent_cpu ),
205- cpu_work = int (args .cpu_work ),
209+ cpu_work = sys . maxsize if args . time else int (args .cpu_work ),
206210 core = core ,
207211 total_mem = args .mem )
208- for proc in cpu_procs :
209- proc .wait ()
212+
213+ if args .time :
214+ time .sleep (int (args .time ))
215+ for proc in cpu_procs :
216+ os .killpg (os .getpgid (proc .pid ), signal .SIGTERM )
217+ else :
218+ for proc in cpu_procs :
219+ proc .wait ()
220+
210221 mem_kill = subprocess .Popen (["killall" , "stress-ng" ])
211222 mem_kill .wait ()
212223 print ("[WfBench] Completed CPU and Memory Benchmarks!\n " )
0 commit comments