Anton Shestakov <engored@ya.ru>, Fri, 08 May 2015 15:18:12 +0800
bench: add grepall and grepallf
viewer.py
Permissions: -rwxr-xr-x
from tornado.ioloop import IOLoop from tornado.options import define, options from tornado.web import Application, RequestHandler, URLSpec from settings import DBPATH, HG, TEMPLATES, TESTHGREPO define('listen', metavar='IP', default='127.0.0.1') define('port', metavar='PORT', default=8065, type=int) define('xheaders', metavar='True|False', default=False, type=bool) define('debug', metavar='True|False', default=False, type=bool) output = subprocess.check_output([HG, 'log', '-R', TESTHGREPO, '-T', 'json', '-r', revset]) return json.loads(output) class BaseHandler(RequestHandler): self.conn = sqlite3.connect(DBPATH) super(BaseHandler, self).prepare() class IndexHandler(BaseHandler): self.redirect('results.html') class ResultsHandler(BaseHandler): rev = self.get_argument('rev', 'tip') return getinfo('first({}:0, {})'.format(rev, revcount)) def getresults(self, changesets): 'SELECT MIN(time), MAX(time) FROM results WHERE mark = ? AND cache = ?', (mark, False)).fetchone() 'SELECT MIN(time), MAX(time) FROM results WHERE mark = ? AND cache = ?', resultsq = self.conn.execute( 'SELECT mark, time, cache FROM results WHERE node = ?', for mark, time, cache in resultsq: results.setdefault(node, {}).setdefault(mark, [None, None, None, None]) color = green_to_red(limits[mark][0:2], time) if time is not None else None results[node][mark][0:2] = [time, color] color = green_to_red(limits[mark][2:4], time) if time is not None else None results[node][mark][2:4] = [time, color] self.set_header('Content-Type', 'text/plain; charset=UTF-8') changesets = self.getchangesets() results = self.getresults(changesets) self.write('\t{0} (without cache)\t{0} (with cache)'.format(mark)) self.write('{rev}\t{node}'.format(**cset)) marks = results.get(cset['node'], {}).get(mark, ('', '', '')) self.write('\t{0}\t{2}'.format(*marks)) self.set_header('Content-Type', 'text/plain; charset=UTF-8') rev = self.get_argument('rev', 'tip') regex = re.compile(r'^[-\\|/+ ]+([0-9a-f]{40})$') template = '{rev}:{node|short} {tags} {date|isodate} {author|user} {desc|firstline|strip}\n {node}\n\n' revset = 'first({}:0, {})'.format(rev, revcount) cmd = [HG, 'log', '-R', TESTHGREPO, '-G', '-T', template, '-r', revset] graph = subprocess.Popen(cmd, stdout=subprocess.PIPE) while graph.poll() is None: line = graph.stdout.readline() matches = regex.findall(line) rows = self.conn.execute( 'SELECT mark, time, cache FROM results WHERE node = ?', for mark, time, cache in rows: matchtimes.setdefault(mark, [None, None]) matchtimes[mark][1 if cache else 0] = time msg.append('{mark}: {0:.2f}s/{1:.2f}s'.format(*matchtimes[mark], mark=mark)) line = line.replace(match, ' '.join(msg)) changesets = self.getchangesets() results = self.getresults(changesets) self.render('results.html', changesets=changesets, marks=MARKS, results=results) def green_to_red((low, high), value): hue = (value - low) / (high - low) if high != low else 0.5 r, g, b = colorsys.hsv_to_rgb((1 - hue) * 0.3, 1, 1) return (int(r * 255), int(g * 255), int(b * 255)) class Viewer(Application): URLSpec(r'/', IndexHandler), URLSpec(r'/results\.(html|tsv|asc)', ResultsHandler), super(Viewer, self).__init__(handlers, **settings) def listen(self, port, address='', **kwargs): logging.info('{} is serving on {}:{}'.format(self.__class__.__name__, address, port)) super(Viewer, self).listen(port, address, **kwargs) options.parse_command_line() application.listen(options.port, address=options.listen, xheaders=options.xheaders) IOLoop.instance().start() if __name__ == '__main__':