~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/pmu-events/models.py

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/perf/pmu-events/models.py (Architecture i386) and /tools/perf/pmu-events/models.py (Architecture m68k)


  1 #!/usr/bin/env python3                              1 #!/usr/bin/env python3
  2 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-      2 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
  3 """List model names from mapfile.csv files."""      3 """List model names from mapfile.csv files."""
  4 import argparse                                     4 import argparse
  5 import csv                                          5 import csv
  6 import os                                           6 import os
  7 import re                                           7 import re
  8 from typing import List                             8 from typing import List
  9                                                     9 
 10 def main() -> None:                                10 def main() -> None:
 11     def dir_path(path: str) -> str:                11     def dir_path(path: str) -> str:
 12         """Validate path is a directory for ar     12         """Validate path is a directory for argparse."""
 13         if os.path.isdir(path):                    13         if os.path.isdir(path):
 14             return path                            14             return path
 15         raise argparse.ArgumentTypeError(f'\'{     15         raise argparse.ArgumentTypeError(f'\'{path}\' is not a valid directory')
 16                                                    16 
 17     def find_archs(start_dir: str, arch: str)      17     def find_archs(start_dir: str, arch: str) -> List[str]:
 18         archs = []                                 18         archs = []
 19         for item in os.scandir(start_dir):         19         for item in os.scandir(start_dir):
 20             if not item.is_dir():                  20             if not item.is_dir():
 21                 continue                           21                 continue
 22             if arch in (item.name, 'all'):         22             if arch in (item.name, 'all'):
 23                 archs.append(item.name)            23                 archs.append(item.name)
 24                                                    24 
 25         if len(archs) < 1:                         25         if len(archs) < 1:
 26             raise IOError(f'Missing architectu     26             raise IOError(f'Missing architecture directory \'{arch}\'')
 27                                                    27 
 28         return archs                               28         return archs
 29                                                    29 
 30     def find_mapfiles(start_dir: str, archs: L     30     def find_mapfiles(start_dir: str, archs: List[str]) -> List[str]:
 31         result = []                                31         result = []
 32         for arch in archs:                         32         for arch in archs:
 33             for item in os.scandir(f'{start_di     33             for item in os.scandir(f'{start_dir}/{arch}'):
 34                 if item.is_dir():                  34                 if item.is_dir():
 35                     continue                       35                     continue
 36                 if item.name == 'mapfile.csv':     36                 if item.name == 'mapfile.csv':
 37                     result.append(f'{start_dir     37                     result.append(f'{start_dir}/{arch}/mapfile.csv')
 38         return result                              38         return result
 39                                                    39 
 40     def find_cpuids(mapfiles: List[str], cpuid     40     def find_cpuids(mapfiles: List[str], cpuids: str) -> List[str]:
 41         result = []                                41         result = []
 42         for mapfile in mapfiles:                   42         for mapfile in mapfiles:
 43             with open(mapfile, encoding='utf-8     43             with open(mapfile, encoding='utf-8') as csvfile:
 44                 first = False                      44                 first = False
 45                 table = csv.reader(csvfile)        45                 table = csv.reader(csvfile)
 46                 for row in table:                  46                 for row in table:
 47                     if not first or len(row) =     47                     if not first or len(row) == 0 or row[0].startswith('#'):
 48                         first = True               48                         first = True
 49                         continue                   49                         continue
 50                     # Python regular expressio     50                     # Python regular expressions don't handle xdigit.
 51                     regex = row[0].replace('[[     51                     regex = row[0].replace('[[:xdigit:]]', '[0-9a-fA-F]')
 52                     for cpuid in cpuids.split(     52                     for cpuid in cpuids.split(','):
 53                         if re.match(regex, cpu     53                         if re.match(regex, cpuid):
 54                             result.append(row[     54                             result.append(row[2])
 55         return result                              55         return result
 56                                                    56 
 57     ap = argparse.ArgumentParser()                 57     ap = argparse.ArgumentParser()
 58     ap.add_argument('arch', help='Architecture     58     ap.add_argument('arch', help='Architecture name like x86')
 59     ap.add_argument('cpuid', default='all', he     59     ap.add_argument('cpuid', default='all', help='List of cpuids to convert to model names')
 60     ap.add_argument(                               60     ap.add_argument(
 61         'starting_dir',                            61         'starting_dir',
 62         type=dir_path,                             62         type=dir_path,
 63         help='Root of tree containing architec     63         help='Root of tree containing architecture directories containing json files'
 64     )                                              64     )
 65     args = ap.parse_args()                         65     args = ap.parse_args()
 66                                                    66 
 67     archs = find_archs(args.starting_dir, args     67     archs = find_archs(args.starting_dir, args.arch)
 68     mapfiles = find_mapfiles(args.starting_dir     68     mapfiles = find_mapfiles(args.starting_dir, archs)
 69     models = find_cpuids(mapfiles, args.cpuid)     69     models = find_cpuids(mapfiles, args.cpuid)
 70     print(','.join(models))                        70     print(','.join(models))
 71                                                    71 
 72 if __name__ == '__main__':                         72 if __name__ == '__main__':
 73     main()                                         73     main()
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php