blob: c8b00c38d5f4c2e296e68d91034eecdad8ba7851 [file] [log] [blame]
Dan Willemsen1e704462016-08-21 15:17:17 -07001// 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
15package build
16
17import (
18 "context"
Dan Willemsen1e704462016-08-21 15:17:17 -070019
20 "android/soong/ui/logger"
Dan Willemsenb82471a2018-05-17 16:37:09 -070021 "android/soong/ui/status"
22 "android/soong/ui/terminal"
Dan Willemsend9f6fa22016-08-21 15:17:17 -070023 "android/soong/ui/tracer"
Dan Willemsen1e704462016-08-21 15:17:17 -070024)
25
Dan Willemsenb82471a2018-05-17 16:37:09 -070026// Context combines a context.Context, logger.Logger, and terminal.Writer.
Dan Willemsen1e704462016-08-21 15:17:17 -070027// 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 Willemsend9f6fa22016-08-21 15:17:17 -070029type Context struct{ *ContextImpl }
Dan Willemsen1e704462016-08-21 15:17:17 -070030type ContextImpl struct {
31 context.Context
32 logger.Logger
33
Dan Willemsenb82471a2018-05-17 16:37:09 -070034 Writer terminal.Writer
35 Status *status.Status
Dan Willemsend9f6fa22016-08-21 15:17:17 -070036
37 Thread tracer.Thread
38 Tracer tracer.Tracer
39}
40
41// BeginTrace starts a new Duration Event.
42func (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.
49func (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.
56func (c ContextImpl) CompleteTrace(name string, begin, end uint64) {
57 if c.Tracer != nil {
58 c.Tracer.Complete(name, c.Thread, begin, end)
59 }
60}