@@ -305,38 +305,45 @@ def is_leaf_dir(path: str) -> bool:
305
305
print_events_table_entries (item , get_topic (item .name ))
306
306
307
307
308
- def print_mapping_table () -> None :
308
+ def print_mapping_table (archs : Sequence [ str ] ) -> None :
309
309
"""Read the mapfile and generate the struct from cpuid string to event table."""
310
- with open (f'{ _args .starting_dir } /{ _args .arch } /mapfile.csv' ) as csvfile :
311
- table = csv .reader (csvfile )
312
- _args .output_file .write (
313
- 'const struct pmu_events_map pmu_events_map[] = {\n ' )
314
- first = True
315
- for row in table :
316
- # Skip the first row or any row beginning with #.
317
- if not first and len (row ) > 0 and not row [0 ].startswith ('#' ):
318
- tblname = file_name_to_table_name ([], row [2 ].replace ('/' , '_' ))
319
- _args .output_file .write ("""{
320
- \t .cpuid = \" %s\" ,
321
- \t .version = \" %s\" ,
322
- \t .type = \" %s\" ,
323
- \t .table = %s
324
- },
325
- """ % (row [0 ].replace ('\\ ' , '\\ \\ ' ), row [1 ], row [3 ], tblname ))
326
- first = False
327
-
328
- _args .output_file .write ("""{
310
+ _args .output_file .write ('const struct pmu_events_map pmu_events_map[] = {\n ' )
311
+ for arch in archs :
312
+ if arch == 'test' :
313
+ _args .output_file .write ("""{
314
+ \t .arch = "testarch",
329
315
\t .cpuid = "testcpu",
330
316
\t .version = "v1",
331
317
\t .type = "core",
332
318
\t .table = pme_test_soc_cpu,
333
319
},
334
- {
320
+ """ )
321
+ else :
322
+ with open (f'{ _args .starting_dir } /{ arch } /mapfile.csv' ) as csvfile :
323
+ table = csv .reader (csvfile )
324
+ first = True
325
+ for row in table :
326
+ # Skip the first row or any row beginning with #.
327
+ if not first and len (row ) > 0 and not row [0 ].startswith ('#' ):
328
+ tblname = file_name_to_table_name ([], row [2 ].replace ('/' , '_' ))
329
+ cpuid = row [0 ].replace ('\\ ' , '\\ \\ ' )
330
+ _args .output_file .write (f"""{{
331
+ \t .arch = "{ arch } ",
332
+ \t .cpuid = "{ cpuid } ",
333
+ \t .version = "{ row [1 ]} ",
334
+ \t .type = "{ row [3 ]} ",
335
+ \t .table = { tblname }
336
+ }},
337
+ """ )
338
+ first = False
339
+
340
+ _args .output_file .write ("""{
341
+ \t .arch = 0,
335
342
\t .cpuid = 0,
336
343
\t .version = 0,
337
344
\t .type = 0,
338
345
\t .table = 0,
339
- },
346
+ }
340
347
};
341
348
""" )
342
349
@@ -387,15 +394,24 @@ def ftw(path: str, parents: Sequence[str],
387
394
_args = ap .parse_args ()
388
395
389
396
_args .output_file .write ("#include \" pmu-events/pmu-events.h\" \n " )
390
- for path in [_args .arch , 'test' ]:
391
- arch_path = f'{ _args .starting_dir } /{ path } '
392
- if not os .path .isdir (arch_path ):
393
- raise IOError (f'Missing architecture directory in \' { arch_path } \' ' )
397
+ archs = []
398
+ for item in os .scandir (_args .starting_dir ):
399
+ if not item .is_dir ():
400
+ continue
401
+ if item .name == _args .arch or _args .arch == 'all' or item .name == 'test' :
402
+ archs .append (item .name )
403
+
404
+ if len (archs ) < 2 :
405
+ raise IOError (f'Missing architecture directory \' { _args .arch } \' ' )
406
+
407
+ archs .sort ()
408
+ for arch in archs :
409
+ arch_path = f'{ _args .starting_dir } /{ arch } '
394
410
preprocess_arch_std_files (arch_path )
395
411
ftw (arch_path , [], process_one_file )
396
412
print_events_table_suffix ()
397
413
398
- print_mapping_table ()
414
+ print_mapping_table (archs )
399
415
print_system_mapping_table ()
400
416
401
417
0 commit comments