Add pprof labels
Add pprof labels to the larger stages of blueprint, including labels for each mutator. Change-Id: Ie91daff51811187c1b702a775c05d0b32f7170fc
This commit is contained in:
parent
716137ec38
commit
3a8c025648
1 changed files with 152 additions and 103 deletions
95
context.go
95
context.go
|
@ -16,6 +16,7 @@ package blueprint
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -24,6 +25,7 @@ import (
|
|||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -66,6 +68,8 @@ const MockModuleListFile = "bplist"
|
|||
// write phase generates the Ninja manifest text based on the generated build
|
||||
// actions.
|
||||
type Context struct {
|
||||
context.Context
|
||||
|
||||
// set at instantiation
|
||||
moduleFactories map[string]ModuleFactory
|
||||
nameInterface NameInterface
|
||||
|
@ -275,6 +279,7 @@ type mutatorInfo struct {
|
|||
|
||||
func newContext() *Context {
|
||||
return &Context{
|
||||
Context: context.Background(),
|
||||
moduleFactories: make(map[string]ModuleFactory),
|
||||
nameInterface: NewSimpleNameInterface(),
|
||||
moduleInfo: make(map[Module]*moduleInfo),
|
||||
|
@ -1329,27 +1334,39 @@ func (c *Context) addModule(module *moduleInfo) []error {
|
|||
// the modules depended upon are defined and that no circular dependencies
|
||||
// exist.
|
||||
func (c *Context) ResolveDependencies(config interface{}) (deps []string, errs []error) {
|
||||
return c.resolveDependencies(c.Context, config)
|
||||
}
|
||||
|
||||
func (c *Context) resolveDependencies(ctx context.Context, config interface{}) (deps []string, errs []error) {
|
||||
pprof.Do(ctx, pprof.Labels("blueprint", "ResolveDependencies"), func(ctx context.Context) {
|
||||
c.liveGlobals = newLiveTracker(config)
|
||||
|
||||
deps, errs = c.generateSingletonBuildActions(config, c.preSingletonInfo, c.liveGlobals)
|
||||
if len(errs) > 0 {
|
||||
return nil, errs
|
||||
return
|
||||
}
|
||||
|
||||
errs = c.updateDependencies()
|
||||
if len(errs) > 0 {
|
||||
return nil, errs
|
||||
return
|
||||
}
|
||||
|
||||
mutatorDeps, errs := c.runMutators(config)
|
||||
var mutatorDeps []string
|
||||
mutatorDeps, errs = c.runMutators(ctx, config)
|
||||
if len(errs) > 0 {
|
||||
return nil, errs
|
||||
return
|
||||
}
|
||||
deps = append(deps, mutatorDeps...)
|
||||
|
||||
c.cloneModules()
|
||||
|
||||
c.dependenciesReady = true
|
||||
})
|
||||
|
||||
if len(errs) > 0 {
|
||||
return nil, errs
|
||||
}
|
||||
|
||||
return deps, nil
|
||||
}
|
||||
|
||||
|
@ -1863,31 +1880,39 @@ func (c *Context) updateDependencies() (errs []error) {
|
|||
// SingletonContext.AddNinjaFileDeps(), and PackageContext.AddNinjaFileDeps()
|
||||
// methods.
|
||||
func (c *Context) PrepareBuildActions(config interface{}) (deps []string, errs []error) {
|
||||
pprof.Do(c.Context, pprof.Labels("blueprint", "PrepareBuildActions"), func(ctx context.Context) {
|
||||
c.buildActionsReady = false
|
||||
|
||||
if !c.dependenciesReady {
|
||||
extraDeps, errs := c.ResolveDependencies(config)
|
||||
var extraDeps []string
|
||||
extraDeps, errs = c.resolveDependencies(ctx, config)
|
||||
if len(errs) > 0 {
|
||||
return nil, errs
|
||||
return
|
||||
}
|
||||
deps = append(deps, extraDeps...)
|
||||
}
|
||||
|
||||
depsModules, errs := c.generateModuleBuildActions(config, c.liveGlobals)
|
||||
var depsModules []string
|
||||
depsModules, errs = c.generateModuleBuildActions(config, c.liveGlobals)
|
||||
if len(errs) > 0 {
|
||||
return nil, errs
|
||||
return
|
||||
}
|
||||
|
||||
depsSingletons, errs := c.generateSingletonBuildActions(config, c.singletonInfo, c.liveGlobals)
|
||||
var depsSingletons []string
|
||||
depsSingletons, errs = c.generateSingletonBuildActions(config, c.singletonInfo, c.liveGlobals)
|
||||
if len(errs) > 0 {
|
||||
return nil, errs
|
||||
return
|
||||
}
|
||||
|
||||
deps = append(deps, depsModules...)
|
||||
deps = append(deps, depsSingletons...)
|
||||
|
||||
if c.ninjaBuildDir != nil {
|
||||
c.liveGlobals.addNinjaStringDeps(c.ninjaBuildDir)
|
||||
err := c.liveGlobals.addNinjaStringDeps(c.ninjaBuildDir)
|
||||
if err != nil {
|
||||
errs = []error{err}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
pkgNames, depsPackages := c.makeUniquePackageNames(c.liveGlobals)
|
||||
|
@ -1903,17 +1928,24 @@ func (c *Context) PrepareBuildActions(config interface{}) (deps []string, errs [
|
|||
c.globalRules = c.liveGlobals.rules
|
||||
|
||||
c.buildActionsReady = true
|
||||
})
|
||||
|
||||
if len(errs) > 0 {
|
||||
return nil, errs
|
||||
}
|
||||
|
||||
return deps, nil
|
||||
}
|
||||
|
||||
func (c *Context) runMutators(config interface{}) (deps []string, errs []error) {
|
||||
func (c *Context) runMutators(ctx context.Context, config interface{}) (deps []string, errs []error) {
|
||||
var mutators []*mutatorInfo
|
||||
|
||||
pprof.Do(ctx, pprof.Labels("blueprint", "runMutators"), func(ctx context.Context) {
|
||||
mutators = append(mutators, c.earlyMutatorInfo...)
|
||||
mutators = append(mutators, c.mutatorInfo...)
|
||||
|
||||
for _, mutator := range mutators {
|
||||
pprof.Do(ctx, pprof.Labels("mutator", mutator.name), func(context.Context) {
|
||||
var newDeps []string
|
||||
if mutator.topDownMutator != nil {
|
||||
newDeps, errs = c.runMutator(config, mutator, topDownMutator)
|
||||
|
@ -1923,9 +1955,18 @@ func (c *Context) runMutators(config interface{}) (deps []string, errs []error)
|
|||
panic("no mutator set on " + mutator.name)
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return nil, errs
|
||||
return
|
||||
}
|
||||
deps = append(deps, newDeps...)
|
||||
})
|
||||
if len(errs) > 0 {
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if len(errs) > 0 {
|
||||
return nil, errs
|
||||
}
|
||||
|
||||
return deps, nil
|
||||
|
@ -2932,55 +2973,63 @@ func (c *Context) VisitAllModuleVariants(module Module,
|
|||
// actions to w. If this is called before PrepareBuildActions successfully
|
||||
// completes then ErrBuildActionsNotReady is returned.
|
||||
func (c *Context) WriteBuildFile(w io.Writer) error {
|
||||
var err error
|
||||
pprof.Do(c.Context, pprof.Labels("blueprint", "WriteBuildFile"), func(ctx context.Context) {
|
||||
if !c.buildActionsReady {
|
||||
return ErrBuildActionsNotReady
|
||||
err = ErrBuildActionsNotReady
|
||||
return
|
||||
}
|
||||
|
||||
nw := newNinjaWriter(w)
|
||||
|
||||
err := c.writeBuildFileHeader(nw)
|
||||
err = c.writeBuildFileHeader(nw)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
err = c.writeNinjaRequiredVersion(nw)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
err = c.writeSubninjas(nw)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Group the globals by package.
|
||||
|
||||
err = c.writeGlobalVariables(nw)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
err = c.writeGlobalPools(nw)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
err = c.writeBuildDir(nw)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
err = c.writeGlobalRules(nw)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
err = c.writeAllModuleActions(nw)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
err = c.writeAllSingletonActions(nw)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue