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 ensures cleanup() is eventually invoked.

Attributes

REQUIRED_TOOLS

The tools required to execute the workload. See lisa.target.Target.install_tools().

Properties

logger inherited

Convenience short-hand for self.get_logger().

Methods

__del__()

__enter__()

__exit__()

Cleanup the artifacts of the workload on the target.

__init_subclass__()

Automatically decorate _run() so that it returns a context manager.

cleanup()

Remove all the artifacts installed on the target with deploy().

deploy()

Deploy the workload on the target.

run()

Run the workload and returns the post-processed output.

run_background()

Run the command asynchronously and give control back to the caller.

wipe_run_dir()

Wipe all content from the run_dir target directory and all its empty parents.

factory() inherited

Decorator to use on alternative constructors, i.e. classmethods that return instances of the class.

get_logger() inherited

Provides a logging.Logger named after cls.

log_locals() inherited

Debugging 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().

property Workload.output[source]#

Deprecated since version 2.0.

output() is deprecated and will be removed in version 4.0: Processed output is returned by run() or by the “.output” attribute of the value returned by the run_background() context manager

Methods#

Workload.__del__()[source]#
Workload.__enter__()[source]#
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:

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 in self.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 after cls.

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.