Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Side by Side Diff: gm/rebaseline_server/server.py

Issue 443013002: rebaseline_server: add "prefetch" directive that just warms the cache without awaiting results (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: download all images, unless downloadOnlyDifferingImages=true Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 """ 3 """
4 Copyright 2013 Google Inc. 4 Copyright 2013 Google Inc.
5 5
6 Use of this source code is governed by a BSD-style license that can be 6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file. 7 found in the LICENSE file.
8 8
9 HTTP server for our HTML rebaseline viewer. 9 HTTP server for our HTML rebaseline viewer.
10 """ 10 """
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 KEY__EDITS__OLD_RESULTS_HASH = 'oldResultsHash' 66 KEY__EDITS__OLD_RESULTS_HASH = 'oldResultsHash'
67 KEY__EDITS__OLD_RESULTS_TYPE = 'oldResultsType' 67 KEY__EDITS__OLD_RESULTS_TYPE = 'oldResultsType'
68 68
69 DEFAULT_ACTUALS_DIR = results_mod.DEFAULT_ACTUALS_DIR 69 DEFAULT_ACTUALS_DIR = results_mod.DEFAULT_ACTUALS_DIR
70 DEFAULT_GM_SUMMARIES_BUCKET = download_actuals.GM_SUMMARIES_BUCKET 70 DEFAULT_GM_SUMMARIES_BUCKET = download_actuals.GM_SUMMARIES_BUCKET
71 DEFAULT_JSON_FILENAME = download_actuals.DEFAULT_JSON_FILENAME 71 DEFAULT_JSON_FILENAME = download_actuals.DEFAULT_JSON_FILENAME
72 DEFAULT_PORT = 8888 72 DEFAULT_PORT = 8888
73 73
74 PARENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) 74 PARENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
75 TRUNK_DIRECTORY = os.path.dirname(os.path.dirname(PARENT_DIRECTORY)) 75 TRUNK_DIRECTORY = os.path.dirname(os.path.dirname(PARENT_DIRECTORY))
76 # Directory, relative to PARENT_DIRECTORY, within which the server will serve 76
77 # out image diff data from within the precomputed _SERVER.results .
78 PRECOMPUTED_RESULTS_SUBDIR = 'results'
79 # Directory, relative to PARENT_DIRECTORY, within which the server will serve
80 # out live-generated image diff data.
81 LIVE_RESULTS_SUBDIR = 'live-results'
82 # Directory, relative to PARENT_DIRECTORY, within which the server will serve 77 # Directory, relative to PARENT_DIRECTORY, within which the server will serve
83 # out static files. 78 # out static files.
84 STATIC_CONTENTS_SUBDIR = 'static' 79 STATIC_CONTENTS_SUBDIR = 'static'
85 # All of the GENERATED_*_SUBDIRS are relative to STATIC_CONTENTS_SUBDIR 80 # All of the GENERATED_*_SUBDIRS are relative to STATIC_CONTENTS_SUBDIR
86 GENERATED_HTML_SUBDIR = 'generated-html' 81 GENERATED_HTML_SUBDIR = 'generated-html'
87 GENERATED_IMAGES_SUBDIR = 'generated-images' 82 GENERATED_IMAGES_SUBDIR = 'generated-images'
88 GENERATED_JSON_SUBDIR = 'generated-json' 83 GENERATED_JSON_SUBDIR = 'generated-json'
89 84
85 # Directives associated with various HTTP GET requests.
86 GET__LIVE_RESULTS = 'live-results'
87 GET__PRECOMPUTED_RESULTS = 'results'
88 GET__PREFETCH_RESULTS = 'prefetch'
89 GET__STATIC_CONTENTS = 'static'
90
90 # Parameters we use within do_GET_live_results() 91 # Parameters we use within do_GET_live_results()
91 LIVE_PARAM__SET_A_DIR = 'setADir' 92 LIVE_PARAM__SET_A_DIR = 'setADir'
92 LIVE_PARAM__SET_B_DIR = 'setBDir' 93 LIVE_PARAM__SET_B_DIR = 'setBDir'
93 94
95 # Parameters we use within do_GET_prefetch_results()
96 PREFETCH_PARAM__DOWNLOAD_ONLY_DIFFERING = 'downloadOnlyDifferingImages'
97
94 # How often (in seconds) clients should reload while waiting for initial 98 # How often (in seconds) clients should reload while waiting for initial
95 # results to load. 99 # results to load.
96 RELOAD_INTERVAL_UNTIL_READY = 10 100 RELOAD_INTERVAL_UNTIL_READY = 10
97 101
98 SUMMARY_TYPES = [ 102 SUMMARY_TYPES = [
99 results_mod.KEY__HEADER__RESULTS_FAILURES, 103 results_mod.KEY__HEADER__RESULTS_FAILURES,
100 results_mod.KEY__HEADER__RESULTS_ALL, 104 results_mod.KEY__HEADER__RESULTS_ALL,
101 ] 105 ]
102 # If --compare-configs is specified, compare these configs. 106 # If --compare-configs is specified, compare these configs.
103 CONFIG_PAIRS_TO_COMPARE = [('8888', 'gpu')] 107 CONFIG_PAIRS_TO_COMPARE = [('8888', 'gpu')]
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 os.makedirs(dir_path) 167 os.makedirs(dir_path)
164 with open(file_path, 'w') as file_handle: 168 with open(file_path, 'w') as file_handle:
165 file_handle.write( 169 file_handle.write(
166 '<!DOCTYPE html><html>' 170 '<!DOCTYPE html><html>'
167 '<head><title>rebaseline_server</title></head>' 171 '<head><title>rebaseline_server</title></head>'
168 '<body><ul>') 172 '<body><ul>')
169 if SUMMARY_TYPES: 173 if SUMMARY_TYPES:
170 file_handle.write('<li>Expectations vs Actuals</li><ul>') 174 file_handle.write('<li>Expectations vs Actuals</li><ul>')
171 for summary_type in SUMMARY_TYPES: 175 for summary_type in SUMMARY_TYPES:
172 file_handle.write( 176 file_handle.write(
173 '<li><a href="/{static_subdir}/view.html#/view.html?' 177 '<li><a href="/{static_directive}/view.html#/view.html?'
174 'resultsToLoad=/{results_subdir}/{summary_type}">' 178 'resultsToLoad=/{results_directive}/{summary_type}">'
175 '{summary_type}</a></li>'.format( 179 '{summary_type}</a></li>'.format(
176 results_subdir=PRECOMPUTED_RESULTS_SUBDIR, 180 results_directive=GET__PRECOMPUTED_RESULTS,
177 static_subdir=STATIC_CONTENTS_SUBDIR, 181 static_directive=GET__STATIC_CONTENTS,
178 summary_type=summary_type)) 182 summary_type=summary_type))
179 file_handle.write('</ul>') 183 file_handle.write('</ul>')
180 if config_pairs: 184 if config_pairs:
181 file_handle.write('<li>Comparing configs within actual results</li><ul>') 185 file_handle.write('<li>Comparing configs within actual results</li><ul>')
182 for config_pair in config_pairs: 186 for config_pair in config_pairs:
183 file_handle.write('<li>%s vs %s:' % config_pair) 187 file_handle.write('<li>%s vs %s:' % config_pair)
184 for summary_type in SUMMARY_TYPES: 188 for summary_type in SUMMARY_TYPES:
185 file_handle.write( 189 file_handle.write(
186 ' <a href="/%s/view.html#/view.html?' 190 ' <a href="/%s/view.html#/view.html?'
187 'resultsToLoad=/%s/%s/%s-vs-%s_%s.json">%s</a>' % ( 191 'resultsToLoad=/%s/%s/%s-vs-%s_%s.json">%s</a>' % (
188 STATIC_CONTENTS_SUBDIR, STATIC_CONTENTS_SUBDIR, 192 GET__STATIC_CONTENTS, GET__STATIC_CONTENTS,
189 GENERATED_JSON_SUBDIR, config_pair[0], config_pair[1], 193 GENERATED_JSON_SUBDIR, config_pair[0], config_pair[1],
190 summary_type, summary_type)) 194 summary_type, summary_type))
191 file_handle.write('</li>') 195 file_handle.write('</li>')
192 file_handle.write('</ul>') 196 file_handle.write('</ul>')
193 file_handle.write('</ul></body></html>') 197 file_handle.write('</ul></body></html>')
194 198
195 199
196 class Server(object): 200 class Server(object):
197 """ HTTP server for our HTML rebaseline viewer. """ 201 """ HTTP server for our HTML rebaseline viewer. """
198 202
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 """ 458 """
455 Handles all GET requests, forwarding them to the appropriate 459 Handles all GET requests, forwarding them to the appropriate
456 do_GET_* dispatcher. 460 do_GET_* dispatcher.
457 461
458 If we see any Exceptions, return a 404. This fixes http://skbug.com/2147 462 If we see any Exceptions, return a 404. This fixes http://skbug.com/2147
459 """ 463 """
460 try: 464 try:
461 logging.debug('do_GET: path="%s"' % self.path) 465 logging.debug('do_GET: path="%s"' % self.path)
462 if self.path == '' or self.path == '/' or self.path == '/index.html' : 466 if self.path == '' or self.path == '/' or self.path == '/index.html' :
463 self.redirect_to('/%s/%s/index.html' % ( 467 self.redirect_to('/%s/%s/index.html' % (
464 STATIC_CONTENTS_SUBDIR, GENERATED_HTML_SUBDIR)) 468 GET__STATIC_CONTENTS, GENERATED_HTML_SUBDIR))
465 return 469 return
466 if self.path == '/favicon.ico' : 470 if self.path == '/favicon.ico' :
467 self.redirect_to('/%s/favicon.ico' % STATIC_CONTENTS_SUBDIR) 471 self.redirect_to('/%s/favicon.ico' % GET__STATIC_CONTENTS)
468 return 472 return
469 473
470 # All requests must be of this form: 474 # All requests must be of this form:
471 # /dispatcher/remainder 475 # /dispatcher/remainder
472 # where 'dispatcher' indicates which do_GET_* dispatcher to run 476 # where 'dispatcher' indicates which do_GET_* dispatcher to run
473 # and 'remainder' is the remaining path sent to that dispatcher. 477 # and 'remainder' is the remaining path sent to that dispatcher.
474 normpath = posixpath.normpath(self.path) 478 normpath = posixpath.normpath(self.path)
475 (dispatcher_name, remainder) = PATHSPLIT_RE.match(normpath).groups() 479 (dispatcher_name, remainder) = PATHSPLIT_RE.match(normpath).groups()
476 dispatchers = { 480 dispatchers = {
477 PRECOMPUTED_RESULTS_SUBDIR: self.do_GET_precomputed_results, 481 GET__LIVE_RESULTS: self.do_GET_live_results,
478 LIVE_RESULTS_SUBDIR: self.do_GET_live_results, 482 GET__PRECOMPUTED_RESULTS: self.do_GET_precomputed_results,
479 STATIC_CONTENTS_SUBDIR: self.do_GET_static, 483 GET__PREFETCH_RESULTS: self.do_GET_prefetch_results,
484 GET__STATIC_CONTENTS: self.do_GET_static,
480 } 485 }
481 dispatcher = dispatchers[dispatcher_name] 486 dispatcher = dispatchers[dispatcher_name]
482 dispatcher(remainder) 487 dispatcher(remainder)
483 except: 488 except:
484 self.send_error(404) 489 self.send_error(404)
485 raise 490 raise
486 491
487 def do_GET_precomputed_results(self, results_type): 492 def do_GET_precomputed_results(self, results_type):
488 """ Handle a GET request for part of the precomputed _SERVER.results object. 493 """ Handle a GET request for part of the precomputed _SERVER.results object.
489 494
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 param_dict = urlparse.parse_qs(url_remainder) 535 param_dict = urlparse.parse_qs(url_remainder)
531 results_obj = compare_rendered_pictures.RenderedPicturesComparisons( 536 results_obj = compare_rendered_pictures.RenderedPicturesComparisons(
532 setA_dirs=param_dict[LIVE_PARAM__SET_A_DIR], 537 setA_dirs=param_dict[LIVE_PARAM__SET_A_DIR],
533 setB_dirs=param_dict[LIVE_PARAM__SET_B_DIR], 538 setB_dirs=param_dict[LIVE_PARAM__SET_B_DIR],
534 image_diff_db=_SERVER.image_diff_db, 539 image_diff_db=_SERVER.image_diff_db,
535 diff_base_url='/static/generated-images', 540 diff_base_url='/static/generated-images',
536 gs=_SERVER.gs, truncate_results=_SERVER.truncate_results) 541 gs=_SERVER.gs, truncate_results=_SERVER.truncate_results)
537 self.send_json_dict(results_obj.get_packaged_results_of_type( 542 self.send_json_dict(results_obj.get_packaged_results_of_type(
538 results_mod.KEY__HEADER__RESULTS_ALL)) 543 results_mod.KEY__HEADER__RESULTS_ALL))
539 544
545 def do_GET_prefetch_results(self, url_remainder):
546 """ Prefetch image diff data for a future do_GET_live_results() call.
547
548 Args:
549 url_remainder: string indicating which image diffs to generate
550 """
551 logging.debug('do_GET_prefetch_results: url_remainder="%s"' % url_remainder)
552 param_dict = urlparse.parse_qs(url_remainder)
553 download_all_images = (
554 param_dict.get(PREFETCH_PARAM__DOWNLOAD_ONLY_DIFFERING, [''])[0].lower()
555 not in ['1', 'true'])
556 compare_rendered_pictures.RenderedPicturesComparisons(
557 setA_dirs=param_dict[LIVE_PARAM__SET_A_DIR],
558 setB_dirs=param_dict[LIVE_PARAM__SET_B_DIR],
559 image_diff_db=_SERVER.image_diff_db,
560 diff_base_url='/static/generated-images',
561 gs=_SERVER.gs, truncate_results=_SERVER.truncate_results,
562 prefetch_only=True, download_all_images=download_all_images)
563 self.send_response(200)
564
540 def do_GET_static(self, path): 565 def do_GET_static(self, path):
541 """ Handle a GET request for a file under STATIC_CONTENTS_SUBDIR . 566 """ Handle a GET request for a file under STATIC_CONTENTS_SUBDIR .
542 Only allow serving of files within STATIC_CONTENTS_SUBDIR that is a 567 Only allow serving of files within STATIC_CONTENTS_SUBDIR that is a
543 filesystem sibling of this script. 568 filesystem sibling of this script.
544 569
545 Args: 570 Args:
546 path: path to file (within STATIC_CONTENTS_SUBDIR) to retrieve 571 path: path to file (within STATIC_CONTENTS_SUBDIR) to retrieve
547 """ 572 """
548 # Strip arguments ('?resultsToLoad=all') from the path 573 # Strip arguments ('?resultsToLoad=all') from the path
549 path = urlparse.urlparse(path).path 574 path = urlparse.urlparse(path).path
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 reload_seconds=args.reload, config_pairs=config_pairs, 791 reload_seconds=args.reload, config_pairs=config_pairs,
767 builder_regex_list=args.builders, boto_file_path=args.boto, 792 builder_regex_list=args.builders, boto_file_path=args.boto,
768 imagediffdb_threads=args.threads) 793 imagediffdb_threads=args.threads)
769 if args.truncate: 794 if args.truncate:
770 _SERVER.truncate_results = True 795 _SERVER.truncate_results = True
771 _SERVER.run() 796 _SERVER.run()
772 797
773 798
774 if __name__ == '__main__': 799 if __name__ == '__main__':
775 main() 800 main()
OLDNEW
« gm/rebaseline_server/imagediffdb.py ('K') | « gm/rebaseline_server/imagepair_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698