diff --git a/libs/wlgen/wlgen/workload.py b/libs/wlgen/wlgen/workload.py index 8df27d20e4e478c71b2ff4ad0b61fa2065131b16..0700e69e4762a59c4fa1ad80ee3243cd5a67164c 100644 --- a/libs/wlgen/wlgen/workload.py +++ b/libs/wlgen/wlgen/workload.py @@ -20,6 +20,7 @@ import json import logging import os import re +from time import sleep class Workload(object): @@ -152,7 +153,43 @@ class Workload(object): cgroup=None, background=False, out_dir='./', - as_root=False): + as_root=False, + start_pause_s=None, + end_pause_s=None): + """ + This method starts the execution of the workload. If the user provides + an ftrace object, the method will also collect a trace. + + :param ftrace: FTrace object to collect a trace + :type ftrace: :mod:`trappy.trace.FTrace` + + :param cgroup: specifies the cgroup name in which the workload has to + run + :type cgroup: str + + :param background: run the workload in background. In this case the + method will not return a result. When used with + ftrace it is up to the caller to stop trace + collection + :type background: bool + + :param out_dir: output directory where to store the collected trace (if + any) + :type out_dir: str + + :param as_root: run the workload as root on the target + :type as_root: bool + + :param start_pause_s: time to wait before executing the workload in + seconds. If ftrace is provided, trace collection + is started before waiting. + :type start_pause_s: float + + :param end_pause_s: time to wait after executing the workload in + seconds. If ftrace is provided, trace collection is + stopped after this wait time. + :type end_pause_s: float + """ self.cgroup = cgroup @@ -180,6 +217,12 @@ class Workload(object): if ftrace: ftrace.start() + # Wait `start_pause` seconds before running the workload + if start_pause_s: + logging.info('%14s - Waiting %f seconds before starting workload execution', + 'WlGen', start_pause_s) + sleep(start_pause_s) + # Start task in background if required if background: logging.debug('%14s - WlGen [background]: %s', 'WlGen', self.command) @@ -197,6 +240,12 @@ class Workload(object): # print type(results) self.output['executor'] = results + # Wait `end_pause` seconds before stopping ftrace + if end_pause_s: + logging.info('%14s - Waiting %f seconds before stopping trace collection', + 'WlGen', end_pause_s) + sleep(end_pause_s) + # Stop FTrace (if required) ftrace_dat = None if ftrace: