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

Unified Diff: gm/rebaseline_server/imagepair.py

Issue 235923002: rebaseline_server: multithreaded loading/diffing of images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: gm/rebaseline_server/imagepair.py
diff --git a/gm/rebaseline_server/imagepair.py b/gm/rebaseline_server/imagepair.py
index 33385ab5224b74239d6c7a347b421ddc777250e6..a89066fca31dfc2c74431551ebfea1dc2a3f37bb 100644
--- a/gm/rebaseline_server/imagepair.py
+++ b/gm/rebaseline_server/imagepair.py
@@ -48,27 +48,43 @@ class ImagePair(object):
self.extra_columns_dict = extra_columns
if not imageA_relative_url or not imageB_relative_url:
self._is_different = True
- self.diff_record = None
+ self._diff_record = None
+ self._diff_record_set = True
elif imageA_relative_url == imageB_relative_url:
self._is_different = False
- self.diff_record = None
+ self._diff_record = None
+ self._diff_record_set = True
else:
- # TODO(epoger): Rather than blocking until image_diff_db can read in
- # the image pair and generate diffs, it would be better to do it
- # asynchronously: tell image_diff_db to download a bunch of file pairs,
- # and only block later if we're still waiting for diff_records to come
- # back.
- self._is_different = True
- image_diff_db.add_image_pair(
+ # Tell image_diff_db to add this ImagePair.
+ # It will do so in a separate thread so as not to block this one;
+ # when you call self.get_diff_record(), it will block until the results
+ # are ready.
+ image_diff_db.add_image_pair_async(
expected_image_locator=imageA_relative_url,
expected_image_url=posixpath.join(base_url, imageA_relative_url),
actual_image_locator=imageB_relative_url,
actual_image_url=posixpath.join(base_url, imageB_relative_url))
- self.diff_record = image_diff_db.get_diff_record(
- expected_image_locator=imageA_relative_url,
- actual_image_locator=imageB_relative_url)
- if self.diff_record and self.diff_record.get_num_pixels_differing() == 0:
+ self._image_diff_db = image_diff_db
+ self._diff_record_set = False
+
+ def get_diff_record(self):
+ """Returns the DiffRecord associated with this ImagePair.
+
+ Returns None if the images are identical, or one is missing.
+ This method will block until the DiffRecord is available.
+ """
+ if not self._diff_record_set:
+ self._diff_record = self._image_diff_db.get_diff_record(
+ expected_image_locator=self.imageA_relative_url,
+ actual_image_locator=self.imageB_relative_url)
+ self._image_diff_db = None # release reference, no longer needed
+ if (self._diff_record and
+ self._diff_record.get_num_pixels_differing() == 0):
self._is_different = False
+ else:
+ self._is_different = True
+ self._diff_record_set = True
+ return self._diff_record
def as_dict(self):
"""Returns a dictionary describing this ImagePair.
@@ -79,11 +95,12 @@ class ImagePair(object):
KEY__IMAGE_A_URL: self.imageA_relative_url,
KEY__IMAGE_B_URL: self.imageB_relative_url,
}
- asdict[KEY__IS_DIFFERENT] = self._is_different
if self.expectations_dict:
asdict[KEY__EXPECTATIONS_DATA] = self.expectations_dict
if self.extra_columns_dict:
asdict[KEY__EXTRA_COLUMN_VALUES] = self.extra_columns_dict
- if self.diff_record and (self.diff_record.get_num_pixels_differing() > 0):
- asdict[KEY__DIFFERENCE_DATA] = self.diff_record.as_dict()
+ diff_record = self.get_diff_record()
+ if diff_record and (diff_record.get_num_pixels_differing() > 0):
+ asdict[KEY__DIFFERENCE_DATA] = diff_record.as_dict()
+ asdict[KEY__IS_DIFFERENT] = self._is_different
return asdict

Powered by Google App Engine
This is Rietveld 408576698