| OLD | NEW |
| 1 // capture_skps_on_workers is an application that captures SKPs of the | 1 // capture_skps_on_workers is an application that captures SKPs of the |
| 2 // specified patchset type on all CT workers and uploads the results to Google | 2 // specified patchset type on all CT workers and uploads the results to Google |
| 3 // Storage. The requester is emailed when the task is done. | 3 // Storage. The requester is emailed when the task is done. |
| 4 package main | 4 package main |
| 5 | 5 |
| 6 import ( | 6 import ( |
| 7 "bytes" | |
| 8 "flag" | 7 "flag" |
| 9 "fmt" | 8 "fmt" |
| 9 "path/filepath" |
| 10 "strings" | 10 "strings" |
| 11 "text/template" | |
| 12 "time" | 11 "time" |
| 13 | 12 |
| 14 "github.com/skia-dev/glog" | 13 "github.com/skia-dev/glog" |
| 15 "go.skia.org/infra/ct/go/ctfe/capture_skps" | 14 "go.skia.org/infra/ct/go/ctfe/capture_skps" |
| 16 "go.skia.org/infra/ct/go/frontend" | 15 "go.skia.org/infra/ct/go/frontend" |
| 17 "go.skia.org/infra/ct/go/master_scripts/master_common" | 16 "go.skia.org/infra/ct/go/master_scripts/master_common" |
| 18 "go.skia.org/infra/ct/go/util" | 17 "go.skia.org/infra/ct/go/util" |
| 19 "go.skia.org/infra/go/common" | 18 "go.skia.org/infra/go/common" |
| 20 skutil "go.skia.org/infra/go/util" | 19 skutil "go.skia.org/infra/go/util" |
| 21 ) | 20 ) |
| 22 | 21 |
| 22 const ( |
| 23 MAX_PAGES_PER_SWARMING_BOT_CAPTURE_SKPS = 100 |
| 24 MAX_PAGES_PER_SWARMING_BOT_CAPTURE_SKPS_FROM_PDFS = 1000 |
| 25 ) |
| 26 |
| 23 var ( | 27 var ( |
| 24 emails = flag.String("emails", "", "The comma separated email ad
dresses to notify when the task is picked up and completes.") | 28 emails = flag.String("emails", "", "The comma separated email ad
dresses to notify when the task is picked up and completes.") |
| 25 description = flag.String("description", "", "The description of the
run as entered by the requester.") | 29 description = flag.String("description", "", "The description of the
run as entered by the requester.") |
| 26 gaeTaskID = flag.Int64("gae_task_id", -1, "The key of the App Engin
e task. This task will be updated when the task is completed.") | 30 gaeTaskID = flag.Int64("gae_task_id", -1, "The key of the App Engin
e task. This task will be updated when the task is completed.") |
| 27 pagesetType = flag.String("pageset_type", "", "The type of pagesets t
o use. Eg: 10k, Mobile10k, All.") | 31 pagesetType = flag.String("pageset_type", "", "The type of pagesets t
o use. Eg: 10k, Mobile10k, All.") |
| 28 chromiumBuild = flag.String("chromium_build", "", "The chromium build t
o use for this capture SKPs run.") | 32 chromiumBuild = flag.String("chromium_build", "", "The chromium build t
o use for this capture SKPs run.") |
| 29 targetPlatform = flag.String("target_platform", util.PLATFORM_LINUX, "Th
e platform the benchmark will run on (Android / Linux).") | 33 targetPlatform = flag.String("target_platform", util.PLATFORM_LINUX, "Th
e platform the benchmark will run on (Android / Linux).") |
| 30 runID = flag.String("run_id", "", "The unique run id (typically
requester + timestamp).") | 34 runID = flag.String("run_id", "", "The unique run id (typically
requester + timestamp).") |
| 31 | 35 |
| 32 taskCompletedSuccessfully = false | 36 taskCompletedSuccessfully = false |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 glog.Error("At least one email address must be specified") | 76 glog.Error("At least one email address must be specified") |
| 73 return | 77 return |
| 74 } | 78 } |
| 75 skutil.LogErr(frontend.UpdateWebappTaskSetStarted(&capture_skps.UpdateVa
rs{}, *gaeTaskID)) | 79 skutil.LogErr(frontend.UpdateWebappTaskSetStarted(&capture_skps.UpdateVa
rs{}, *gaeTaskID)) |
| 76 skutil.LogErr(util.SendTaskStartEmail(emailsArr, "Capture SKPs", *runID,
*description)) | 80 skutil.LogErr(util.SendTaskStartEmail(emailsArr, "Capture SKPs", *runID,
*description)) |
| 77 // Ensure webapp is updated and completion email is sent even if task | 81 // Ensure webapp is updated and completion email is sent even if task |
| 78 // fails. | 82 // fails. |
| 79 defer updateWebappTask() | 83 defer updateWebappTask() |
| 80 defer sendEmail(emailsArr) | 84 defer sendEmail(emailsArr) |
| 81 | 85 |
| 82 if !*master_common.Local { | |
| 83 // Cleanup tmp files after the run. | |
| 84 defer util.CleanTmpDir() | |
| 85 } | |
| 86 // Finish with glog flush and how long the task took. | 86 // Finish with glog flush and how long the task took. |
| 87 defer util.TimeTrack(time.Now(), "Running capture skps task on workers") | 87 defer util.TimeTrack(time.Now(), "Running capture skps task on workers") |
| 88 defer glog.Flush() | 88 defer glog.Flush() |
| 89 | 89 |
| 90 if *pagesetType == "" { | 90 if *pagesetType == "" { |
| 91 glog.Error("Must specify --pageset_type") | 91 glog.Error("Must specify --pageset_type") |
| 92 return | 92 return |
| 93 } | 93 } |
| 94 if *chromiumBuild == "" { | 94 if *chromiumBuild == "" { |
| 95 glog.Error("Must specify --chromium_build") | 95 glog.Error("Must specify --chromium_build") |
| 96 return | 96 return |
| 97 } | 97 } |
| 98 if *runID == "" { | 98 if *runID == "" { |
| 99 glog.Error("Must specify --run_id") | 99 glog.Error("Must specify --run_id") |
| 100 return | 100 return |
| 101 } | 101 } |
| 102 | 102 |
| 103 » workerScript := "capture_skps" | 103 » isolateFile := util.CAPTURE_SKPS_ISOLATE |
| 104 » maxPages := MAX_PAGES_PER_SWARMING_BOT_CAPTURE_SKPS |
| 104 if strings.Contains(strings.ToUpper(*pagesetType), "PDF") { | 105 if strings.Contains(strings.ToUpper(*pagesetType), "PDF") { |
| 105 // For PDF pagesets use the capture_skps_from_pdfs worker script
. | 106 // For PDF pagesets use the capture_skps_from_pdfs worker script
. |
| 106 » » workerScript = "capture_skps_from_pdfs" | 107 » » isolateFile = util.CAPTURE_SKPS_FROM_PDFS_ISOLATE |
| 108 » » maxPages = MAX_PAGES_PER_SWARMING_BOT_CAPTURE_SKPS_FROM_PDFS |
| 107 // TODO(rmistry): Uncomment when ready to capture SKPs. | 109 // TODO(rmistry): Uncomment when ready to capture SKPs. |
| 108 //// Sync PDFium and build pdfium_test binary which will be used
by the worker script. | 110 //// Sync PDFium and build pdfium_test binary which will be used
by the worker script. |
| 109 //if err := util.SyncDir(util.PDFiumTreeDir); err != nil { | 111 //if err := util.SyncDir(util.PDFiumTreeDir); err != nil { |
| 110 // glog.Errorf("Could not sync PDFium: %s", err) | 112 // glog.Errorf("Could not sync PDFium: %s", err) |
| 111 // return | 113 // return |
| 112 //} | 114 //} |
| 113 //if err := util.BuildPDFium(); err != nil { | 115 //if err := util.BuildPDFium(); err != nil { |
| 114 // glog.Errorf("Could not build PDFium: %s", err) | 116 // glog.Errorf("Could not build PDFium: %s", err) |
| 115 // return | 117 // return |
| 116 //} | 118 //} |
| 117 //// Copy pdfium_test to Google Storage. | 119 //// Copy pdfium_test to Google Storage. |
| 118 //pdfiumLocalDir := path.Join(util.PDFiumTreeDir, "out", "Debug"
) | 120 //pdfiumLocalDir := path.Join(util.PDFiumTreeDir, "out", "Debug"
) |
| 119 //pdfiumRemoteDir := path.Join(util.BINARIES_DIR_NAME, *chromium
Build) | 121 //pdfiumRemoteDir := path.Join(util.BINARIES_DIR_NAME, *chromium
Build) |
| 120 //// Instantiate GsUtil object. | 122 //// Instantiate GsUtil object. |
| 121 //gs, err := util.NewGsUtil(nil) | 123 //gs, err := util.NewGsUtil(nil) |
| 122 //if err != nil { | 124 //if err != nil { |
| 123 // glog.Error(err) | 125 // glog.Error(err) |
| 124 // return | 126 // return |
| 125 //} | 127 //} |
| 126 //if err := gs.UploadFile(util.BINARY_PDFIUM_TEST, pdfiumLocalDi
r, pdfiumRemoteDir); err != nil { | 128 //if err := gs.UploadFile(util.BINARY_PDFIUM_TEST, pdfiumLocalDi
r, pdfiumRemoteDir); err != nil { |
| 127 // glog.Errorf("Could not upload %s to %s: %s", util.BINARY
_PDFIUM_TEST, pdfiumRemoteDir, err) | 129 // glog.Errorf("Could not upload %s to %s: %s", util.BINARY
_PDFIUM_TEST, pdfiumRemoteDir, err) |
| 128 // return | 130 // return |
| 129 //} | 131 //} |
| 130 } | 132 } |
| 131 | 133 |
| 132 » // Run the capture SKPs script on all workers. | 134 » // Empty the remote dir before the workers upload to it. |
| 133 » captureSKPsCmdTemplate := "DISPLAY=:0 {{.WorkerScript}} --worker_num={{.
WorkerNum}} --log_dir={{.LogDir}} --log_id={{.RunID}} " + | 135 » gs, err := util.NewGsUtil(nil) |
| 134 » » "--pageset_type={{.PagesetType}} --chromium_build={{.ChromiumBui
ld}} --run_id={{.RunID}} " + | 136 » if err != nil { |
| 135 » » "--target_platform={{.TargetPlatform}} --local={{.Local}};" | 137 » » glog.Error(err) |
| 136 » captureSKPsTemplateParsed := template.Must(template.New("capture_skps_cm
d").Parse(captureSKPsCmdTemplate)) | 138 » » return |
| 137 » captureSKPsCmdBytes := new(bytes.Buffer) | 139 » } |
| 138 » if err := captureSKPsTemplateParsed.Execute(captureSKPsCmdBytes, struct
{ | 140 » skpGSBaseDir := filepath.Join(util.SWARMING_DIR_NAME, util.SKPS_DIR_NAME
, *pagesetType) |
| 139 » » WorkerScript string | 141 » skutil.LogErr(gs.DeleteRemoteDir(skpGSBaseDir)) |
| 140 » » WorkerNum string | 142 » if strings.Contains(strings.ToUpper(*pagesetType), "PDF") { |
| 141 » » LogDir string | 143 » » pdfGSBaseDir := filepath.Join(util.SWARMING_DIR_NAME, util.PDFS_
DIR_NAME, *pagesetType) |
| 142 » » PagesetType string | 144 » » skutil.LogErr(gs.DeleteRemoteDir(pdfGSBaseDir)) |
| 143 » » ChromiumBuild string | 145 » } |
| 144 » » RunID string | 146 |
| 145 » » TargetPlatform string | 147 » // Archive, trigger and collect swarming tasks. |
| 146 » » Local bool | 148 » isolateExtraArgs := map[string]string{ |
| 147 » }{ | 149 » » "CHROMIUM_BUILD": *chromiumBuild, |
| 148 » » WorkerScript: workerScript, | 150 » » "RUN_ID": *runID, |
| 149 » » WorkerNum: util.WORKER_NUM_KEYWORD, | 151 » } |
| 150 » » LogDir: util.GLogDir, | 152 » if err := util.TriggerSwarmingTask(*pagesetType, "capture_skps", isolate
File, 2*time.Hour, 1*time.Hour, maxPages, isolateExtraArgs); err != nil { |
| 151 » » PagesetType: *pagesetType, | 153 » » glog.Errorf("Error encountered when swarming tasks: %s", err) |
| 152 » » ChromiumBuild: *chromiumBuild, | |
| 153 » » RunID: *runID, | |
| 154 » » TargetPlatform: *targetPlatform, | |
| 155 » » Local: *master_common.Local, | |
| 156 » }); err != nil { | |
| 157 » » glog.Errorf("Failed to execute template: %s", err) | |
| 158 return | 154 return |
| 159 } | 155 } |
| 160 | 156 |
| 161 cmd := append(master_common.WorkerSetupCmds(), | |
| 162 // The main command that captures SKPs on all workers. | |
| 163 captureSKPsCmdBytes.String()) | |
| 164 _, err := util.SSH(strings.Join(cmd, " "), util.Slaves, util.CAPTURE_SKP
S_TIMEOUT) | |
| 165 if err != nil { | |
| 166 glog.Errorf("Error while running cmd %s: %s", cmd, err) | |
| 167 return | |
| 168 } | |
| 169 | |
| 170 taskCompletedSuccessfully = true | 157 taskCompletedSuccessfully = true |
| 171 } | 158 } |
| OLD | NEW |