github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/ui/tracer/microfactory.go (about) 1 // Copyright 2017 Google Inc. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (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 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tracer 16 17 import ( 18 "bufio" 19 "os" 20 "strconv" 21 "strings" 22 ) 23 24 func (t *tracerImpl) ImportMicrofactoryLog(filename string) { 25 if _, err := os.Stat(filename); err != nil { 26 return 27 } 28 29 f, err := os.Open(filename) 30 if err != nil { 31 t.log.Verboseln("Error opening microfactory trace:", err) 32 return 33 } 34 defer f.Close() 35 36 entries := []*eventEntry{} 37 begin := map[string][]uint64{} 38 s := bufio.NewScanner(f) 39 for s.Scan() { 40 fields := strings.SplitN(s.Text(), " ", 3) 41 if len(fields) != 3 { 42 t.log.Verboseln("Unknown line in microfactory trace:", s.Text()) 43 continue 44 } 45 timestamp, err := strconv.ParseUint(fields[0], 10, 64) 46 if err != nil { 47 t.log.Verboseln("Failed to parse timestamp in microfactory trace:", err) 48 } 49 50 if fields[1] == "B" { 51 begin[fields[2]] = append(begin[fields[2]], timestamp) 52 } else if beginTimestamps, ok := begin[fields[2]]; ok { 53 entries = append(entries, &eventEntry{ 54 Name: fields[2], 55 Begin: beginTimestamps[len(beginTimestamps)-1], 56 End: timestamp, 57 }) 58 begin[fields[2]] = beginTimestamps[:len(beginTimestamps)-1] 59 } 60 } 61 62 t.importEvents(entries) 63 }