Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 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 build |
| 16 | |
| 17 | import ( |
| 18 | "context" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 19 | |
| 20 | "android/soong/ui/logger" |
Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame^] | 21 | "android/soong/ui/status" |
| 22 | "android/soong/ui/terminal" |
Dan Willemsen | d9f6fa2 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 23 | "android/soong/ui/tracer" |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 24 | ) |
| 25 | |
Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame^] | 26 | // Context combines a context.Context, logger.Logger, and terminal.Writer. |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 27 | // These all are agnostic of the current build, and may be used for multiple |
| 28 | // builds, while the Config objects contain per-build information. |
Dan Willemsen | d9f6fa2 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 29 | type Context struct{ *ContextImpl } |
Dan Willemsen | 1e70446 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 30 | type ContextImpl struct { |
| 31 | context.Context |
| 32 | logger.Logger |
| 33 | |
Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame^] | 34 | Writer terminal.Writer |
| 35 | Status *status.Status |
Dan Willemsen | d9f6fa2 | 2016-08-21 15:17:17 -0700 | [diff] [blame] | 36 | |
| 37 | Thread tracer.Thread |
| 38 | Tracer tracer.Tracer |
| 39 | } |
| 40 | |
| 41 | // BeginTrace starts a new Duration Event. |
| 42 | func (c ContextImpl) BeginTrace(name string) { |
| 43 | if c.Tracer != nil { |
| 44 | c.Tracer.Begin(name, c.Thread) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // EndTrace finishes the last Duration Event. |
| 49 | func (c ContextImpl) EndTrace() { |
| 50 | if c.Tracer != nil { |
| 51 | c.Tracer.End(c.Thread) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // CompleteTrace writes a trace with a beginning and end times. |
| 56 | func (c ContextImpl) CompleteTrace(name string, begin, end uint64) { |
| 57 | if c.Tracer != nil { |
| 58 | c.Tracer.Complete(name, c.Thread, begin, end) |
| 59 | } |
| 60 | } |