Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // run_chromium_perf is an application that runs the specified benchmark over CT 's | 1 // run_chromium_perf is an application that runs the specified benchmark over CT 's |
| 2 // webpage archives. | 2 // webpage archives. |
| 3 package main | 3 package main |
| 4 | 4 |
| 5 import ( | 5 import ( |
| 6 "encoding/csv" | 6 "encoding/csv" |
| 7 "flag" | 7 "flag" |
| 8 "fmt" | 8 "fmt" |
| 9 "io" | |
| 9 "io/ioutil" | 10 "io/ioutil" |
| 10 "os" | 11 "os" |
| 11 "path/filepath" | 12 "path/filepath" |
| 12 "runtime" | 13 "runtime" |
| 13 "sync" | 14 "sync" |
| 14 "time" | 15 "time" |
| 15 | 16 |
| 16 "github.com/skia-dev/glog" | 17 "github.com/skia-dev/glog" |
| 17 | 18 |
| 18 "strings" | 19 "strings" |
| 19 | 20 |
| 20 "go.skia.org/infra/ct/go/adb" | 21 "go.skia.org/infra/ct/go/adb" |
| 21 "go.skia.org/infra/ct/go/util" | 22 "go.skia.org/infra/ct/go/util" |
| 22 "go.skia.org/infra/ct/go/worker_scripts/worker_common" | 23 "go.skia.org/infra/ct/go/worker_scripts/worker_common" |
| 23 "go.skia.org/infra/go/common" | 24 "go.skia.org/infra/go/common" |
| 24 skutil "go.skia.org/infra/go/util" | 25 skutil "go.skia.org/infra/go/util" |
| 25 ) | 26 ) |
| 26 | 27 |
| 27 const ( | 28 const ( |
| 28 // The number of goroutines that will run in parallel to run benchmarks. | 29 // The number of goroutines that will run in parallel to run benchmarks. |
| 29 WORKER_POOL_SIZE = 10 | 30 WORKER_POOL_SIZE = 10 |
| 30 ) | 31 ) |
| 31 | 32 |
| 32 var ( | 33 var ( |
| 33 workerNum = flag.Int("worker_num", 1, "The number of thi s CT worker. It will be in the {1..100} range.") | 34 workerNum = flag.Int("worker_num", 1, "The number of thi s CT worker. It will be in the {1..100} range.") |
| 34 pagesetType = flag.String("pageset_type", util.PAGESET_TYP E_MOBILE_10k, "The type of pagesets to create from the Alexa CSV list. Eg: 10k, Mobile10k, All.") | 35 pagesetType = flag.String("pageset_type", util.PAGESET_TYP E_MOBILE_10k, "The type of pagesets to create from the Alexa CSV list. Eg: 10k, Mobile10k, All.") |
| 35 chromiumBuildNoPatch = flag.String("chromium_build_nopatch", "", "T he chromium build to use for the nopatch run.") | 36 chromiumBuildNoPatch = flag.String("chromium_build_nopatch", "", "T he chromium build to use for the nopatch run.") |
| 36 chromiumBuildWithPatch = flag.String("chromium_build_withpatch", "", "The chromium build to use for the withpatch run.") | 37 chromiumBuildWithPatch = flag.String("chromium_build_withpatch", "", "The chromium build to use for the withpatch run.") |
| 38 runID = flag.String("run_id", "", "The unique run id (typically requester + timestamp).") | |
| 37 runIDNoPatch = flag.String("run_id_nopatch", "", "The uniqu e run id (typically requester + timestamp) for the nopatch run.") | 39 runIDNoPatch = flag.String("run_id_nopatch", "", "The uniqu e run id (typically requester + timestamp) for the nopatch run.") |
| 38 runIDWithPatch = flag.String("run_id_withpatch", "", "The uni que run id (typically requester + timestamp) for the withpatch run.") | 40 runIDWithPatch = flag.String("run_id_withpatch", "", "The uni que run id (typically requester + timestamp) for the withpatch run.") |
| 39 benchmarkName = flag.String("benchmark_name", "", "The telem etry benchmark to run on this worker.") | 41 benchmarkName = flag.String("benchmark_name", "", "The telem etry benchmark to run on this worker.") |
| 40 benchmarkExtraArgs = flag.String("benchmark_extra_args", "", "The extra arguments that are passed to the specified benchmark.") | 42 benchmarkExtraArgs = flag.String("benchmark_extra_args", "", "The extra arguments that are passed to the specified benchmark.") |
| 41 browserExtraArgsNoPatch = flag.String("browser_extra_args_nopatch", "" , "The extra arguments that are passed to the browser while running the benchmar k during the nopatch run.") | 43 browserExtraArgsNoPatch = flag.String("browser_extra_args_nopatch", "" , "The extra arguments that are passed to the browser while running the benchmar k during the nopatch run.") |
| 42 browserExtraArgsWithPatch = flag.String("browser_extra_args_withpatch", "", "The extra arguments that are passed to the browser while running the benchm ark during the withpatch run.") | 44 browserExtraArgsWithPatch = flag.String("browser_extra_args_withpatch", "", "The extra arguments that are passed to the browser while running the benchm ark during the withpatch run.") |
| 43 repeatBenchmark = flag.Int("repeat_benchmark", 3, "The number of times the benchmark should be repeated. For skpicture_printer benchmark this value is always 1.") | 45 repeatBenchmark = flag.Int("repeat_benchmark", 3, "The number of times the benchmark should be repeated. For skpicture_printer benchmark this value is always 1.") |
| 44 runInParallel = flag.Bool("run_in_parallel", false, "Run the benchmark by bringing up multiple chrome instances in parallel.") | 46 runInParallel = flag.Bool("run_in_parallel", false, "Run the benchmark by bringing up multiple chrome instances in parallel.") |
| 45 targetPlatform = flag.String("target_platform", util.PLATFORM _ANDROID, "The platform the benchmark will run on (Android / Linux).") | 47 targetPlatform = flag.String("target_platform", util.PLATFORM _ANDROID, "The platform the benchmark will run on (Android / Linux).") |
| 46 chromeCleanerTimer = flag.Duration("cleaner_timer", 15*time.Minut e, "How often all chrome processes will be killed on this slave.") | 48 chromeCleanerTimer = flag.Duration("cleaner_timer", 15*time.Minut e, "How often all chrome processes will be killed on this slave.") |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 util.ADB_ROOT_TIMEOUT, nil, nil)) | 108 util.ADB_ROOT_TIMEOUT, nil, nil)) |
| 107 } | 109 } |
| 108 | 110 |
| 109 // Instantiate GsUtil object. | 111 // Instantiate GsUtil object. |
| 110 gs, err := util.NewGsUtil(nil) | 112 gs, err := util.NewGsUtil(nil) |
| 111 if err != nil { | 113 if err != nil { |
| 112 glog.Error(err) | 114 glog.Error(err) |
| 113 return | 115 return |
| 114 } | 116 } |
| 115 | 117 |
| 118 // Download the benchmark patch for this run from Google storage. | |
| 119 benchmarkPatchName := *runID + ".benchmark.patch" | |
| 120 benchmarkPatchLocalPath := filepath.Join(os.TempDir(), benchmarkPatchNam e) | |
| 121 remoteDir := filepath.Join(util.ChromiumPerfRunsDir, *runID) | |
| 122 benchmarkPatchRemotePath := filepath.Join(remoteDir, benchmarkPatchName) | |
| 123 respBody, err := gs.GetRemoteFileContents(benchmarkPatchRemotePath) | |
| 124 if err != nil { | |
| 125 glog.Errorf("Could not fetch %s: %s", benchmarkPatchRemotePath, err) | |
| 126 return | |
| 127 } | |
| 128 defer skutil.Close(respBody) | |
| 129 out, err := os.Create(benchmarkPatchLocalPath) | |
|
dogben
2015/10/20 15:17:26
Seems like you could use os.WriteFile. https://gol
rmistry
2015/10/20 17:47:48
Done.
| |
| 130 if err != nil { | |
| 131 glog.Errorf("Unable to create file %s: %s", benchmarkPatchLocalP ath, err) | |
| 132 return | |
| 133 } | |
| 134 defer skutil.Close(out) | |
| 135 defer skutil.Remove(benchmarkPatchLocalPath) | |
| 136 if _, err = io.Copy(out, respBody); err != nil { | |
| 137 glog.Error(err) | |
| 138 return | |
| 139 } | |
| 140 // Apply benchmark patch to the local chromium checkout. | |
| 141 benchmarkPatchFile, _ := os.Open(benchmarkPatchLocalPath) | |
|
dogben
2015/10/20 15:17:26
Use os.Stat. https://golang.org/pkg/os/#Stat
(Or d
rmistry
2015/10/20 17:47:48
Done.
dogben
2015/10/20 18:14:08
Nit: You actually have the size from buf above, so
rmistry
2015/10/21 12:32:47
Done.
| |
| 142 benchmarkPatchFileInfo, _ := benchmarkPatchFile.Stat() | |
| 143 if benchmarkPatchFileInfo.Size() > 10 { | |
| 144 if err := util.ApplyPatch(benchmarkPatchLocalPath, util.Chromium SrcDir); err != nil { | |
| 145 glog.Errorf("Could not apply Telemetry's patch in %s: %s ", util.ChromiumSrcDir, err) | |
| 146 return | |
| 147 } | |
| 148 } | |
| 149 | |
| 116 // Download the specified chromium builds. | 150 // Download the specified chromium builds. |
| 117 for _, chromiumBuild := range []string{*chromiumBuildNoPatch, *chromiumB uildWithPatch} { | 151 for _, chromiumBuild := range []string{*chromiumBuildNoPatch, *chromiumB uildWithPatch} { |
| 118 if err := gs.DownloadChromiumBuild(chromiumBuild); err != nil { | 152 if err := gs.DownloadChromiumBuild(chromiumBuild); err != nil { |
| 119 glog.Error(err) | 153 glog.Error(err) |
| 120 return | 154 return |
| 121 } | 155 } |
| 122 //Delete the chromium build to save space when we are done. | 156 //Delete the chromium build to save space when we are done. |
| 123 defer skutil.RemoveAll(filepath.Join(util.ChromiumBuildsDir, chr omiumBuild)) | 157 defer skutil.RemoveAll(filepath.Join(util.ChromiumBuildsDir, chr omiumBuild)) |
| 124 } | 158 } |
| 125 | 159 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 | 280 |
| 247 // Read the pageset. | 281 // Read the pageset. |
| 248 pagesetName := strings.TrimSuffix(pagesetBaseName, filepath.Ext(pagesetB aseName)) | 282 pagesetName := strings.TrimSuffix(pagesetBaseName, filepath.Ext(pagesetB aseName)) |
| 249 pagesetPath := filepath.Join(pathToPagesets, fileInfoName) | 283 pagesetPath := filepath.Join(pathToPagesets, fileInfoName) |
| 250 decodedPageset, err := util.ReadPageset(pagesetPath) | 284 decodedPageset, err := util.ReadPageset(pagesetPath) |
| 251 if err != nil { | 285 if err != nil { |
| 252 return fmt.Errorf("Could not read %s: %s", pagesetPath, err) | 286 return fmt.Errorf("Could not read %s: %s", pagesetPath, err) |
| 253 } | 287 } |
| 254 | 288 |
| 255 glog.Infof("===== Processing %s for %s =====", pagesetPath, runID) | 289 glog.Infof("===== Processing %s for %s =====", pagesetPath, runID) |
| 290 pagesetName, present := util.BenchmarksToPagesetName[*benchmarkName] | |
| 291 if !present { | |
| 292 // If it is custom benchmark use the entered benchmark name. | |
| 293 pagesetName = *benchmarkName | |
| 294 } | |
| 256 args := []string{ | 295 args := []string{ |
| 257 filepath.Join(util.TelemetryBinariesDir, util.BINARY_RUN_BENCHMA RK), | 296 filepath.Join(util.TelemetryBinariesDir, util.BINARY_RUN_BENCHMA RK), |
| 258 » » util.BenchmarksToPagesetName[*benchmarkName], | 297 » » pagesetName, |
| 259 "--also-run-disabled-tests", | 298 "--also-run-disabled-tests", |
| 260 "--user-agent=" + decodedPageset.UserAgent, | 299 "--user-agent=" + decodedPageset.UserAgent, |
| 261 "--urls-list=" + decodedPageset.UrlsList, | 300 "--urls-list=" + decodedPageset.UrlsList, |
| 262 "--archive-data-file=" + decodedPageset.ArchiveDataFile, | 301 "--archive-data-file=" + decodedPageset.ArchiveDataFile, |
| 263 } | 302 } |
| 264 | 303 |
| 265 // Need to capture output for all benchmarks. | 304 // Need to capture output for all benchmarks. |
| 266 outputDirArgValue := filepath.Join(localOutputDir, pagesetName) | 305 outputDirArgValue := filepath.Join(localOutputDir, pagesetName) |
| 267 args = append(args, "--output-dir="+outputDirArgValue) | 306 args = append(args, "--output-dir="+outputDirArgValue) |
| 268 // Figure out which browser should be used. | 307 // Figure out which browser should be used. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 return fmt.Errorf("Could not write to %s: %s", csvPath, err) | 424 return fmt.Errorf("Could not write to %s: %s", csvPath, err) |
| 386 } | 425 } |
| 387 // Write all values. | 426 // Write all values. |
| 388 for _, row := range values { | 427 for _, row := range values { |
| 389 if err := writer.Write(row); err != nil { | 428 if err := writer.Write(row); err != nil { |
| 390 return fmt.Errorf("Could not write to %s: %s", csvPath, err) | 429 return fmt.Errorf("Could not write to %s: %s", csvPath, err) |
| 391 } | 430 } |
| 392 } | 431 } |
| 393 return nil | 432 return nil |
| 394 } | 433 } |
| OLD | NEW |