| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import platform | 9 import platform |
| 10 import re | |
| 11 import subprocess | 10 import subprocess |
| 11 import tempfile |
| 12 import urllib2 | 12 import urllib2 |
| 13 | 13 |
| 14 | 14 |
| 15 from core import path_util | 15 from core import path_util |
| 16 | 16 |
| 17 from telemetry import benchmark | 17 from telemetry import benchmark |
| 18 from telemetry import decorators | 18 from telemetry import decorators |
| 19 from telemetry.core import discover | 19 from telemetry.core import discover |
| 20 from telemetry.util import command_line | 20 from telemetry.util import command_line |
| 21 from telemetry.util import matching | 21 from telemetry.util import matching |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 if branch_name == 'HEAD': | 439 if branch_name == 'HEAD': |
| 440 raise TrybotError('Not on a valid branch, looks like branch ' | 440 raise TrybotError('Not on a valid branch, looks like branch ' |
| 441 'is dettached. [branch:%s]' % branch_name) | 441 'is dettached. [branch:%s]' % branch_name) |
| 442 | 442 |
| 443 # Check if the tree is dirty: make sure the index is up to date and then | 443 # Check if the tree is dirty: make sure the index is up to date and then |
| 444 # run diff-index | 444 # run diff-index |
| 445 RunGit(['update-index', '--refresh', '-q'], ignore_return_code=True) | 445 RunGit(['update-index', '--refresh', '-q'], ignore_return_code=True) |
| 446 output = RunGit(['diff-index', 'HEAD']) | 446 output = RunGit(['diff-index', 'HEAD']) |
| 447 if output: | 447 if output: |
| 448 raise TrybotError( | 448 raise TrybotError( |
| 449 'Cannot send a try job with a dirty tree. Please commit ' | 449 'Cannot send a try job with a dirty tree.\nPlease commit locally and ' |
| 450 'your changes locally first in %s repository.' % repo_path) | 450 'upload your changes to rietveld in %s repository.' % repo_path) |
| 451 | |
| 452 # Make sure the tree does have local commits. | |
| 453 output = RunGit(['footers', 'HEAD']) | |
| 454 if output: | |
| 455 raise TrybotError('No local changes found in %s repository.' % repo_path) | |
| 456 | 451 |
| 457 return (repo_name, branch_name) | 452 return (repo_name, branch_name) |
| 458 | 453 |
| 459 def _GetBaseGitHashForRepo(self, branch_name, git_url): | 454 def _GetBaseGitHashForRepo(self, branch_name, git_url): |
| 460 """Gets the base revision for the repo on which local changes are made. | 455 """Gets the base revision for the repo on which local changes are made. |
| 461 | 456 |
| 462 Finds the upstream of the current branch that it is set to and gets | 457 Finds the upstream of the current branch that it is set to and gets |
| 463 the HEAD revision from upstream. This also checks if the remote URL on | 458 the HEAD revision from upstream. This also checks if the remote URL on |
| 464 the upstream is supported by Perf Try job. | 459 the upstream is supported by Perf Try job. |
| 465 | 460 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 494 if cur_remote == '.': | 489 if cur_remote == '.': |
| 495 return False | 490 return False |
| 496 cur_remote_url = RunGit( | 491 cur_remote_url = RunGit( |
| 497 ['config', 'remote.%s.url' % cur_remote], | 492 ['config', 'remote.%s.url' % cur_remote], |
| 498 'Failed to get remote.%s.url from git config' % cur_remote) | 493 'Failed to get remote.%s.url from git config' % cur_remote) |
| 499 if cur_remote_url.lower() == repo_git_url: | 494 if cur_remote_url.lower() == repo_git_url: |
| 500 return True | 495 return True |
| 501 raise TrybotError('URL %s on remote %s is not recognized on branch.'% ( | 496 raise TrybotError('URL %s on remote %s is not recognized on branch.'% ( |
| 502 cur_remote_url, cur_remote)) | 497 cur_remote_url, cur_remote)) |
| 503 | 498 |
| 499 def _GetChangeList(self): |
| 500 """Gets the codereview URL for the current changes.""" |
| 501 temp_file = None |
| 502 json_output = None |
| 503 try: |
| 504 fd, temp_file = tempfile.mkstemp(suffix='.json', prefix='perf_try_cl') |
| 505 os.close(fd) |
| 506 RunGit(['cl', 'issue', '--json', temp_file], |
| 507 'Failed to run "git cl issue" command.') |
| 508 with open(temp_file, 'r') as f: |
| 509 json_output = json.load(f) |
| 510 finally: |
| 511 try: |
| 512 if temp_file: |
| 513 os.remove(temp_file) |
| 514 except OSError: |
| 515 pass |
| 516 |
| 517 # Make sure the local commits are uploaded to rietveld. |
| 518 if not json_output.get('issue'): |
| 519 raise TrybotError( |
| 520 'PLEASE NOTE: The workflow for Perf Try jobs is changed. ' |
| 521 'In order to run the perf try job, you must first upload your ' |
| 522 'changes to rietveld.') |
| 523 return json_output.get('issue_url') |
| 524 |
| 504 def _AttemptTryjob(self, options, extra_args): | 525 def _AttemptTryjob(self, options, extra_args): |
| 505 """Attempts to run a tryjob from a repo directory. | 526 """Attempts to run a tryjob from a repo directory. |
| 506 | 527 |
| 507 Args: | 528 Args: |
| 508 options: Command line arguments to run benchmark. | 529 options: Command line arguments to run benchmark. |
| 509 extra_args: Extra arugments to run benchmark. | 530 extra_args: Extra arugments to run benchmark. |
| 510 | 531 |
| 511 Returns: | 532 Returns: |
| 512 If successful returns 0, otherwise 1. | 533 If successful returns 0, otherwise 1. |
| 513 """ | 534 """ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 526 if not repo_info: | 547 if not repo_info: |
| 527 raise TrybotError('Unsupported repository %s' % repo_name) | 548 raise TrybotError('Unsupported repository %s' % repo_name) |
| 528 | 549 |
| 529 deps_override = None | 550 deps_override = None |
| 530 if repo_name != 'src': | 551 if repo_name != 'src': |
| 531 if not options.deps_revision: | 552 if not options.deps_revision: |
| 532 options.deps_revision = self._GetBaseGitHashForRepo( | 553 options.deps_revision = self._GetBaseGitHashForRepo( |
| 533 branch_name, repo_info.get('url')) | 554 branch_name, repo_info.get('url')) |
| 534 deps_override = {repo_info.get('src'): options.deps_revision} | 555 deps_override = {repo_info.get('src'): options.deps_revision} |
| 535 | 556 |
| 536 arguments = [options.benchmark_name] + extra_args | 557 rietveld_url = self._GetChangeList() |
| 537 | 558 print ('\nRunning try job....\nview progress here %s.' |
| 538 rietveld_url = self._UploadPatchToRietveld(repo_name, options) | |
| 539 print ('\nUploaded try job to rietveld.\nview progress here %s.' | |
| 540 '\n\tRepo Name: %s\n\tPath: %s\n\tBranch: %s' % ( | 559 '\n\tRepo Name: %s\n\tPath: %s\n\tBranch: %s' % ( |
| 541 rietveld_url, repo_name, repo_path, branch_name)) | 560 rietveld_url, repo_name, repo_path, branch_name)) |
| 542 | 561 |
| 543 for bot_platform in self._builder_names: | 562 for bot_platform in self._builder_names: |
| 544 if not self._builder_names[bot_platform]: | 563 if not self._builder_names[bot_platform]: |
| 545 logging.warning('No builder is found for %s', bot_platform) | 564 logging.warning('No builder is found for %s', bot_platform) |
| 546 continue | 565 continue |
| 547 try: | 566 try: |
| 567 arguments = [options.benchmark_name] + extra_args |
| 548 self._RunTryJob(bot_platform, arguments, deps_override) | 568 self._RunTryJob(bot_platform, arguments, deps_override) |
| 549 # Even if git cl try throws TrybotError exception for any platform, | 569 # Even if git cl try throws TrybotError exception for any platform, |
| 550 # keep sending try jobs to other platforms. | 570 # keep sending try jobs to other platforms. |
| 551 except TrybotError, err: | 571 except TrybotError, err: |
| 552 print err | 572 print err |
| 553 except TrybotError, error: | 573 except TrybotError, error: |
| 554 print error | 574 print error |
| 555 return 1 | 575 return 1 |
| 556 finally: | 576 finally: |
| 557 # Restore to original working directory. | 577 # Restore to original working directory. |
| 558 os.chdir(original_workdir) | 578 os.chdir(original_workdir) |
| 559 return 0 | 579 return 0 |
| 560 | 580 |
| 561 def _UploadPatchToRietveld(self, repo_name, options): | |
| 562 """Uploads the patch to rietveld and returns rietveld URL.""" | |
| 563 output = RunGit(['cl', 'upload', '-f', '--bypass-hooks', '-m', | |
| 564 ('CL for %s perf tryjob to run %s benchmark ' | |
| 565 'on %s platform(s)' % ( | |
| 566 repo_name, options.benchmark_name, options.trybot))], | |
| 567 'Could not upload to rietveld for %s' % repo_name) | |
| 568 | |
| 569 match = re.search(r'https://codereview.chromium.org/[\d]+', output) | |
| 570 if not match: | |
| 571 raise TrybotError('Could not upload CL to rietveld for %s! Output %s' % | |
| 572 (repo_name, output)) | |
| 573 return match.group(0) | |
| 574 | |
| 575 def _RunTryJob(self, bot_platform, arguments, deps_override): | 581 def _RunTryJob(self, bot_platform, arguments, deps_override): |
| 576 """Executes perf try job with benchmark test properties. | 582 """Executes perf try job with benchmark test properties. |
| 577 | 583 |
| 578 Args: | 584 Args: |
| 579 bot_platform: Name of the platform to be generated. | 585 bot_platform: Name of the platform to be generated. |
| 580 arguments: Command line arguments. | 586 arguments: Command line arguments. |
| 581 deps_override: DEPS revision if needs to be overridden. | 587 deps_override: DEPS revision if needs to be overridden. |
| 582 | 588 |
| 583 Raises: | 589 Raises: |
| 584 TrybotError: When trybot fails to upload CL or run git try. | 590 TrybotError: When trybot fails to upload CL or run git try. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 595 # Add deps overrides to git try --properties arg. | 601 # Add deps overrides to git try --properties arg. |
| 596 if deps_override: | 602 if deps_override: |
| 597 git_try_command.extend([ | 603 git_try_command.extend([ |
| 598 '-p', 'deps_revision_overrides=%s' % json.dumps(deps_override)]) | 604 '-p', 'deps_revision_overrides=%s' % json.dumps(deps_override)]) |
| 599 error_msg_on_fail += ' with DEPS override (%s)' % deps_override | 605 error_msg_on_fail += ' with DEPS override (%s)' % deps_override |
| 600 for bot in self._builder_names[bot_platform]: | 606 for bot in self._builder_names[bot_platform]: |
| 601 git_try_command.extend(['-b', bot]) | 607 git_try_command.extend(['-b', bot]) |
| 602 | 608 |
| 603 RunGit(git_try_command, error_msg_on_fail) | 609 RunGit(git_try_command, error_msg_on_fail) |
| 604 print 'Perf Try job sent to rietveld for %s platform.' % bot_platform | 610 print 'Perf Try job sent to rietveld for %s platform.' % bot_platform |
| OLD | NEW |