Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: client/cmd/isolate/exp_archive.go

Issue 2985203002: isolate: Move json dumping back into exparchive main (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | client/cmd/isolate/upload_tracker.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. 1 // Copyright 2015 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 package main 15 package main
16 16
17 import ( 17 import (
18 "encoding/json"
18 "errors" 19 "errors"
19 "fmt" 20 "fmt"
20 "io" 21 "io"
21 "io/ioutil"
22 "log" 22 "log"
23 "os" 23 "os"
24 "path/filepath" 24 "path/filepath"
25 "time" 25 "time"
26 26
27 humanize "github.com/dustin/go-humanize" 27 humanize "github.com/dustin/go-humanize"
28 "github.com/golang/protobuf/proto" 28 "github.com/golang/protobuf/proto"
29 "github.com/maruel/subcommands" 29 "github.com/maruel/subcommands"
30 "golang.org/x/net/context" 30 "golang.org/x/net/context"
31 31
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 numFiles := len(parts.filesToArchive.items) + len(parts.indivFiles.items ) 208 numFiles := len(parts.filesToArchive.items) + len(parts.indivFiles.items )
209 filesSize := uint64(parts.filesToArchive.totalSize + parts.indivFiles.to talSize) 209 filesSize := uint64(parts.filesToArchive.totalSize + parts.indivFiles.to talSize)
210 log.Printf("Isolate expanded to %d files (total size %s) and %d symlinks ", numFiles, humanize.Bytes(filesSize), len(parts.links.items)) 210 log.Printf("Isolate expanded to %d files (total size %s) and %d symlinks ", numFiles, humanize.Bytes(filesSize), len(parts.links.items))
211 log.Printf("\t%d files (%s) to be isolated individually", len(parts.indi vFiles.items), humanize.Bytes(uint64(parts.indivFiles.totalSize))) 211 log.Printf("\t%d files (%s) to be isolated individually", len(parts.indi vFiles.items), humanize.Bytes(uint64(parts.indivFiles.totalSize)))
212 log.Printf("\t%d files (%s) to be isolated in archives", len(parts.files ToArchive.items), humanize.Bytes(uint64(parts.filesToArchive.totalSize))) 212 log.Printf("\t%d files (%s) to be isolated in archives", len(parts.files ToArchive.items), humanize.Bytes(uint64(parts.filesToArchive.totalSize)))
213 213
214 tracker := NewUploadTracker(checker, uploader, isol) 214 tracker := NewUploadTracker(checker, uploader, isol)
215 if err := tracker.UploadDeps(parts); err != nil { 215 if err := tracker.UploadDeps(parts); err != nil {
216 return err 216 return err
217 } 217 }
218 isolSummary, err := tracker.Finalize(archiveOpts.Isolated)
219 if err != nil {
220 return err
221 }
218 222
219 » var dumpJSONWriter io.Writer = ioutil.Discard 223 » printSummary(isolSummary)
220
221 if c.dumpJSON != "" { 224 if c.dumpJSON != "" {
222 f, err := os.OpenFile(c.dumpJSON, os.O_RDWR|os.O_CREATE|os.O_TRU NC, 0644) 225 f, err := os.OpenFile(c.dumpJSON, os.O_RDWR|os.O_CREATE|os.O_TRU NC, 0644)
223 if err != nil { 226 if err != nil {
224 return err 227 return err
225 } 228 }
226 » » defer f.Close() 229 » » writeSummaryJSON(f, isolSummary)
227 » » dumpJSONWriter = f 230 » » f.Close()
228 » }
229
230 » isolDigest, err := tracker.Finalize(archiveOpts.Isolated, dumpJSONWriter )
231 » if err != nil {
232 » » return err
233 } 231 }
234 232
235 end := time.Now() 233 end := time.Now()
236 234
237 archiveDetails := &logpb.IsolateClientEvent_ArchiveDetails{ 235 archiveDetails := &logpb.IsolateClientEvent_ArchiveDetails{
238 HitCount: proto.Int64(int64(checker.Hit.Count)), 236 HitCount: proto.Int64(int64(checker.Hit.Count)),
239 MissCount: proto.Int64(int64(checker.Miss.Count)), 237 MissCount: proto.Int64(int64(checker.Miss.Count)),
240 HitBytes: &checker.Hit.Bytes, 238 HitBytes: &checker.Hit.Bytes,
241 MissBytes: &checker.Miss.Bytes, 239 MissBytes: &checker.Miss.Bytes,
242 » » IsolateHash: []string{string(isolDigest)}, 240 » » IsolateHash: []string{string(isolSummary.Digest)},
243 } 241 }
244 eventlogger := NewLogger(ctx, c.loggingFlags.EventlogEndpoint) 242 eventlogger := NewLogger(ctx, c.loggingFlags.EventlogEndpoint)
245 op := logpb.IsolateClientEvent_ARCHIVE.Enum() 243 op := logpb.IsolateClientEvent_ARCHIVE.Enum()
246 if err := eventlogger.logStats(ctx, op, start, end, archiveDetails); err != nil { 244 if err := eventlogger.logStats(ctx, op, start, end, archiveDetails); err != nil {
247 log.Printf("Failed to log to eventlog: %v", err) 245 log.Printf("Failed to log to eventlog: %v", err)
248 } 246 }
249 247
250 return nil 248 return nil
251 } 249 }
252 250
251 func writeSummaryJSON(w io.Writer, summaries ...IsolatedSummary) error {
252 m := make(map[string]isolated.HexDigest)
253 for _, summary := range summaries {
254 m[summary.Name] = summary.Digest
255 }
256
257 return json.NewEncoder(w).Encode(m)
258 }
259
260 func printSummary(summary IsolatedSummary) {
261 fmt.Printf("%s\t%s\n", summary.Digest, summary.Name)
262 }
263
253 func (c *expArchiveRun) parseFlags(args []string) error { 264 func (c *expArchiveRun) parseFlags(args []string) error {
254 if len(args) != 0 { 265 if len(args) != 0 {
255 return errors.New("position arguments not expected") 266 return errors.New("position arguments not expected")
256 } 267 }
257 if err := c.commonServerFlags.Parse(); err != nil { 268 if err := c.commonServerFlags.Parse(); err != nil {
258 return err 269 return err
259 } 270 }
260 cwd, err := os.Getwd() 271 cwd, err := os.Getwd()
261 if err != nil { 272 if err != nil {
262 return err 273 return err
(...skipping 18 matching lines...) Expand all
281 } 292 }
282 293
283 func hashFile(path string) (isolated.HexDigest, error) { 294 func hashFile(path string) (isolated.HexDigest, error) {
284 f, err := os.Open(path) 295 f, err := os.Open(path)
285 if err != nil { 296 if err != nil {
286 return "", err 297 return "", err
287 } 298 }
288 defer f.Close() 299 defer f.Close()
289 return isolated.Hash(f) 300 return isolated.Hash(f)
290 } 301 }
OLDNEW
« no previous file with comments | « no previous file | client/cmd/isolate/upload_tracker.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698