Skip to content

Commit 0aecf88

Browse files
rjogradycopybara-github
authored andcommitted
Lint fixes for parallel_bench- adding docstrings and avoid the empty list default argument.
Reformat the flags help text for consistency, remove trailing whitespace. PiperOrigin-RevId: 669022062 Change-Id: Id2eeaaea411f3acb4b02478e5be9ff6fb5dad8b6
1 parent 7e53385 commit 0aecf88

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

fleetbench/parallel/parallel_bench.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,26 @@
5252
"benchmark_filter",
5353
[],
5454
"""Specifies subset of benchmarks to run.
55-
5655
Filtering options:
5756
- Empty list: Selects all default benchmarks.
58-
- Keyword list: Selects benchmarks from the default list matching any \n
59-
provided keyword, one keyword per filter \n
60-
(e.g., "--benchmark_filter=Cold --benchmark_filter=Hot").""",
57+
- Keyword list: Selects benchmarks from the default list matching any
58+
provided keyword, one keyword per filter
59+
(e.g., "--benchmark_filter=Cold --benchmark_filter=Hot")
60+
""",
6161
)
6262

6363

6464
_WORKLOAD_FILTER = flags.DEFINE_multi_string(
6565
"workload_filter",
6666
[],
67-
"""Selects benchmarks associated with specified workloads. This will \n
67+
"""Selects benchmarks associated with specified workloads. This will
6868
overwrite the `--benchmark_filter` flag.
69-
7069
Filtering options:
71-
- Workload name + keyword(s): Selects benchmarks associated with the \n
72-
specified workload, further filtered by keywords
73-
(e.g., "--workload_filter=libc,Memcpy,Memcmp").
74-
- Workload name + "all": Selects all benchmarks associated with the \n
75-
specified workload
76-
(e.g., "--workload_filter=proto,all")
70+
- Workload name + keyword(s): Selects benchmarks associated with the
71+
specified workload, further filtered by keywords
72+
(e.g., "--workload_filter=libc,Memcpy,Memcmp").
73+
- Workload name + "all": Selects all benchmarks associated with the
74+
specified workload (e.g., "--workload_filter=proto,all")
7775
""",
7876
)
7977

@@ -109,9 +107,9 @@
109107
_NUM_CPUS = flags.DEFINE_integer(
110108
"num_cpus",
111109
len(cpu.Available()),
112-
"Number of CPUs to use. Note that 1 CPU will be reserved for scheduling."
113-
" The lowest available core will be used for the control thread, and the"
114-
" remaining up to num_cpus - 1 will be used for the workers.",
110+
"""Number of CPUs to use. Note that 1 CPU will be reserved for scheduling.
111+
The lowest available core will be used for the control thread, and the
112+
remaining up to num_cpus - 1 will be used for the workers.""",
115113
lower_bound=2,
116114
upper_bound=len(cpu.Available()),
117115
)

fleetbench/parallel/parallel_bench_lib.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ def _GetDefaultBenchmarks(
6262
- Empty list: Returns all default benchmarks.
6363
- Keyword list: Returns benchmarks from the default list matching the provided
6464
keyword (e.g., "Cold Hot").
65+
66+
Args:
67+
benchmark_target: Path to the benchmark binary.
68+
benchmark_filters: List of filters to apply to the benchmarks to run.
69+
70+
Returns:
71+
A map of benchmark names to Benchmark objects.
6572
"""
6673
benchmarks = {}
6774
sub_benchmarks = bm.GetSubBenchmarks(benchmark_target)
@@ -89,6 +96,12 @@ def _GetWorkloadBenchmarks(
8996
"libc,Memcpy,Memcmp").
9097
- Workload name + "all": Returns all benchmarks associated with the
9198
specified workload (e.g., "proto,all").
99+
Args:
100+
benchmark_target: Path to the benchmark binary.
101+
workload_filters: List of filters to apply to the benchmarks to run.
102+
103+
Returns:
104+
A map of benchmark names to Benchmark objects.
92105
"""
93106
benchmarks = {}
94107

@@ -177,7 +190,8 @@ def __init__(
177190
raise ValueError("Must specify at least 2 CPUs.")
178191

179192
# Reserve a CPU for the controller loop.
180-
self.controller_cpu, *self.cpus = cpus
193+
self.controller_cpu = cpus[0]
194+
self.cpus = cpus[1:]
181195
self.cpu_affinity = cpu_affinity
182196
self.benchmarks: dict[str, bm.Benchmark] = {}
183197
self.target_utilization = utilization * 100
@@ -191,8 +205,8 @@ def __init__(
191205
def _PreRun(
192206
self,
193207
benchmark_target: str,
194-
benchmark_filters: list[str],
195-
workload_filters: list[str],
208+
benchmark_filters: list[str] | None,
209+
workload_filters: list[str] | None,
196210
benchmark_perf_counters: str,
197211
benchmark_repetitions: int,
198212
benchmark_min_time: str,
@@ -332,6 +346,7 @@ def _RunSchedulingLoop(self) -> None:
332346
self.results.append(r)
333347

334348
def GenerateBenchmarkReport(self) -> None:
349+
"""Print some aggregated results of the benchmark runs."""
335350
utilization = pd.DataFrame(
336351
self.utilization_samples, columns=["timestamp", "utilization"]
337352
)
@@ -399,8 +414,8 @@ def GeneratePerfCounterReport(self, counters: list[str]) -> None:
399414
def Run(
400415
self,
401416
benchmark_target: str,
402-
benchmark_filter: list[str] = [],
403-
workload_filter: list[str] = [],
417+
benchmark_filter: list[str] | None = None,
418+
workload_filter: list[str] | None = None,
404419
benchmark_perf_counters: str = "",
405420
benchmark_repetitions: int = 0,
406421
benchmark_min_time: str = "",

0 commit comments

Comments
 (0)