legate.util.benchmark.benchmark_log#

legate.util.benchmark.benchmark_log(
name: str,
columns: list[str],
*,
out: TextIO | None = None,
metadata: dict[str, Any] | None = None,
start_runtime: bool = True,
) BenchmarkLog | BenchmarkLogFromFilename#

Create a context manager for logging tables of data generated for benchmarking legate code.

The context manager will write a table of benchmarking data to a specified output textstream, including with the table a header comment with reproducibility data about how the benchmark was run.

Parameters:
  • name (str) – The name for the benchmark.

  • columns (list[str]) – A list of headers for the columns of data in the table.

  • out (TextIO | None = None) – Optional io stream for benchmark data: e.g. out=sys.stdout to write benchmark data to the screen. If out is not specified, the destination of benchmark data depends on the LEGATE_BENCHMARK_OUT environment variable. By default, this variable is stdout, in which case benchmark data will be written to sys.stdout (see also LEGATE_LIMIT_STDOUT). If instead this is a directory, e.g. LEGATE_BENCHMARK_OUT=${PWD}, then a unique basename will be generated for a set of output csv files (one per rank) in that directory. (The legate command line option --benchmark-to-file is equivalent to setting LEGATE_BENCHMARK_OUT to have the same value as the directory as --logdir.) For example, if name is mybench, then rank P will write its benchmark data to mybench_[unique hex string].P.csv.

  • metadata (dict[str, Any] | None = None) – Optional dictionary of metadata that will be included in the header of the table. If None, legate.util.info.info() will be used to generate the metadata.

  • start_runtime (bool = True) – By default, benchmark_log() uses the legate runtime to populate metadata and, in multi-rank programs, to determine a globally unique id for each benchmark. If start_runtime=False is specified, the legate runtime will not be started if it is not already running: each rank in a multiprocess program will generate a different id, and metadata about the runtime and machine configuration of legate will be missing.

Returns:

A context manager whose primary method is log(), which adds a row of benchmark data to the table.

Return type:

BenchmarkLog | BenchmarkLogFromFilename