Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/rmit.py

    r83b22b53 r6f27b67  
    1616import random
    1717import re
    18 import socket
    1918import subprocess
    2019import sys
     
    9695        return nopts
    9796
    98 # returns the first option with key 'opt'
    99 def search_option(action, opt):
    100         i = 0
    101         while i < len(action):
    102                 if action[i] == opt:
    103                         i += 1
    104                         if i != len(action):
    105                                 return action[i]
    106                 i += 1
    107 
    108         return None
    109 
    11097def actions_eta(actions):
    11198        time = 0
    11299        for a in actions:
    113                 o = search_option(a, '-d')
    114                 if o :
    115                         time += int(o)
     100                i = 0
     101                while i < len(a):
     102                        if a[i] == '-d':
     103                                i += 1
     104                                if i != len(a):
     105                                        time += int(a[i])
     106                        i += 1
    116107        return time
    117 
    118 taskset_maps = None
    119 
    120 def init_taskset_maps():
    121         global taskset_maps
    122         known_hosts = {
    123                 "jax": {
    124                         range(  1,  24) : "48-71",
    125                         range( 25,  48) : "48-71,144-167",
    126                         range( 49,  96) : "48-95,144-191",
    127                         range( 97, 144) : "24-95,120-191",
    128                         range(145, 192) : "0-95,96-191",
    129                 },
    130         }
    131 
    132         if (host := socket.gethostname()) in known_hosts:
    133                 taskset_maps = known_hosts[host]
    134                 return True
    135 
    136         print("Warning unknown host '{}', disable taskset usage".format(host), file=sys.stderr)
    137         return False
    138 
    139 
    140 def settaskset_one(action):
    141         o = search_option(action, '-p')
    142         if not o:
    143                 return action
    144         try:
    145                 oi = int(o)
    146         except ValueError:
    147                 return action
    148 
    149         m = "Not found"
    150         for key in taskset_maps:
    151                 if oi in key:
    152                         return ['taskset', '-c', taskset_maps[key], *action]
    153 
    154         print("Warning no mapping for {} cores".format(oi), file=sys.stderr)
    155         return action
    156 
    157 def settaskset(actions):
    158         return [settaskset_one(a) for a in actions]
    159108
    160109if __name__ == "__main__":
     
    166115        parser.add_argument('--file', nargs='?', type=argparse.FileType('w'), default=sys.stdout)
    167116        parser.add_argument('--trials', help='Number of trials to run per combinaison', type=int, default=3)
    168         parser.add_argument('--notaskset', help='If specified, the trial will not use taskset to match the -p option', action='store_true')
    169117        parser.add_argument('command', metavar='command', type=str, nargs=1, help='the command prefix to run')
    170118        parser.add_argument('candidates', metavar='candidates', type=str, nargs='*', help='the candidate suffix to run')
     
    222170
    223171        # ================================================================================
    224         # Fixup the different commands
    225 
    226         # Add tasksets
    227         withtaskset = False
    228         if not options.notaskset and init_taskset_maps():
    229                 withtaskset = True
    230                 actions = settaskset(actions)
    231 
    232         # ================================================================================
    233         # Now that we know what to run, print it.
    234         # find expected time
    235         time = actions_eta(actions)
    236         print("Running {} trials{}".format(len(actions), "" if time == 0 else " (expecting to take {})".format(str(datetime.timedelta(seconds=int(time)))) ))
    237 
    238         # dry run if options ask for it
     172        # Figure out all the combinations to run
    239173        if options.list:
    240174                for a in actions:
     
    246180        # Prepare to run
    247181
     182        # find expected time
     183        time = actions_eta(actions)
     184        print("Running {} trials{}".format(len(actions), "" if time == 0 else " (expecting to take {})".format(str(datetime.timedelta(seconds=int(time)))) ))
     185
    248186        random.shuffle(actions)
    249187
     
    253191        first = True
    254192        for i, a in enumerate(actions):
    255                 sa = " ".join(a[3:] if withtaskset else a)
     193                sa = " ".join(a)
    256194                if first:
    257195                        first = False
     
    270208                                match = re.search("^(.*):(.*)$", s)
    271209                                if match:
    272                                         try:
    273                                                 fields[match.group(1).strip()] = float(match.group(2).strip().replace(',',''))
    274                                         except:
    275                                                 pass
    276 
    277                 options.file.write(json.dumps([a[3 if withtaskset else 0][2:], sa, fields]))
     210                                        fields[match.group(1).strip()] = float(match.group(2).strip().replace(',',''))
     211
     212                options.file.write(json.dumps([a[0][2:], sa, fields]))
    278213                options.file.flush()
    279214
Note: See TracChangeset for help on using the changeset viewer.