def _parse(cls, filename, startfun="mainQ", traceindicator="//%%%traces:"): """ Return inpdecls = {'x':'int', 'y':'double', ..} invdecls = {'lineno' : {'x':'int'; 'y':'double'}} """ def mkVarsDict(s): #%%%indicator double x , double y .. -> {x: int, y: double} #where x and y are SAGE's symbolic variables contents = (x.split() for x in s.split(',')) try: return OrderedDict((k.strip(), t.strip()) for t, k in contents) except ValueError: return None inpdecls, invdecls = OrderedDict(), OrderedDict() for i, l in enumerate(CM.iread(filename)): i = i + 1 l = l.strip() if not l: continue if startfun in l and l.endswith( ' {'): #void startfun(int x, double y) { l = l.split('(')[1].split(')')[0] #int x, double y inpdecls = mkVarsDict(l) elif l.startswith(traceindicator): invdecls[i] = mkVarsDict(Miscs.stripTo(l, ':')) assert invdecls assert (inpdecls is None or (isinstance(inpdecls, OrderedDict) and inpdecls)), inpdecls return inpdecls, invdecls
def mkProgStmts(cls, filename, locs_d, mk_f): stmts = [] for i, l in enumerate(CM.iread(filename)): i = i + 1 l = l.strip() if not l: continue stmts.append(l) lineno = i if lineno in locs_d and locs_d[lineno]: stmts_ = mk_f(locs_d[lineno], lineno) stmts.extend(stmts_) return stmts
def doit(logfile): lines = [l for l in CM.iread(logfile) if "Info:***" in l] rs = OrderedDict() for l in lines: name, nlocs, ninvs, ninps, ntime, nrand = l.split(',') name = name.split()[1].strip() nlocs = float(nlocs.split()[0].strip()) ninvs = float(ninvs.split()[1].strip()) ninps = float(ninps.split()[1].strip()) ntime = float(ntime.split()[1].strip()) print name, nlocs, ninvs, ninps, ntime if name not in rs: rs[name] = {'nlocs': [], 'ninvs': [], 'ninps': [], 'ntime': []} rs[name]['nlocs'].append(nlocs) rs[name]['ninvs'].append(ninvs) rs[name]['ninps'].append(ninps) rs[name]['ntime'].append(ntime) nruns = max(len(rs[name]['nlocs']) for name in rs) stats = {} for name in rs: stats[name] = {} for key in rs[name]: contents = rs[name][key] if len(contents) < nruns: maxv = max(contents) maxv = maxv * 100 contents.extend([maxv] * (nruns - len(contents))) medianc = median(contents) meanc = mean(contents) lenc = len(contents) stats[name][key] = (medianc, meanc, lenc) print('{} {} median {} mean {} len {}'.format( name, key, medianc, meanc, lenc)) for name in sorted(stats): invsd = stats[name]["ninvs"] timesd = stats[name]["ntime"] print name, invsd[0], timesd[0] return stats
def mkProgStmts(cls, filename, invdecls, lineno, mk_f): assert lineno > 0 stmts = [] for i, l in enumerate(CM.iread(filename)): i = i + 1 l = l.strip() if not l: continue stmts.append(l) if i == lineno: assert invdecls stmts_ = mk_f(invdecls, lineno) stmts.extend(stmts_) return stmts