<s> """<STR_LIT>""" <EOL> import shutil <EOL> import os <EOL> import sys <EOL> import argparse <EOL> import tempfile <EOL> import time <EOL> import re <EOL> import random <EOL> import numpy as np <EOL> import pandas as pd <EOL> from pandas import DataFrame , Series <EOL> from suite import REPO_PATH <EOL> VB_DIR = os . path . dirname ( os . path . dirname ( os . path . abspath ( __file__ ) ) ) <EOL> DEFAULT_MIN_DURATION = <NUM_LIT> <EOL> HEAD_COL = "<STR_LIT>" <EOL> BASE_COL = "<STR_LIT>" <EOL> try : <EOL> import git <EOL> except Exception : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> class RevParseAction ( argparse . Action ) : <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> import subprocess <EOL> cmd = '<STR_LIT>' . format ( values ) <EOL> rev_parse = subprocess . check_output ( cmd , shell = True ) <EOL> setattr ( namespace , self . dest , rev_parse . strip ( ) ) <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> type = str , action = RevParseAction ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> type = str , action = RevParseAction ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' '<STR_LIT>' , <EOL> type = str ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' '<STR_LIT>' , <EOL> type = str ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' % DEFAULT_MIN_DURATION , <EOL> type = float , <EOL> default = <NUM_LIT> ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> dest = '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> dest = '<STR_LIT>' , <EOL> default = "<STR_LIT>" , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> dest = '<STR_LIT>' , <EOL> default = <NUM_LIT> , <EOL> type = int , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = "<STR_LIT:N>" , <EOL> dest = '<STR_LIT>' , <EOL> default = <NUM_LIT:3> , <EOL> type = int , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , <EOL> metavar = "<STR_LIT:N>" , <EOL> dest = '<STR_LIT>' , <EOL> default = <NUM_LIT:3> , <EOL> type = int , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = "<STR_LIT:N>" , <EOL> dest = '<STR_LIT>' , <EOL> default = <NUM_LIT:1> , <EOL> type = int , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = "<STR_LIT:a>" , <EOL> dest = '<STR_LIT>' , <EOL> default = <NUM_LIT:1> , <EOL> type = int , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = "<STR_LIT:u>" , <EOL> dest = '<STR_LIT>' , <EOL> default = <NUM_LIT:1> , <EOL> type = int , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> default = False , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> default = None , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> default = False , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> def get_results_df ( db , rev ) : <EOL> """<STR_LIT>""" <EOL> bench = DataFrame ( db . get_benchmarks ( ) ) <EOL> results = DataFrame ( map ( list , db . get_rev_results ( rev ) . values ( ) ) ) <EOL> results . columns = db . _results . c . keys ( ) <EOL> results = results . join ( bench [ '<STR_LIT:name>' ] , on = '<STR_LIT>' ) . set_index ( "<STR_LIT>" ) <EOL> return results <EOL> def prprint ( s ) : <EOL> print ( "<STR_LIT>" % s ) <EOL> def pre_hook ( ) : <EOL> import gc <EOL> gc . disable ( ) <EOL> def post_hook ( ) : <EOL> import gc <EOL> gc . enable ( ) <EOL> def profile_comparative ( benchmarks ) : <EOL> from vbench . api import BenchmarkRunner <EOL> from vbench . db import BenchmarkDB <EOL> from vbench . git import GitRepo <EOL> from suite import BUILD , DB_PATH , PREPARE , dependencies <EOL> TMP_DIR = args . temp_dir or tempfile . mkdtemp ( ) <EOL> try : <EOL> prprint ( "<STR_LIT>" % DB_PATH ) <EOL> db = BenchmarkDB ( DB_PATH ) <EOL> prprint ( "<STR_LIT>" ) <EOL> GitRepo . _parse_commit_log = _parse_wrapper ( args . base_commit ) <EOL> runner = BenchmarkRunner ( <EOL> benchmarks , REPO_PATH , REPO_PATH , BUILD , DB_PATH , <EOL> TMP_DIR , PREPARE , always_clean = True , <EOL> module_dependencies = dependencies ) <EOL> repo = runner . repo <EOL> h_head = args . target_commit or repo . shas [ - <NUM_LIT:1> ] <EOL> h_baseline = args . base_commit <EOL> ( repo . shas , repo . messages , <EOL> repo . timestamps , repo . authors ) = _parse_commit_log ( None , REPO_PATH , <EOL> args . base_commit ) <EOL> prprint ( '<STR_LIT>' % ( h_head , repo . messages . get ( h_head , "<STR_LIT>" ) ) ) <EOL> prprint ( '<STR_LIT>' % ( h_baseline , <EOL> repo . messages . get ( h_baseline , "<STR_LIT>" ) ) ) <EOL> prprint ( "<STR_LIT>" ) <EOL> db . delete_rev_results ( h_baseline ) <EOL> db . delete_rev_results ( h_head ) <EOL> prprint ( "<STR_LIT>" % h_baseline ) <EOL> runner . _run_and_write_results ( h_baseline ) <EOL> prprint ( "<STR_LIT>" % h_head ) <EOL> runner . _run_and_write_results ( h_head ) <EOL> prprint ( '<STR_LIT>' ) <EOL> head_res = get_results_df ( db , h_head ) <EOL> baseline_res = get_results_df ( db , h_baseline ) <EOL> report_comparative ( head_res , baseline_res ) <EOL> finally : <EOL> shutil . rmtree ( TMP_DIR ) <EOL> def prep_pickle_for_total ( df , agg_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> def prep ( df ) : <EOL> agg = getattr ( df , agg_name ) <EOL> df = DataFrame ( agg ( <NUM_LIT:1> ) ) <EOL> cols = list ( df . columns ) <EOL> cols [ <NUM_LIT:0> ] = '<STR_LIT>' <EOL> df . columns = cols <EOL> df [ '<STR_LIT:name>' ] = list ( df . index ) <EOL> return df <EOL> return prep ( df ) <EOL> def prep_totals ( head_res , baseline_res ) : <EOL> """<STR_LIT>""" <EOL> head_res , baseline_res = head_res . align ( baseline_res ) <EOL> ratio = head_res [ '<STR_LIT>' ] / baseline_res [ '<STR_LIT>' ] <EOL> totals = DataFrame ( { HEAD_COL : head_res [ '<STR_LIT>' ] , <EOL> BASE_COL : baseline_res [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : ratio , <EOL> '<STR_LIT:name>' : baseline_res . name } , <EOL> columns = [ HEAD_COL , BASE_COL , "<STR_LIT>" , "<STR_LIT:name>" ] ) <EOL> totals = totals . ix [ totals [ HEAD_COL ] > args . min_duration ] <EOL> totals = totals . dropna ( <EOL> ) . sort ( "<STR_LIT>" ) . set_index ( '<STR_LIT:name>' ) <EOL> return totals <EOL> def report_comparative ( head_res , baseline_res ) : <EOL> try : <EOL> r = git . Repo ( VB_DIR ) <EOL> except : <EOL> import pdb <EOL> pdb . set_trace ( ) <EOL> totals = prep_totals ( head_res , baseline_res ) <EOL> h_head = args . target_commit <EOL> h_baseline = args . base_commit <EOL> h_msg = b_msg = "<STR_LIT>" <EOL> try : <EOL> h_msg = r . commit ( h_head ) . message . strip ( ) <EOL> except git . exc . BadObject : <EOL> pass <EOL> try : <EOL> b_msg = r . commit ( h_baseline ) . message . strip ( ) <EOL> except git . exc . BadObject : <EOL> pass <EOL> print_report ( totals , h_head = h_head , h_msg = h_msg , <EOL> h_baseline = h_baseline , b_msg = b_msg ) <EOL> if args . outdf : <EOL> prprint ( "<STR_LIT>" % args . outdf ) <EOL> totals . save ( args . outdf ) <EOL> def profile_head_single ( benchmark ) : <EOL> import gc <EOL> results = [ ] <EOL> gc . collect ( ) <EOL> try : <EOL> from ctypes import cdll , CDLL <EOL> cdll . LoadLibrary ( "<STR_LIT>" ) <EOL> libc = CDLL ( "<STR_LIT>" ) <EOL> libc . malloc_trim ( <NUM_LIT:0> ) <EOL> except : <EOL> pass <EOL> N = args . hrepeats + args . burnin <EOL> results = [ ] <EOL> try : <EOL> for i in range ( N ) : <EOL> gc . disable ( ) <EOL> d = dict ( ) <EOL> try : <EOL> d = benchmark . run ( ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except Exception as e : <EOL> err = "<STR_LIT>" <EOL> try : <EOL> err = d . get ( "<STR_LIT>" ) <EOL> if err is None : <EOL> err = str ( e ) <EOL> except : <EOL> pass <EOL> print ( "<STR_LIT>" % ( benchmark . name , err ) ) <EOL> results . append ( d . get ( '<STR_LIT>' , np . nan ) ) <EOL> gc . enable ( ) <EOL> gc . collect ( ) <EOL> finally : <EOL> gc . enable ( ) <EOL> if results : <EOL> results = results [ args . burnin : ] <EOL> sys . stdout . write ( '<STR_LIT:.>' ) <EOL> sys . stdout . flush ( ) <EOL> return Series ( results , name = benchmark . name ) <EOL> def profile_head ( benchmarks ) : <EOL> print ( "<STR_LIT>" % ( len ( benchmarks ) , args . hrepeats ) ) <EOL> ss = [ profile_head_single ( b ) for b in benchmarks ] <EOL> print ( "<STR_LIT:\n>" ) <EOL> results = DataFrame ( ss ) <EOL> results . columns = [ "<STR_LIT>" % i for i in range ( args . hrepeats ) ] <EOL> shas , messages , _ , _ = _parse_commit_log ( None , REPO_PATH , base_commit = "<STR_LIT>" ) <EOL> print_report ( results , h_head = shas [ - <NUM_LIT:1> ] , h_msg = messages [ - <NUM_LIT:1> ] ) <EOL> if args . outdf : <EOL> prprint ( "<STR_LIT>" % args . outdf ) <EOL> DataFrame ( results ) . save ( args . outdf ) <EOL> def print_report ( df , h_head = None , h_msg = "<STR_LIT>" , h_baseline = None , b_msg = "<STR_LIT>" ) : <EOL> name_width = <NUM_LIT> <EOL> col_width = <NUM_LIT:10> <EOL> hdr = ( "<STR_LIT>" % name_width ) . format ( "<STR_LIT>" ) <EOL> hdr += ( "<STR_LIT>" % col_width ) * len ( df . columns ) <EOL> hdr += "<STR_LIT:|>" <EOL> hdr = hdr . format ( * df . columns ) <EOL> hdr = "<STR_LIT:->" * len ( hdr ) + "<STR_LIT:\n>" + hdr + "<STR_LIT:\n>" + "<STR_LIT:->" * len ( hdr ) + "<STR_LIT:\n>" <EOL> ftr = hdr <EOL> s = "<STR_LIT:\n>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" % ( args . ncalls or '<STR_LIT>' ) <EOL> s += "<STR_LIT>" % ( args . repeats ) <EOL> s += "<STR_LIT>" <EOL> s += hdr <EOL> for i in range ( len ( df ) ) : <EOL> lfmt = ( "<STR_LIT>" % name_width ) <EOL> lfmt += ( "<STR_LIT>" % ( col_width - <NUM_LIT:2> ) ) * len ( df . columns ) <EOL> lfmt += "<STR_LIT>" <EOL> s += lfmt . format ( df . index [ i ] , * list ( df . iloc [ i ] . values ) ) <EOL> s += ftr + "<STR_LIT:\n>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" % args . seed <EOL> if h_head : <EOL> s += '<STR_LIT>' % ( h_head , h_msg ) <EOL> if h_baseline : <EOL> s += '<STR_LIT>' % ( <EOL> h_baseline , b_msg ) <EOL> stats_footer = "<STR_LIT:\n>" <EOL> if args . stats : <EOL> try : <EOL> pd . options . display . expand_frame_repr = False <EOL> except : <EOL> pass <EOL> stats_footer += str ( df . T . describe ( ) . T ) + "<STR_LIT>" <EOL> s += stats_footer <EOL> logfile = open ( args . log_file , '<STR_LIT:w>' ) <EOL> logfile . write ( s ) <EOL> logfile . close ( ) <EOL> if not args . quiet : <EOL> prprint ( s ) <EOL> if args . stats and args . quiet : <EOL> prprint ( stats_footer ) <EOL> prprint ( "<STR_LIT>" % <EOL> args . log_file ) <EOL> def main ( ) : <EOL> from suite import benchmarks <EOL> if not args . log_file : <EOL> args . log_file = os . path . abspath ( <EOL> os . path . join ( REPO_PATH , '<STR_LIT>' ) ) <EOL> saved_dir = os . path . curdir <EOL> if args . outdf : <EOL> args . outdf = os . path . realpath ( args . outdf ) <EOL> if args . log_file : <EOL> args . log_file = os . path . realpath ( args . log_file ) <EOL> random . seed ( args . seed ) <EOL> np . random . seed ( args . seed ) <EOL> if args . base_pickle and args . target_pickle : <EOL> baseline_res = prep_pickle_for_total ( pd . load ( args . base_pickle ) ) <EOL> target_res = prep_pickle_for_total ( pd . load ( args . target_pickle ) ) <EOL> report_comparative ( target_res , baseline_res ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if args . affinity is not None : <EOL> try : <EOL> import psutil <EOL> if hasattr ( psutil . Process , '<STR_LIT>' ) : <EOL> psutil . Process ( os . getpid ( ) ) . set_cpu_affinity ( [ args . affinity ] ) <EOL> print ( "<STR_LIT>" % args . affinity ) <EOL> except ImportError : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> print ( "<STR_LIT:\n>" ) <EOL> prprint ( "<STR_LIT>" % args . log_file ) <EOL> if args . outdf : <EOL> prprint ( "<STR_LIT>" % args . outdf ) <EOL> print ( "<STR_LIT:\n>" ) <EOL> os . chdir ( os . path . dirname ( os . path . abspath ( __file__ ) ) ) <EOL> benchmarks = [ x for x in benchmarks if re . search ( args . regex , x . name ) ] <EOL> for b in benchmarks : <EOL> b . repeat = args . repeats <EOL> if args . ncalls : <EOL> b . ncalls = args . ncalls <EOL> if benchmarks : <EOL> if args . head : <EOL> profile_head ( benchmarks ) <EOL> else : <EOL> profile_comparative ( benchmarks ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> os . chdir ( saved_dir ) <EOL> def _parse_commit_log ( this , repo_path , base_commit = None ) : <EOL> from vbench . git import _convert_timezones <EOL> from pandas import Series <EOL> from dateutil import parser as dparser <EOL> git_cmd = '<STR_LIT>' % ( repo_path , repo_path ) <EOL> githist = git_cmd + ( '<STR_LIT>' + <EOL> '<STR_LIT>' + <EOL> ( '<STR_LIT>' % base_commit ) + <EOL> '<STR_LIT>' ) <EOL> os . system ( githist ) <EOL> githist = open ( '<STR_LIT>' ) . read ( ) <EOL> os . remove ( '<STR_LIT>' ) <EOL> shas = [ ] <EOL> timestamps = [ ] <EOL> messages = [ ] <EOL> authors = [ ] <EOL> for line in githist . split ( '<STR_LIT:\n>' ) : <EOL> if '<STR_LIT:*>' not in line . split ( "<STR_LIT>" ) [ <NUM_LIT:0> ] : <EOL> continue <EOL> _ , sha , stamp , message , author = line . split ( '<STR_LIT>' , <NUM_LIT:4> ) <EOL> stamp = dparser . parse ( stamp ) <EOL> shas . append ( sha ) <EOL> timestamps . append ( stamp ) <EOL> messages . append ( message ) <EOL> authors . append ( author ) <EOL> timestamps = _convert_timezones ( timestamps ) <EOL> shas = Series ( shas , timestamps ) <EOL> messages = Series ( messages , shas ) <EOL> timestamps = Series ( timestamps , shas ) <EOL> authors = Series ( authors , shas ) <EOL> return shas [ : : - <NUM_LIT:1> ] , messages [ : : - <NUM_LIT:1> ] , timestamps [ : : - <NUM_LIT:1> ] , authors [ : : - <NUM_LIT:1> ] <EOL> def _parse_wrapper ( base_commit ) : <EOL> def inner ( repo_path ) : <EOL> return _parse_commit_log ( repo_path , base_commit ) <EOL> return inner <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> args = parser . parse_args ( ) <EOL> if ( not args . head <EOL> and not ( args . base_commit and args . target_commit ) <EOL> and not ( args . base_pickle and args . target_pickle ) ) : <EOL> parser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif ( ( args . base_pickle or args . target_pickle ) and not <EOL> ( args . base_pickle and args . target_pickle ) ) : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if ( ( args . base_pickle or args . target_pickle ) and not <EOL> ( args . base_commit and args . target_commit ) ) : <EOL> if not args . base_commit : <EOL> print ( "<STR_LIT>" ) <EOL> args . base_commit = args . base_pickle . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] <EOL> if not args . target_commit : <EOL> print ( "<STR_LIT>" ) <EOL> args . target_commit = args . target_pickle . split ( '<STR_LIT:->' ) [ <NUM_LIT:0> ] <EOL> import warnings <EOL> warnings . filterwarnings ( '<STR_LIT:ignore>' , category = FutureWarning ) <EOL> warnings . filterwarnings ( '<STR_LIT:ignore>' , category = DeprecationWarning ) <EOL> if args . base_commit and args . target_commit : <EOL> print ( "<STR_LIT>" ) <EOL> r = git . Repo ( VB_DIR ) <EOL> for c in [ args . base_commit , args . target_commit ] : <EOL> try : <EOL> msg = r . commit ( c ) . message . strip ( ) <EOL> except git . BadObject : <EOL> print ( "<STR_LIT>" % c ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> print ( "<STR_LIT>" % ( c , msg ) ) <EOL> main ( ) </s>
