lisa.wlgen.workload.Workload#
- class lisa.wlgen.workload.Workload(*args, **kwargs)[source]#
Bases:
PartialInit
,Loggable
Handle the execution of a command on a target, with custom output processing.
- Parameters:
target (Target) – The Target on which to execute this workload
name (str or None) – Name of the workload. Useful for naming related artefacts.
res_dir (str or None) – Host directory into which artifacts will be stored
run_dir (str or None) – Target directory into which artifacts will be created.
cpus (list(int) or None) – CPUs on which to restrict the workload execution (taskset)
cgroup (str or None) – cgroup in which to run the workload
as_root (bool) – Whether to run the workload as root or not
timeout (int) – Timeout in seconds for the workload execution.
Note
A
Workload
instance can be used as a context manager, which ensurescleanup()
is eventually invoked.Attributes
The tools required to execute the workload. See
lisa.target.Target.install_tools()
.Properties
logger
inheritedConvenience short-hand for
self.get_logger()
.Methods
Cleanup the artifacts of the workload on the target.
Automatically decorate
_run()
so that it returns a context manager.Remove all the artifacts installed on the target with
deploy()
.Deploy the workload on the target.
Run the workload and returns the post-processed output.
Run the command asynchronously and give control back to the caller.
Wipe all content from the
run_dir
target directory and all its empty parents.factory()
inheritedDecorator to use on alternative constructors, i.e. classmethods that return instances of the class.
get_logger()
inheritedProvides a
logging.Logger
named aftercls
.log_locals()
inheritedDebugging aid: log the local variables of the calling function.
Attributes#
- Workload.REQUIRED_TOOLS = []#
The tools required to execute the workload. See
lisa.target.Target.install_tools()
.
Properties#
- property Workload.logger#
Inherited property, see
lisa.utils.Loggable.logger
Convenience short-hand for
self.get_logger()
.
Methods#
- Workload.__exit__(exc_type, exc_val, exc_tb)[source]#
Cleanup the artifacts of the workload on the target.
- classmethod Workload.__init_subclass__(*args, **kwargs)#
Inherited method, see
lisa.wlgen.workload.Workload.__init_subclass__()
Automatically decorate
_run()
so that it returns a context manager.
- Workload.cleanup()[source]#
Remove all the artifacts installed on the target with
deploy()
.If not called manually, it will be called in
__exit__()
or__del__
if the workload is used as a context manager.Note
This method can be called any number of times, but will only have an effect the first time and if the target was deployed.
Note
This method should not be overridden, see
_setup()
.
- Workload.deploy()[source]#
Deploy the workload on the target.
If not called manually, it will be called:
If the workload is used as a context manager, in
__enter__
.If not, in
run()
orrun_background()
.
Calling it manually ahead of time makes can allow less garbage while tracing during the execution of the workload.
Note
This method can be called any number of times, but will only have an effect the first time.
Note
This method should not be overridden, see
_setup()
.
- Workload.run(cpus=None, cgroup=None, as_root=False, timeout=None)[source]#
Run the workload and returns the post-processed output.
Calls
deploy()
if it has not already been done. stdout and stderr will be saved into files inself.res_dir
Note
Subclasses should implement
_run()
.
- Workload.run_background()[source]#
Run the command asynchronously and give control back to the caller.
Returns a transparent wrapper for
devlib.connection.BackgroundCommand
.Example:
wload = Workload(...) with wload.run_background() as bg: # do something. "bg" can be monitored, except for stdout/stderr # which are captured for later post-processing by the class. ... time.sleep(42) # Post-processed output, which would be equal to: # print(wload.run()) print(bg.output)
Note
Subclasses should implement
_run()
.
- Workload.wipe_run_dir()[source]#
Wipe all content from the
run_dir
target directory and all its empty parents.Note
This function should only be called directly in interactive sessions. For other purposes, use
Workload
instances as a context manager.
- classmethod Workload.factory(f)#
Inherited method, see
lisa.utils.PartialInit.factory()
Decorator to use on alternative constructors, i.e. classmethods that return instances of the class.
- classmethod Workload.get_logger(suffix=None)#
Inherited method, see
lisa.utils.Loggable.get_logger()
Provides a
logging.Logger
named aftercls
.
- classmethod Workload.log_locals(var_names=None, level='debug')#
Inherited method, see
lisa.utils.Loggable.log_locals()
Debugging aid: log the local variables of the calling function.