Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Functions for adding results to perf dashboard.""" | |
| 7 | |
| 8 import httplib | |
| 9 import json | |
| 10 import urllib | |
| 11 import urllib2 | |
| 12 | |
| 13 SEND_RESULTS_PATH = "/add_point" | |
| 14 RESULTS_LINK_PATH = "/report?masters=%s&bots=%s&tests=%s&rev=%s" | |
| 15 CACHE_FILE = "/tmp/my_log_file" | |
|
Mike Stip (use stip instead)
2013/02/27 09:53:35
in a later version this will be build_dir/results_
| |
| 16 | |
| 17 | |
| 18 def SendResults(logname, lines, master, system, test, url, stdio_url): | |
| 19 if not logname.endswith("-summary.dat"): | |
| 20 return | |
| 21 | |
| 22 new_results_line = _GetResultsJson( | |
| 23 logname, lines, master, system, test, url, stdio_url) | |
| 24 # Write the new request line to the cache, in case of errors. | |
| 25 cache = open(CACHE_FILE, "a+b") | |
| 26 cache.write("\n" + new_results_line) | |
| 27 cache.close() | |
| 28 | |
| 29 # Send all the results from this run and the previous cache to the dashboard. | |
| 30 cache = open(CACHE_FILE, "r") | |
| 31 cache_lines = cache.readlines() | |
| 32 cache.close() | |
| 33 errors = [] | |
| 34 lines_to_retry = [] | |
| 35 fatal_error = False | |
| 36 for index, line in enumerate(cache_lines): | |
| 37 line = line.strip() | |
| 38 if not line: | |
| 39 continue | |
| 40 error = _SendResultsJson(url, line) | |
| 41 if error: | |
| 42 if index != len(cache_lines) -1: | |
| 43 # This request has already been tried before, now it's fatal. | |
| 44 fatal_error = True | |
| 45 lines_to_retry.append(line) | |
| 46 errors.append(error) | |
| 47 | |
| 48 # Write any failing requests to the cache. | |
| 49 cache = open(CACHE_FILE, "w+b") | |
| 50 cache.write("\n".join(set(lines_to_retry))) | |
| 51 cache.close() | |
| 52 | |
| 53 # Print any errors, and if there was a fatal error, it should be an exception. | |
| 54 for error in errors: | |
| 55 print error | |
| 56 if fatal_error: | |
| 57 print "Multiple failures uploading to dashboard." | |
| 58 print "@@@STEP_EXCEPTION@@@" | |
| 59 | |
| 60 def _GetResultsJson(logname, lines, master, system, test, url, stdio_url): | |
| 61 results_to_add = [] | |
| 62 bot = system | |
| 63 graph = logname.replace("-summary.dat", "") | |
| 64 for line in lines: | |
| 65 data = json.loads(line) | |
| 66 revision = data["rev"] | |
| 67 for (trace, values) in data["traces"].iteritems(): | |
| 68 # TODO(sullivan): Handle special trace names: | |
| 69 # Reference builds | |
| 70 # by_url builds | |
| 71 test_path = "%s/%s/%s" % (test, graph, trace) | |
| 72 if graph == trace: | |
| 73 test_path = "%s/%s" % (test, graph) | |
| 74 result = { | |
| 75 "master": master, | |
| 76 "bot": system, | |
| 77 "test": test_path, | |
| 78 "revision": revision, | |
| 79 "value": values[0], | |
| 80 "error": values[1], | |
| 81 } | |
| 82 if "webkit_rev" in data and data["webkit_rev"] != "undefined": | |
| 83 result["supplemental_columns"] = {"r_webkit_rev": data["webkit_rev"]} | |
| 84 if stdio_url: | |
| 85 result["supplemental_columns"] = {"s_stdio_url": stdio_url} | |
| 86 results_to_add.append(result) | |
| 87 _PrintLinkStep(url, master, bot, test_path, revision) | |
| 88 return json.dumps(results_to_add) | |
| 89 | |
| 90 def _SendResultsJson(url, results_json): | |
| 91 data = urllib.urlencode({"data": results_json}) | |
| 92 req = urllib2.Request(url + SEND_RESULTS_PATH, data) | |
| 93 try: | |
| 94 urllib2.urlopen(req) | |
| 95 except urllib2.HTTPError, e: | |
| 96 return "HTTPError: %d for JSON %s\n" % (e.code, results_json) | |
| 97 except urllib2.URLError, e: | |
| 98 return "URLError: %s for JSON %s\n" % (str(e.reason), results_json) | |
| 99 except httplib.HTTPException, e: | |
| 100 return "HTTPException for JSON %s\n" % results_json | |
| 101 return None | |
| 102 | |
| 103 def _PrintLinkStep(url, master, bot, test_path, revision): | |
| 104 results_link = url + RESULTS_LINK_PATH % ( | |
| 105 urllib.quote(master), | |
| 106 urllib.quote(bot), | |
| 107 urllib.quote(test_path), | |
| 108 revision) | |
| 109 print "@@@STEP_LINK@%s@%s@@@" % ("Results Dashboard", results_link) | |
| OLD | NEW |