OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 | 6 |
7 import datetime | 7 import datetime |
8 import math | 8 import math |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 out.seek(0, os.SEEK_END) | 71 out.seek(0, os.SEEK_END) |
72 p = subprocess.Popen(cmd_list, stdout = out, stderr=subprocess.PIPE, | 72 p = subprocess.Popen(cmd_list, stdout = out, stderr=subprocess.PIPE, |
73 stdin=subprocess.PIPE, shell=self.has_shell) | 73 stdin=subprocess.PIPE, shell=self.has_shell) |
74 output, stderr = p.communicate(std_in) | 74 output, stderr = p.communicate(std_in) |
75 if output: | 75 if output: |
76 print output | 76 print output |
77 if stderr: | 77 if stderr: |
78 print stderr | 78 print stderr |
79 return output, stderr | 79 return output, stderr |
80 | 80 |
| 81 def RunBrowserPerfRunnerCmd(self, browser, url_path, file_path_to_test_code, |
| 82 trace_file, code_root=''): |
| 83 command_list = [os.path.join(DART_REPO_LOC, utils.GetBuildRoot( |
| 84 utils.GuessOS(), 'release', 'ia32'), 'dart-sdk', 'bin', 'dart'), |
| 85 '--package-root=%s' % os.path.join(file_path_to_test_code, 'packages'), |
| 86 os.path.join(file_path_to_test_code, 'packages', |
| 87 'browser_controller', 'browser_perf_testing.dart'), '--browser', |
| 88 browser, '--test_path=%s' % url_path] |
| 89 if code_root != '': |
| 90 command_list += ['--code_root=%s' % code_root] |
| 91 |
| 92 if browser == 'dartium': |
| 93 dartium_path = os.path.join(DART_REPO_LOC, 'client', 'tests', 'dartium') |
| 94 if platform.system() == 'Windows': |
| 95 dartium_path = os.path.join(dartium_path, 'chrome.exe'); |
| 96 elif platform.system() == 'Darwin': |
| 97 dartium_path = os.path.join(dartium_path, 'Chromium.app', 'Contents', |
| 98 'MacOS', 'Chromium') |
| 99 else: |
| 100 dartium_path = os.path.join(dartium_path, 'chrome') |
| 101 command_list += ['--executable=%s' % dartium_path] |
| 102 |
| 103 self.RunCmd(command_list, trace_file, append=True) |
| 104 |
81 def TimeCmd(self, cmd): | 105 def TimeCmd(self, cmd): |
82 """Determine the amount of (real) time it takes to execute a given | 106 """Determine the amount of (real) time it takes to execute a given |
83 command.""" | 107 command.""" |
84 start = time.time() | 108 start = time.time() |
85 self.RunCmd(cmd) | 109 self.RunCmd(cmd) |
86 return time.time() - start | 110 return time.time() - start |
87 | 111 |
88 def ClearOutUnversionedFiles(self): | 112 def ClearOutUnversionedFiles(self): |
89 """Remove all files that are unversioned by svn.""" | 113 """Remove all files that are unversioned by svn.""" |
90 if os.path.exists(DART_REPO_LOC): | 114 if os.path.exists(DART_REPO_LOC): |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 or 'InvalidUriError' in stderr or "Couldn't download" in stdout or | 193 or 'InvalidUriError' in stderr or "Couldn't download" in stdout or |
170 'Unable to download' in stdout): | 194 'Unable to download' in stdout): |
171 # Couldn't find the SDK on Google Storage. Build it locally. | 195 # Couldn't find the SDK on Google Storage. Build it locally. |
172 | 196 |
173 # TODO(efortuna): Currently always building ia32 architecture because we | 197 # TODO(efortuna): Currently always building ia32 architecture because we |
174 # don't have test statistics for what's passing on x64. Eliminate arch | 198 # don't have test statistics for what's passing on x64. Eliminate arch |
175 # specification when we have tests running on x64, too. | 199 # specification when we have tests running on x64, too. |
176 shutil.rmtree(os.path.join(os.getcwd(), | 200 shutil.rmtree(os.path.join(os.getcwd(), |
177 utils.GetBuildRoot(utils.GuessOS())), | 201 utils.GetBuildRoot(utils.GuessOS())), |
178 onerror=TestRunner._OnRmError) | 202 onerror=TestRunner._OnRmError) |
179 lines = self.RunCmd([os.path.join('.', 'tools', 'build.py'), '-m', | 203 lines = self.RunCmd(['python', os.path.join('tools', 'build.py'), '-m', |
180 'release', '--arch=ia32', 'create_sdk']) | 204 'release', '--arch=ia32', 'create_sdk']) |
181 | 205 |
182 for line in lines: | 206 for line in lines: |
183 if 'BUILD FAILED' in line: | 207 if 'BUILD FAILED' in line: |
184 # Someone checked in a broken build! Stop trying to make it work | 208 # Someone checked in a broken build! Stop trying to make it work |
185 # and wait to try again. | 209 # and wait to try again. |
186 print 'Broken Build' | 210 print 'Broken Build' |
187 return 1 | 211 return 1 |
188 return 0 | 212 return 0 |
189 | 213 |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 | 738 |
715 class DromaeoPerfTester(DromaeoTester): | 739 class DromaeoPerfTester(DromaeoTester): |
716 def RunTests(self): | 740 def RunTests(self): |
717 """Run dromaeo in the browser.""" | 741 """Run dromaeo in the browser.""" |
718 success, _, _ = self.test.test_runner.GetArchive('dartium') | 742 success, _, _ = self.test.test_runner.GetArchive('dartium') |
719 if not success: | 743 if not success: |
720 # Unable to download dartium. Try later. | 744 # Unable to download dartium. Try later. |
721 return | 745 return |
722 | 746 |
723 # Build tests. | 747 # Build tests. |
724 # TODO(efortuna): Make the pub functionality a separate function. | |
725 current_path = os.getcwd() | 748 current_path = os.getcwd() |
726 os.chdir(os.path.join(DART_REPO_LOC, 'samples', 'third_party', | 749 os.chdir(os.path.join(DART_REPO_LOC, 'samples', 'third_party', |
727 'dromaeo')) | 750 'dromaeo')) |
728 self.test.test_runner.RunCmd([os.path.join(DART_REPO_LOC, | 751 # Note: This uses debug on purpose, so that we can also run performance |
729 utils.GetBuildRoot(utils.GuessOS(), 'release', 'ia32'), | 752 # tests on pure Dart applications in Dartium. Pub --debug simply also |
730 'dart-sdk', 'bin', 'pub'), 'install']) # TODO: pub upgrade? | 753 # moves the .dart files to the build directory. To ensure effective |
| 754 # comparison, though, ensure that minify: true is set in your transformer |
| 755 # compilation step in your pubspec. |
731 stdout, _ = self.test.test_runner.RunCmd([os.path.join(DART_REPO_LOC, | 756 stdout, _ = self.test.test_runner.RunCmd([os.path.join(DART_REPO_LOC, |
732 utils.GetBuildRoot(utils.GuessOS(), 'release', 'ia32'), | 757 utils.GetBuildRoot(utils.GuessOS(), 'release', 'ia32'), |
733 'dart-sdk', 'bin', 'pub'), 'build']) | 758 'dart-sdk', 'bin', 'pub'), 'build', '--mode=debug']) |
734 os.chdir(current_path) | 759 os.chdir(current_path) |
735 if 'failed' in stdout: | 760 if 'failed' in stdout: |
736 return | 761 return |
737 | 762 |
738 versions = DromaeoTester.GetDromaeoVersions() | 763 versions = DromaeoTester.GetDromaeoVersions() |
739 | 764 |
740 for browser in BrowserTester.GetBrowsers(): | 765 for browser in BrowserTester.GetBrowsers(): |
741 for version_name in versions: | 766 for version_name in versions: |
742 if not self.test.IsValidCombination(browser, version_name): | 767 if not self.test.IsValidCombination(browser, version_name): |
743 continue | 768 continue |
744 version = DromaeoTest.DromaeoPerfTester.GetDromaeoUrlQuery( | 769 version = DromaeoTest.DromaeoPerfTester.GetDromaeoUrlQuery( |
745 browser, version_name) | 770 browser, version_name) |
746 self.test.trace_file = os.path.join(TOP_LEVEL_DIR, | 771 self.test.trace_file = os.path.join(TOP_LEVEL_DIR, |
747 'tools', 'testing', 'perf_testing', self.test.result_folder_name, | 772 'tools', 'testing', 'perf_testing', self.test.result_folder_name, |
748 'dromaeo-%s-%s-%s' % (self.test.cur_time, browser, version_name)) | 773 'dromaeo-%s-%s-%s' % (self.test.cur_time, browser, version_name)) |
749 self.AddSvnRevisionToTrace(self.test.trace_file, browser) | 774 self.AddSvnRevisionToTrace(self.test.trace_file, browser) |
750 url_path = '/'.join(['/code_root', 'build', 'web', 'index%s.html?%s'%( | 775 url_path = '/'.join(['/code_root', 'build', 'web', 'index%s.html?%s'%( |
751 '-dart' if version_name == 'dart_html' else '-js', | 776 '-dart' if version_name == 'dart_html' else '-js', |
752 version)]) | 777 version)]) |
753 | 778 |
754 self.test.test_runner.RunCmd( | 779 self.test.test_runner.RunBrowserPerfRunnerCmd(browser, url_path, |
755 [os.path.join(DART_REPO_LOC, utils.GetBuildRoot( | 780 os.path.join(DART_REPO_LOC, 'samples', 'third_party', 'dromaeo'), |
756 utils.GuessOS(), 'release', 'ia32'), 'dart-sdk', 'bin', 'dart'), | 781 self.test.trace_file) |
757 '--package-root=%s' % os.path.join(DART_REPO_LOC, 'samples', | |
758 'third_party', 'dromaeo', 'packages'), os.path.join( | |
759 DART_REPO_LOC, 'samples', 'third_party', 'dromaeo', 'packages', | |
760 'browser_controller', 'browser_perf_testing.dart'), | |
761 '--browser', browser, | |
762 '--test_path', url_path], self.test.trace_file, | |
763 append=True) | |
764 | 782 |
765 @staticmethod | 783 @staticmethod |
766 def GetDromaeoUrlQuery(browser, version): | 784 def GetDromaeoUrlQuery(browser, version): |
767 version = version.replace('_','AND') | 785 version = version.replace('_','AND') |
768 tags = DromaeoTester.GetValidDromaeoTags() | 786 tags = DromaeoTester.GetValidDromaeoTags() |
769 return 'OR'.join([ '%sAND%s' % (version, tag) for tag in tags]) | 787 return 'OR'.join([ '%sAND%s' % (version, tag) for tag in tags]) |
770 | 788 |
771 | 789 |
772 class DromaeoFileProcessor(Processor): | 790 class DromaeoFileProcessor(Processor): |
773 def ProcessFile(self, afile, should_post_file): | 791 def ProcessFile(self, afile, should_post_file): |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 upload_success = upload_success and self.ReportResults( | 828 upload_success = upload_success and self.ReportResults( |
811 name, score, browser, version, revision_num, | 829 name, score, browser, version, revision_num, |
812 self.GetScoreType(name)) | 830 self.GetScoreType(name)) |
813 else: | 831 else: |
814 upload_success = False | 832 upload_success = False |
815 | 833 |
816 f.close() | 834 f.close() |
817 self.CalculateGeometricMean(browser, version, revision_num) | 835 self.CalculateGeometricMean(browser, version, revision_num) |
818 return upload_success | 836 return upload_success |
819 | 837 |
| 838 class TodoMVCTester(BrowserTester): |
| 839 @staticmethod |
| 840 def GetVersions(): |
| 841 return ['js', 'dart2js_html', 'dart_html'] |
| 842 |
| 843 @staticmethod |
| 844 def GetBenchmarks(): |
| 845 return ['TodoMVCstartup'] |
| 846 |
| 847 class TodoMVCStartupTest(RuntimePerformanceTest): |
| 848 """Start up TodoMVC and see how long it takes to start.""" |
| 849 def __init__(self, test_runner): |
| 850 super(TodoMVCStartupTest, self).__init__( |
| 851 self.Name(), |
| 852 BrowserTester.GetBrowsers(True), |
| 853 'browser', |
| 854 TodoMVCTester.GetVersions(), |
| 855 TodoMVCTester.GetBenchmarks(), test_runner, |
| 856 self.TodoMVCStartupTester(self), |
| 857 self.TodoMVCFileProcessor(self)) |
| 858 |
| 859 @staticmethod |
| 860 def Name(): |
| 861 return 'todoMvcStartup' |
| 862 |
| 863 class TodoMVCStartupTester(BrowserTester): |
| 864 def RunTests(self): |
| 865 """Run dromaeo in the browser.""" |
| 866 success, _, _ = self.test.test_runner.GetArchive('dartium') |
| 867 if not success: |
| 868 # Unable to download dartium. Try later. |
| 869 return |
| 870 |
| 871 dromaeo_path = os.path.join('samples', 'third_party', 'dromaeo') |
| 872 current_path = os.getcwd() |
| 873 |
| 874 os.chdir(os.path.join(DART_REPO_LOC, 'samples', 'third_party', |
| 875 'todomvc_performance')) |
| 876 self.test.test_runner.RunCmd([os.path.join(DART_REPO_LOC, |
| 877 utils.GetBuildRoot(utils.GuessOS(), 'release', 'ia32'), |
| 878 'dart-sdk', 'bin', 'pub'), 'build', '--mode=debug']) |
| 879 os.chdir('js_todomvc'); |
| 880 self.test.test_runner.RunCmd([os.path.join(DART_REPO_LOC, |
| 881 utils.GetBuildRoot(utils.GuessOS(), 'release', 'ia32'), |
| 882 'dart-sdk', 'bin', 'pub'), 'get']) |
| 883 |
| 884 versions = TodoMVCTester.GetVersions() |
| 885 |
| 886 for browser in BrowserTester.GetBrowsers(): |
| 887 for version_name in versions: |
| 888 if not self.test.IsValidCombination(browser, version_name): |
| 889 continue |
| 890 self.test.trace_file = os.path.join(TOP_LEVEL_DIR, |
| 891 'tools', 'testing', 'perf_testing', self.test.result_folder_name, |
| 892 'todoMvcStartup-%s-%s-%s' % (self.test.cur_time, browser, |
| 893 version_name)) |
| 894 self.AddSvnRevisionToTrace(self.test.trace_file, browser) |
| 895 |
| 896 if version_name == 'js': |
| 897 code_root = os.path.join(DART_REPO_LOC, 'samples', 'third_party', |
| 898 'todomvc_performance', 'js_todomvc') |
| 899 self.test.test_runner.RunBrowserPerfRunnerCmd(browser, |
| 900 '/code_root/index.html', code_root, self.test.trace_file, |
| 901 code_root) |
| 902 else: |
| 903 self.test.test_runner.RunBrowserPerfRunnerCmd(browser, |
| 904 '/code_root/build/web/startup-performance.html', os.path.join( |
| 905 DART_REPO_LOC, 'samples', 'third_party', 'todomvc_performance'), |
| 906 self.test.trace_file) |
| 907 |
| 908 class TodoMVCFileProcessor(Processor): |
| 909 def ProcessFile(self, afile, should_post_file): |
| 910 """Comb through the html to find the performance results. |
| 911 Returns: True if we successfully posted our data to storage.""" |
| 912 parts = afile.split('-') |
| 913 browser = parts[2] |
| 914 version = parts[3] |
| 915 |
| 916 bench_dict = self.test.values_dict[browser][version] |
| 917 |
| 918 f = self.OpenTraceFile(afile, should_post_file) |
| 919 lines = f.readlines() |
| 920 i = 0 |
| 921 revision_num = 0 |
| 922 revision_pattern = r'Revision: (\d+)' |
| 923 result_pattern = r'The startup time is (\d+)' |
| 924 |
| 925 upload_success = True |
| 926 for line in lines: |
| 927 rev = re.match(revision_pattern, line.strip().replace('"', '')) |
| 928 if rev: |
| 929 revision_num = int(rev.group(1)) |
| 930 continue |
| 931 |
| 932 results = re.search(result_pattern, line) |
| 933 if results: |
| 934 score = float(results.group(1)) |
| 935 name = TodoMVCTester.GetBenchmarks()[0] |
| 936 bench_dict[name] += [float(score)] |
| 937 self.test.revision_dict[browser][version][name] += \ |
| 938 [revision_num] |
| 939 if not self.test.test_runner.no_upload and should_post_file: |
| 940 upload_success = upload_success and self.ReportResults( |
| 941 name, score, browser, version, revision_num, |
| 942 self.GetScoreType(name)) |
| 943 |
| 944 f.close() |
| 945 self.CalculateGeometricMean(browser, version, revision_num) |
| 946 return upload_success |
| 947 |
| 948 |
820 class TestBuilder(object): | 949 class TestBuilder(object): |
821 """Construct the desired test object.""" | 950 """Construct the desired test object.""" |
822 available_suites = dict((suite.Name(), suite) for suite in [ | 951 available_suites = dict((suite.Name(), suite) for suite in [ |
823 DromaeoTest]) | 952 DromaeoTest, TodoMVCStartupTest]) |
824 | 953 |
825 @staticmethod | 954 @staticmethod |
826 def MakeTest(test_name, test_runner): | 955 def MakeTest(test_name, test_runner): |
827 return TestBuilder.available_suites[test_name](test_runner) | 956 return TestBuilder.available_suites[test_name](test_runner) |
828 | 957 |
829 @staticmethod | 958 @staticmethod |
830 def AvailableSuiteNames(): | 959 def AvailableSuiteNames(): |
831 return TestBuilder.available_suites.keys() | 960 return TestBuilder.available_suites.keys() |
832 | 961 |
833 | 962 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 else: | 1078 else: |
950 if runner.backfill: | 1079 if runner.backfill: |
951 results_set = FillInBackHistory(results_set, runner) | 1080 results_set = FillInBackHistory(results_set, runner) |
952 else: | 1081 else: |
953 time.sleep(200) | 1082 time.sleep(200) |
954 else: | 1083 else: |
955 runner.RunTestSequence() | 1084 runner.RunTestSequence() |
956 | 1085 |
957 if __name__ == '__main__': | 1086 if __name__ == '__main__': |
958 main() | 1087 main() |
OLD | NEW |