2828from fleetbench .parallel import cpu
2929from fleetbench .parallel import reporter
3030from fleetbench .parallel import run
31+ from fleetbench .parallel import weights
3132from fleetbench .parallel import worker
3233
3334
34- def ParseBenchmarkWeights (
35- benchmark_weights_list : list [str ],
36- ) -> dict [str , float ] | None :
37- """Parses a list of benchmark weights into a dictionary.
38-
39- The string element in the list should be in the format:
40- <benchmark_name|benchmark_filter>:<weight>. Note that the benchmark name or
41- filter should be in ALL CAPS to ensure case-insensitive matching.
42-
43- Args:
44- benchmark_weights_list: A list of strings to parse.
45-
46- Returns:
47- A dictionary of {capitalized string: float} or None if the list is empty.
48- """
49- if not benchmark_weights_list :
50- return None
51-
52- benchmark_weights = {}
53- for weights in benchmark_weights_list :
54- try :
55- key , value_str = weights .split (":" )
56- benchmark_weights [key .upper ()] = float (value_str )
57- except ValueError :
58- logging .warning (
59- "Invalid benchmark string: %s. The format should be"
60- " <benchmark_name|benchmark_filter>:<weight>. Skipping..." ,
61- weights ,
62- )
63-
64- return benchmark_weights
65-
66-
6735def _SetExtraBenchmarkFlags (
6836 benchmark_perf_counters : str ,
6937 benchmark_repetitions : int ,
@@ -119,7 +87,6 @@ def __init__(
11987 self ,
12088 cpus : list [int ],
12189 cpu_affinity : bool ,
122- benchmark_weights : dict [str , float ] | None ,
12390 utilization : float ,
12491 duration : float ,
12592 temp_root : str ,
@@ -133,7 +100,7 @@ def __init__(
133100 self .controller_cpu = cpus [0 ]
134101 self .cpus = cpus [1 :]
135102 self .cpu_affinity = cpu_affinity
136- self .benchmark_weights = benchmark_weights
103+ self .benchmark_weights : dict [ str , float ] = {}
137104 self .benchmarks : dict [str , bm .Benchmark ] = {}
138105 self .target_utilization = utilization * 100
139106 self .duration = duration
@@ -142,27 +109,44 @@ def __init__(
142109 self .workers : dict [int , worker .Worker ] = {}
143110 self .utilization_samples : list [tuple [pd .Timestamp , float ]] = []
144111
145- def _PreRun (
112+ def SetWeights (
146113 self ,
147114 benchmark_target : str ,
148- benchmark_filters : list [str ] | None ,
149- workload_filters : list [str ] | None ,
150- benchmark_perf_counters : str ,
151- benchmark_repetitions : int ,
152- benchmark_min_time : str ,
115+ benchmark_filter : list [str ] | None ,
116+ workload_filter : list [str ] | None ,
117+ custom_benchmark_weights : list [str ] | None ,
153118 ) -> None :
154- """Initial configuration steps ."""
155-
156- logging .info ("Initializing benchmarks and worker threads..." )
119+ """Sets the benchmark weights ."""
120+ logging . info ( "Running with benchmark_filter: %s" , benchmark_filter )
121+ logging .info ("Running with workload_filter: %s" , workload_filter )
157122
158- if workload_filters :
123+ if benchmark_filter and workload_filter :
124+ logging .warning (
125+ "Both benchmark_filter and workload_filter specified. "
126+ "benchmark_filter will be ignored."
127+ )
128+ if workload_filter :
159129 self .benchmarks = bm .GetWorkloadBenchmarks (
160- benchmark_target , workload_filters
130+ benchmark_target , workload_filter
161131 )
162132 else :
163133 self .benchmarks = bm .GetDefaultBenchmarks (
164- benchmark_target , benchmark_filters
134+ benchmark_target , benchmark_filter
165135 )
136+ # Gets the number of workloads and num of benchmark for each workload
137+ self .benchmark_weights = weights .GetBenchmarkWeights (
138+ self .benchmarks , custom_benchmark_weights
139+ )
140+
141+ def _PreRun (
142+ self ,
143+ benchmark_perf_counters : str ,
144+ benchmark_repetitions : int ,
145+ benchmark_min_time : str ,
146+ ) -> None :
147+ """Initial configuration steps."""
148+
149+ logging .info ("Initializing benchmarks and worker threads..." )
166150
167151 benchmark_flags = _SetExtraBenchmarkFlags (
168152 benchmark_perf_counters , benchmark_repetitions , benchmark_min_time
@@ -402,27 +386,13 @@ def PostProcessBenchmarkResults(self, benchmark_perf_counters: str) -> None:
402386
403387 def Run (
404388 self ,
405- benchmark_target : str ,
406- benchmark_filter : list [str ] | None = None ,
407- workload_filter : list [str ] | None = None ,
408389 benchmark_perf_counters : str = "" ,
409390 benchmark_repetitions : int = 0 ,
410391 benchmark_min_time : str = "" ,
411392 ):
412393 """Run benchmarks in parallel."""
413- logging .info ("Running with benchmark_filter: %s" , benchmark_filter )
414- logging .info ("Running with workload_filter: %s" , workload_filter )
415-
416- if benchmark_filter and workload_filter :
417- logging .warning (
418- "Both benchmark_filter and workload_filter specified. "
419- "benchmark_filter will be ignored."
420- )
421394
422395 self ._PreRun (
423- benchmark_target ,
424- benchmark_filter ,
425- workload_filter ,
426396 benchmark_perf_counters ,
427397 benchmark_repetitions ,
428398 benchmark_min_time ,
0 commit comments