summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjasplin <qt-info@nokia.com>2011-03-18 16:05:53 +0100
committerjasplin <qt-info@nokia.com>2011-03-18 16:05:53 +0100
commite913546f11a33555b7148e4280145fc48609e7b7 (patch)
tree1cf264bbec4387eedcc032c454153ff369dcbb92
parent6efb3cbdc08f93685dff481635a9e4a9997f8017 (diff)
Output to stdout/stderr and use exit codes in a consistent way.
-rwxr-xr-xscripts/computerankings.py82
-rwxr-xr-xscripts/uploadresults.py82
2 files changed, 85 insertions, 79 deletions
diff --git a/scripts/computerankings.py b/scripts/computerankings.py
index e5165ce..6ff641e 100755
--- a/scripts/computerankings.py
+++ b/scripts/computerankings.py
@@ -10,38 +10,38 @@ from misc import (
# --- BEGIN Global functions ----------------------------------------------
def printUsage():
- print (
- "usage:" + sys.argv[0] +
+ sys.stderr.write(
+ "usage: " + sys.argv[0] +
" --help | [--dbhost H] [--dbport P] --db D --host H --platform P "
- "--branch B --sha1 S [--noprogress NP]")
+ "--branch B --sha1 S [--noprogress NP]\n")
def printVerboseUsage():
printUsage()
- print "\noptions:"
- print(
- " --help: This help.")
- print(
- " --dbhost: The database server host (overriding the default).")
- print(
- " --dbport: The database server port (overriding the default).")
- print(
+ sys.stderr.write("\noptions:\n")
+ sys.stderr.write(
+ " --help: This help.\n")
+ sys.stderr.write(
+ " --dbhost: The database server host (overriding the default).\n")
+ sys.stderr.write(
+ " --dbport: The database server port (overriding the default).\n")
+ sys.stderr.write(
" --db: The database. One of 'bm' or 'bm-dev' (the latter "
- "intended for experimentation).")
- print(
+ "intended for experimentation).\n")
+ sys.stderr.write(
" --host: The physical machine on which the results were "
- "produced (e.g. barbarella or 172.24.90.79).")
- print(
+ "produced (e.g. barbarella or 172.24.90.79).\n")
+ sys.stderr.write(
"--platform: The OS/compiler/architecture combination "
- "(e.g. linux-g++-32).")
- print(
+ "(e.g. linux-g++-32).\n")
+ sys.stderr.write(
" --branch: The product branch (e.g. 'qt 4.6', 'qt 4.7', or "
- "'qt master').")
- print(
+ "'qt master').\n")
+ sys.stderr.write(
" --sha1: The tested revision within the branch. Can be "
"extracted using 'git log -1 --pretty=format:%H' (assuming the "
- "tested revision is the current head revision).")
- print(
- " --noprogress: Specify \'true\' to disable progress indicator.")
+ "tested revision is the current head revision).\n")
+ sys.stderr.write(
+ " --noprogress: Specify \'true\' to disable progress indicator.\n")
# ### 2 B DOCUMENTED!
@@ -216,24 +216,24 @@ def updateRankings(
target_timestamp = getFirstUploadTimestamp(snapshots, sha12_id)
if target_timestamp < 0:
- print (
+ sys.stderr.write(
"error: failed to extract target_timestamp "
- "(error in command-line args?)")
+ "(error in command-line args?)\n")
sys.exit(1)
interval_cond = (
(target_timestamp - last_ranking_timestamp) > ranking_interval)
if not (force_cond or empty_cond or interval_cond):
- print (
+ sys.stdout.write(
"not updating rankings ('force', 'empty', and 'interval' "
- "conditions all failed)")
+ "conditions all failed)\n")
return
- print (
+ sys.stdout.write(
"updating rankings ('force' cond.: " + str(force_cond) +
"; 'empty' cond.: " + str(empty_cond) +
- "; 'interval' cond.: " + str(interval_cond) + ") ...")
+ "; 'interval' cond.: " + str(interval_cond) + ") ...\n")
# For simplicity we hardcode the tolerances for now:
difftol = 1.1
@@ -247,14 +247,15 @@ def updateRankings(
try:
sha12_pos = zip(*snapshots)[0].index(sha12_id)
except ValueError:
- sys.stderr.write("no observations found for SHA-1 ID: " + str(sha12_id))
+ sys.stderr.write(
+ "no observations found for SHA-1 ID: " + str(sha12_id) + "\n")
sys.exit(1)
sha11_pos = max(0, (sha12_pos - 2 * durtolmax) + 1)
snapshots = snapshots[sha11_pos:(sha12_pos + 1)]
if len(snapshots) < 2:
sys.stderr.write(
"no observations found before SHA-1 ID: " + str(sha12_id) +
- " (computing rankings makes no sense)")
+ " (computing rankings makes no sense)\n")
sys.exit(1)
# Get time series statistics for all benchmarks:
@@ -285,7 +286,7 @@ def updateRankings(
# register the ranking positions in the database:
context1_id = getContext(host_id, platform_id, branch_id, snapshots[0][0])
if context1_id == -1:
- print "error: failed to find context for start snapshot"
+ sys.stderr.write("error: failed to find context for start snapshot\n")
sys.exit(1)
nameToIndex = { "QS": 3, "LCSSR": 4, "LCSSI": 5, "LCSS1R": 6, "LCSS1I": 7 }
for name in nameToIndex:
@@ -305,15 +306,15 @@ options, http_get = getOptions()
if "help" in options:
printVerboseUsage()
- sys.exit(0)
+ sys.exit(1)
if (not ("db" in options and "host" in options and "platform" in options and
"branch" in options and "sha1" in options)):
printUsage()
- sys.exit(0)
+ sys.exit(1)
if not isValidSHA1(options["sha1"]):
- print "error: invalid SHA-1:", options["sha1"]
+ sys.stderr.write("error: invalid SHA-1: " + options["sha1"] + "\n")
sys.exit(1)
setDatabase(
@@ -323,24 +324,24 @@ setDatabase(
host_id = textToId("host", options["host"])
if host_id == -1:
- print "error: no such host:", options["host"]
+ sys.stderr.write("error: no such host: " + options["host"] + "\n")
sys.exit(1)
platform_id = textToId("platform", options["platform"])
if platform_id == -1:
- print "error: no such platform:", options["platform"]
+ sys.stderr.write("error: no such platform: " + options["platform"] + "\n")
sys.exit(1)
branch_id = textToId("branch", options["branch"])
if branch_id == -1:
- print "error: no such branch:", options["branch"]
+ sys.stderr.write("error: no such branch:" + options["branch"] + "\n")
sys.exit(1)
sha12_id = textToId("sha1", options["sha1"])
if sha12_id == -1:
- print "error: no such SHA-1:", options["sha1"]
+ sys.stderr.write("error: no such SHA-1:" + options["sha1"] + "\n")
sys.exit(1)
context2_id = getContext(host_id, platform_id, branch_id, sha12_id)
if context2_id == -1:
- print "error: no results found for this context"
+ sys.stderr.write("error: no results found for this context\n")
sys.exit(1)
updateRankings(
@@ -352,6 +353,7 @@ updateRankings(
# Write to database:
commit()
-print "rankings computation done"
+sys.stdout.write("rankings computation done\n")
+sys.exit(0)
# --- END Main program ----------------------------------------------
diff --git a/scripts/uploadresults.py b/scripts/uploadresults.py
index f0d5bb3..3fd38a8 100755
--- a/scripts/uploadresults.py
+++ b/scripts/uploadresults.py
@@ -11,38 +11,40 @@ from misc import (
# --- BEGIN Global functions ----------------------------------------------
def printUsage():
- print (
- "usage:" + sys.argv[0] +
+ sys.stderr.write(
+ "usage: " + sys.argv[0] +
" --help | [--dbhost H --dbport P] --db D --host H --platform P "
- "--branch B --sha1 S --file F")
+ "--branch B --sha1 S --file F\n")
+
def printVerboseUsage():
printUsage()
- print "\noptions:"
- print(
- " --help: This help.")
- print(
- " --dbhost: The database server host (overriding the default).")
- print(
- " --dbport: The database server port (overriding the default).")
- print(
+ sys.stderr.write("\noptions:\n")
+ sys.stderr.write(
+ " --help: This help.\n")
+ sys.stderr.write(
+ " --dbhost: The database server host (overriding the default).\n")
+ sys.stderr.write(
+ " --dbport: The database server port (overriding the default).\n")
+ sys.stderr.write(
" --db: The database. One of 'bm' or 'bm-dev' (the latter "
- "intended for experimentation).")
- print(
+ "intended for experimentation).\n")
+ sys.stderr.write(
" --host: The physical machine on which the results were "
- "produced (e.g. barbarella or 172.24.90.79).")
- print(
+ "produced (e.g. barbarella or 172.24.90.79).\n")
+ sys.stderr.write(
"--platform: The OS/compiler/architecture combination "
- "(e.g. linux-g++-32).")
- print(
+ "(e.g. linux-g++-32).\n")
+ sys.stderr.write(
" --branch: The product branch (e.g. 'qt 4.6', 'qt 4.7', or "
- "'qt master').")
- print(
+ "'qt master').\n")
+ sys.stderr.write(
" --sha1: The tested revision within the branch. Can be "
"extracted using 'git log -1 --pretty=format:%H' (assuming the "
- "tested revision is the current head revision).")
- print(
- " --file: The results file in QTestLib XML output format.")
+ "tested revision is the current head revision).\n")
+ sys.stderr.write(
+ " --file: The results file in QTestLib XML output format.\n")
+
# Returns True iff a low value indicates better performance than a high
# value for the given metric.
@@ -68,6 +70,7 @@ def canonicalMetric(metric):
return "fps"
return metric
+
# Returns True iff at least one of the given incidents indicates failure for
# the given data tag.
def matchesFailedIncident(dataTag, incidents):
@@ -81,6 +84,7 @@ def matchesFailedIncident(dataTag, incidents):
return True
return False
+
# Returns results extracted from a file in QTestLib XML format
# (note: multiple top-level TestCase elements are allowed).
def extractResults(file):
@@ -99,9 +103,9 @@ def extractResults(file):
try:
lowerIsBetter_ = lowerIsBetter(metric)
except:
- print(
+ sys.stdout.write(
"WARNING: skipping result for unsupported metric: >" +
- metric + "<")
+ metric + "<\n")
continue
metric = canonicalMetric(metric)
@@ -166,15 +170,14 @@ def extractResults(file):
return results
+
# ### 2 B DOCUMENTED!
def findOrInsertId(table, value, *args):
- #print "value: >" + value + "<, ",
query_result = execQuery(
"SELECT id FROM " + table + " WHERE value = %s", (value,))
if len(query_result) == 1:
# Found, so return ID:
- #print "returning existing ID: >" + str(query_result[0][0]) + "<"
return query_result[0][0]
# Not found, so insert:
@@ -192,7 +195,6 @@ def findOrInsertId(table, value, *args):
query_result = execQuery(query, values)
assert len(query_result) == 1
- #print "returning new ID: >" + str(query_result[0][0]) + "<"
return query_result[0][0]
@@ -321,16 +323,15 @@ def execComputeRankings(options, new_context):
p = Popen(cmd, stdout = PIPE, stderr = PIPE)
stdout, stderr = p.communicate()
if (p.returncode != 0):
- print "failed to execute command '" + str(cmd) + "':"
- print " return code:", p.returncode
- print " stdout: >%s<" % stdout.strip()
- print " stderr: >%s<" % stderr.strip()
+ sys.stdout.write("failed to execute command '" + str(cmd) + "':\n")
+ sys.stdout.write(" return code: " + str(p.returncode) + "\n")
+ sys.stdout.write(" stdout: >" + stdout.strip() + "<\n")
+ sys.stdout.write(" stderr: >" + stderr.strip() + "<\n")
else:
- print "computerankings.py executed successfully:"
- print " return code:", p.returncode
- print " stdout: >%s<" % stdout.strip()
- print " stderr: >%s<" % stderr.strip()
-
+ sys.stdout.write("computerankings.py executed successfully:\n")
+ sys.stdout.write(" return code: " + str(p.returncode) + "\n")
+ sys.stdout.write(" stdout: >" + stdout.strip() + "<\n")
+ sys.stdout.write(" stderr: >" + stderr.strip() + "<\n")
# --- END Global functions ----------------------------------------------
@@ -341,12 +342,12 @@ options, http_get = getOptions()
if "help" in options:
printVerboseUsage()
- sys.exit(0)
+ sys.exit(1)
if (not ("db" in options and "host" in options and "platform" in options and
"branch" in options and "sha1" in options and "file" in options)):
printUsage()
- sys.exit(0)
+ sys.exit(1)
if not isValidSHA1(options["sha1"]):
sys.stderr.write("error: invalid SHA-1: " + options["sha1"] + "\n")
@@ -362,7 +363,9 @@ sys.stdout.write("UPLOADING RESULTS, OPTIONS: " + str(options) + "\n")
sys.stdout.flush()
-# Reject uploading if this context is already complete:
+# Reject uploading if this context is already complete (since it could
+# modify the input for (and thus invalidate) any rankings computed for
+# this snapshot):
if contextComplete(options):
sys.stderr.write(
"this snapshot is already complete for this time series -> uploading "
@@ -434,5 +437,6 @@ else:
sys.stdout.write("UPLOADING RESULTS DONE\n")
+sys.exit(0)
# --- END Main program ----------------------------------------------