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

Side by Side Diff: appengine/chromium_build_stats/gopath/src/ninjalog/ninjalog.go

Issue 561633002: chromium-build-stats: show ninja_log in table format (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: use 303 instead of 302 Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package ninjalog 5 package ninjalog
6 6
7 import ( 7 import (
8 "bufio" 8 "bufio"
9 "encoding/json" 9 "encoding/json"
10 "fmt" 10 "fmt"
11 "io" 11 "io"
12 "sort" 12 "sort"
13 "strconv" 13 "strconv"
14 "strings" 14 "strings"
15 "time" 15 "time"
16 ) 16 )
17 17
18 // Step is one step in ninja_log file. 18 // Step is one step in ninja_log file.
19 // time is measured from ninja start time. 19 // time is measured from ninja start time.
20 type Step struct { 20 type Step struct {
21 » Start time.Duration 21 » Start time.Duration
22 » End time.Duration 22 » End time.Duration
23 » Restat time.Time 23 » // modification time, but not convertable to absolute real time.
24 » // on POSIX, time_t is used, but on Windows differnt type is used.
Paweł Hajdan Jr. 2014/09/11 09:12:45 nit: typo differnt -> different
ukai 2014/09/11 15:59:47 Done.
25 » // htts://github.com/martine/ninja/blob/master/src/timestamp.h
26 » Restat int
24 Out string 27 Out string
25 CmdHash string 28 CmdHash string
26 } 29 }
27 30
28 // Duration reports step's duration. 31 // Duration reports step's duration.
29 func (s Step) Duration() time.Duration { 32 func (s Step) Duration() time.Duration {
30 return s.End - s.Start 33 return s.End - s.Start
31 } 34 }
32 35
33 // Steps is a list of Step. 36 // Steps is a list of Step.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 89
87 // Env is environment variables. 90 // Env is environment variables.
88 Env map[string]string `json:"env"` 91 Env map[string]string `json:"env"`
89 92
90 // CompilerProxyInfo is a path name of associated compiler_proxy.INFO lo g. 93 // CompilerProxyInfo is a path name of associated compiler_proxy.INFO lo g.
91 CompilerProxyInfo string `json:"compiler_proxy_info"` 94 CompilerProxyInfo string `json:"compiler_proxy_info"`
92 } 95 }
93 96
94 // NinjaLog is parsed data of ninja_log file. 97 // NinjaLog is parsed data of ninja_log file.
95 type NinjaLog struct { 98 type NinjaLog struct {
99 // Filename is a filename of ninja_log.
100 Filename string
101
96 // Start is start line of the last build in ninja_log file. 102 // Start is start line of the last build in ninja_log file.
97 Start int 103 Start int
98 104
99 // Steps contains steps in the last build in ninja_log file. 105 // Steps contains steps in the last build in ninja_log file.
100 Steps []Step 106 Steps []Step
101 107
102 // Metadata is additional data found in ninja_log file. 108 // Metadata is additional data found in ninja_log file.
103 Metadata Metadata 109 Metadata Metadata
104 } 110 }
105 111
106 // Parse parses .ninja_log file, with chromium's compile.py metadata. 112 // Parse parses .ninja_log file, with chromium's compile.py metadata.
107 func Parse(r io.Reader) (*NinjaLog, error) { 113 func Parse(fname string, r io.Reader) (*NinjaLog, error) {
108 b := bufio.NewReader(r) 114 b := bufio.NewReader(r)
109 scanner := bufio.NewScanner(b) 115 scanner := bufio.NewScanner(b)
110 » nlog := &NinjaLog{} 116 » nlog := &NinjaLog{Filename: fname}
111 lineno := 0 117 lineno := 0
112 if !scanner.Scan() { 118 if !scanner.Scan() {
113 if err := scanner.Err(); err != nil { 119 if err := scanner.Err(); err != nil {
114 return nil, err 120 return nil, err
115 } 121 }
116 return nil, fmt.Errorf("empty file?") 122 return nil, fmt.Errorf("empty file?")
117 } 123 }
118 lineno++ 124 lineno++
119 line := scanner.Text() 125 line := scanner.Text()
120 if line != "# ninja log v5" { 126 if line != "# ninja log v5" {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 e, err := strconv.Atoi(fields[1]) 175 e, err := strconv.Atoi(fields[1])
170 if err != nil { 176 if err != nil {
171 return step, fmt.Errorf("bad end %s:%v", fields[1], err) 177 return step, fmt.Errorf("bad end %s:%v", fields[1], err)
172 } 178 }
173 rs, err := strconv.Atoi(fields[2]) 179 rs, err := strconv.Atoi(fields[2])
174 if err != nil { 180 if err != nil {
175 return step, fmt.Errorf("bad restat %s:%v", fields[2], err) 181 return step, fmt.Errorf("bad restat %s:%v", fields[2], err)
176 } 182 }
177 step.Start = time.Duration(s) * time.Millisecond 183 step.Start = time.Duration(s) * time.Millisecond
178 step.End = time.Duration(e) * time.Millisecond 184 step.End = time.Duration(e) * time.Millisecond
179 » step.Restat = time.Unix(int64(rs), 0) 185 » step.Restat = rs
180 step.Out = fields[3] 186 step.Out = fields[3]
181 step.CmdHash = fields[4] 187 step.CmdHash = fields[4]
182 return step, nil 188 return step, nil
183 } 189 }
184 190
185 func stepToLine(s Step) string { 191 func stepToLine(s Step) string {
186 return fmt.Sprintf("%d\t%d\t%d\t%s\t%s", 192 return fmt.Sprintf("%d\t%d\t%d\t%s\t%s",
187 s.Start.Nanoseconds()/int64(time.Millisecond), 193 s.Start.Nanoseconds()/int64(time.Millisecond),
188 s.End.Nanoseconds()/int64(time.Millisecond), 194 s.End.Nanoseconds()/int64(time.Millisecond),
189 » » s.Restat.Unix(), 195 » » s.Restat,
190 s.Out, 196 s.Out,
191 s.CmdHash) 197 s.CmdHash)
192 } 198 }
193 199
194 func parseMetadata(buf []byte, metadata *Metadata) error { 200 func parseMetadata(buf []byte, metadata *Metadata) error {
195 return json.Unmarshal(buf, metadata) 201 return json.Unmarshal(buf, metadata)
196 } 202 }
197 203
198 // Dump dumps steps as ninja log v5 format in w. 204 // Dump dumps steps as ninja log v5 format in w.
199 func Dump(w io.Writer, steps []Step) error { 205 func Dump(w io.Writer, steps []Step) error {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 252 }
247 } 253 }
248 if tid == -1 { 254 if tid == -1 {
249 threads = append(threads, nil) 255 threads = append(threads, nil)
250 tid = len(threads) - 1 256 tid = len(threads) - 1
251 } 257 }
252 threads[tid] = append(threads[tid], s) 258 threads[tid] = append(threads[tid], s)
253 } 259 }
254 return threads 260 return threads
255 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698