Skip to content

Commit

Permalink
for perf table updating, handle the case where there is no perf.csv. …
Browse files Browse the repository at this point in the history
…run.py might not have created it because of an earlier error, for example.
  • Loading branch information
ericeckstrand committed Jan 29, 2016
1 parent 643a68c commit 37a04ba
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions scripts/mr_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@
import csv
import MySQLdb
import traceback
import os.path

def add_perf_results_to_mr_unit(args):
mr_unit = MySQLdb.connect(host='mr-0x8', user='root', passwd=args[1], db='mr_unit')
mr_unit.autocommit(False)
cursor = mr_unit.cursor()
try:
for row in csv.reader(file(os.path.join(args[2], "perf.csv"))):
row = [r.strip() for r in row]
row[3] = row[3].split("/")[-1]
cursor.execute('INSERT INTO perf(date, build_id, git_hash, git_branch, machine_ip, test_name, start_time, '
'end_time, pass, ncpu, os, job_name) VALUES("{0}", "{1}", "{2}", "{3}", "{4}", "{5}", "{6}"'
', "{7}", "{8}", "{9}", "{10}", "{11}")'.format(*row))
mr_unit.commit()
perf_csv_name = os.path.join(args[2], "perf.csv")
if os.path.isfile(perf_csv_name):
for row in csv.reader(file(perf_csv_name)):
row = [r.strip() for r in row]
row[3] = row[3].split("/")[-1]
cursor.execute('INSERT INTO perf(date, build_id, git_hash, git_branch, machine_ip, test_name, '
'start_time, end_time, pass, ncpu, os, job_name) VALUES("{0}", "{1}", "{2}", "{3}", '
'"{4}", "{5}", "{6}", "{7}", "{8}", "{9}", "{10}", "{11}")'.format(*row))
mr_unit.commit()
else:
print "perf.csv does not exist in {0}, so mr_unit.py has nothing to do here. Maybe run.py failed before " \
"it created this file".format(perf_csv_name)
except:
traceback.print_exc()
mr_unit.rollback()
assert False, "Failed to add performance results to mr_unit!"
print "Failed to add performance results to perf table in mr_unit database!"
raise

if __name__ == '__main__':
add_perf_results_to_mr_unit(sys.argv)

0 comments on commit 37a04ba

Please sign in to comment.