| OLD | NEW |
| 1 # Copyright (C) 2011, Google Inc. All rights reserved. | 1 # Copyright (C) 2011, Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import copy | 29 import copy |
| 30 import logging | 30 import logging |
| 31 | 31 |
| 32 from webkitpy.common.memoized import memoized | 32 from webkitpy.common.memoized import memoized |
| 33 from functools import reduce |
| 33 | 34 |
| 34 _log = logging.getLogger(__name__) | 35 _log = logging.getLogger(__name__) |
| 35 | 36 |
| 36 | 37 |
| 37 # FIXME: Should this function be somewhere more general? | 38 # FIXME: Should this function be somewhere more general? |
| 38 def _invert_dictionary(dictionary): | 39 def _invert_dictionary(dictionary): |
| 39 inverted_dictionary = {} | 40 inverted_dictionary = {} |
| 40 for key, value in dictionary.items(): | 41 for key, value in dictionary.items(): |
| 41 if inverted_dictionary.get(value): | 42 if inverted_dictionary.get(value): |
| 42 inverted_dictionary[value].append(key) | 43 inverted_dictionary[value].append(key) |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 if new_results_by_directory == results_by_directory: | 286 if new_results_by_directory == results_by_directory: |
| 286 if new_results_by_directory: | 287 if new_results_by_directory: |
| 287 _log.debug(" %s: (already optimal)" % basename) | 288 _log.debug(" %s: (already optimal)" % basename) |
| 288 self.write_by_directory(results_by_directory, _log.debug, " "
) | 289 self.write_by_directory(results_by_directory, _log.debug, " "
) |
| 289 else: | 290 else: |
| 290 _log.debug(" %s: (no baselines found)" % basename) | 291 _log.debug(" %s: (no baselines found)" % basename) |
| 291 # This is just used for unittests. Intentionally set it to the old d
ata if we don't modify anything. | 292 # This is just used for unittests. Intentionally set it to the old d
ata if we don't modify anything. |
| 292 self.new_results_by_directory.append(results_by_directory) | 293 self.new_results_by_directory.append(results_by_directory) |
| 293 return True | 294 return True |
| 294 | 295 |
| 295 if self._results_by_port_name(results_by_directory, baseline_name) != se
lf._results_by_port_name(new_results_by_directory, baseline_name): | 296 if self._results_by_port_name(results_by_directory, baseline_name) != se
lf._results_by_port_name( |
| 297 new_results_by_directory, baseline_name): |
| 296 # This really should never happen. Just a sanity check to make sure
the script fails in the case of bugs | 298 # This really should never happen. Just a sanity check to make sure
the script fails in the case of bugs |
| 297 # instead of committing incorrect baselines. | 299 # instead of committing incorrect baselines. |
| 298 _log.error(" %s: optimization failed" % basename) | 300 _log.error(" %s: optimization failed" % basename) |
| 299 self.write_by_directory(results_by_directory, _log.warning, " "
) | 301 self.write_by_directory(results_by_directory, _log.warning, " "
) |
| 300 return False | 302 return False |
| 301 | 303 |
| 302 _log.debug(" %s:" % basename) | 304 _log.debug(" %s:" % basename) |
| 303 _log.debug(" Before: ") | 305 _log.debug(" Before: ") |
| 304 self.write_by_directory(results_by_directory, _log.debug, " ") | 306 self.write_by_directory(results_by_directory, _log.debug, " ") |
| 305 _log.debug(" After: ") | 307 _log.debug(" After: ") |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 result = self._optimize_subtree(baseline_name) | 353 result = self._optimize_subtree(baseline_name) |
| 352 non_virtual_baseline_name = self._virtual_base(baseline_name) | 354 non_virtual_baseline_name = self._virtual_base(baseline_name) |
| 353 if not non_virtual_baseline_name: | 355 if not non_virtual_baseline_name: |
| 354 return result, self._files_to_delete, self._files_to_add | 356 return result, self._files_to_delete, self._files_to_add |
| 355 | 357 |
| 356 self._optimize_virtual_root(baseline_name, non_virtual_baseline_name) | 358 self._optimize_virtual_root(baseline_name, non_virtual_baseline_name) |
| 357 | 359 |
| 358 _log.debug("Optimizing non-virtual fallback path.") | 360 _log.debug("Optimizing non-virtual fallback path.") |
| 359 result |= self._optimize_subtree(non_virtual_baseline_name) | 361 result |= self._optimize_subtree(non_virtual_baseline_name) |
| 360 return result, self._files_to_delete, self._files_to_add | 362 return result, self._files_to_delete, self._files_to_add |
| OLD | NEW |