Merge "Save invocation info of dex2oat runs."
diff --git a/android/apex.go b/android/apex.go
index d1fb6f4..8d99d56 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -122,15 +122,13 @@
func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []blueprint.Module {
if len(m.apexVariations) > 0 {
- // The original module is mutated into "platform" variation.
- variations := []string{"platform"}
- for _, a := range m.apexVariations {
- variations = append(variations, a)
- }
+ variations := []string{""} // Original variation for platform
+ variations = append(variations, m.apexVariations...)
+
modules := mctx.CreateVariations(variations...)
for i, m := range modules {
if i == 0 {
- continue // platform
+ continue
}
m.(ApexModule).setApexName(variations[i])
}
diff --git a/android/module.go b/android/module.go
index dc0c856..d2f84ce 100644
--- a/android/module.go
+++ b/android/module.go
@@ -190,6 +190,7 @@
GetProperties() []interface{}
BuildParamsForTests() []BuildParams
+ VariablesForTests() map[string]string
}
type nameProperties struct {
@@ -473,6 +474,7 @@
// For tests
buildParams []BuildParams
+ variables map[string]string
prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
}
@@ -489,6 +491,10 @@
return a.buildParams
}
+func (a *ModuleBase) VariablesForTests() map[string]string {
+ return a.variables
+}
+
func (a *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
a.prefer32 = prefer32
}
@@ -781,6 +787,7 @@
installDeps: a.computeInstallDeps(blueprintCtx),
installFiles: a.installFiles,
missingDeps: blueprintCtx.GetMissingDependencies(),
+ variables: make(map[string]string),
}
desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
@@ -842,6 +849,7 @@
}
a.buildParams = ctx.buildParams
+ a.variables = ctx.variables
}
type androidBaseContextImpl struct {
@@ -864,6 +872,7 @@
// For tests
buildParams []BuildParams
+ variables map[string]string
}
func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) {
@@ -928,6 +937,10 @@
}
func (a *androidModuleContext) Variable(pctx PackageContext, name, value string) {
+ if a.config.captureBuild {
+ a.variables[name] = value
+ }
+
a.ModuleContext.Variable(pctx.PackageContext, name, value)
}
diff --git a/apex/apex.go b/apex/apex.go
index 6230236..79b79e8 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -56,12 +56,12 @@
`--file_contexts ${file_contexts} ` +
`--canned_fs_config ${canned_fs_config} ` +
`--payload_type image ` +
- `--key ${key} ${image_dir} ${out} `,
+ `--key ${key} ${opt_flags} ${image_dir} ${out} `,
CommandDeps: []string{"${apexer}", "${avbtool}", "${e2fsdroid}", "${merge_zips}",
"${mke2fs}", "${resize2fs}", "${sefcontext_compile}",
"${soong_zip}", "${zipalign}", "${aapt2}"},
Description: "APEX ${image_dir} => ${out}",
- }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key")
+ }, "tool_path", "image_dir", "copy_commands", "manifest", "file_contexts", "canned_fs_config", "key", "opt_flags")
zipApexRule = pctx.StaticRule("zipApexRule", blueprint.RuleParams{
Command: `rm -rf ${image_dir} && mkdir -p ${image_dir} && ` +
@@ -518,6 +518,7 @@
filesInfo := []apexFile{}
var keyFile android.Path
+ var pubKeyFile android.Path
var certificate java.Certificate
if a.properties.Payload_type == nil || *a.properties.Payload_type == "image" {
@@ -576,6 +577,12 @@
case keyTag:
if key, ok := child.(*apexKey); ok {
keyFile = key.private_key_file
+ if !key.installable() && ctx.Config().Debuggable() {
+ // If the key is not installed, bundled it with the APEX.
+ // Note: this bundled key is valid only for non-production builds
+ // (eng/userdebug).
+ pubKeyFile = key.public_key_file
+ }
return false
} else {
ctx.PropertyErrorf("key", "%q is not an apex_key module", depName)
@@ -640,18 +647,19 @@
a.filesInfo = filesInfo
if a.apexTypes.zip() {
- a.buildUnflattenedApex(ctx, keyFile, certificate, zipApex)
+ a.buildUnflattenedApex(ctx, keyFile, pubKeyFile, certificate, zipApex)
}
if a.apexTypes.image() {
if ctx.Config().FlattenApex() {
a.buildFlattenedApex(ctx)
} else {
- a.buildUnflattenedApex(ctx, keyFile, certificate, imageApex)
+ a.buildUnflattenedApex(ctx, keyFile, pubKeyFile, certificate, imageApex)
}
}
}
-func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, keyFile android.Path, certificate java.Certificate, apexType apexPackaging) {
+func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext, keyFile android.Path,
+ pubKeyFile android.Path, certificate java.Certificate, apexType apexPackaging) {
cert := String(a.properties.Certificate)
if cert != "" && android.SrcIsModule(cert) == "" {
defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
@@ -739,8 +747,14 @@
}
fileContexts := fileContextsOptionalPath.Path()
+ optFlags := []string{}
+
// Additional implicit inputs.
implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, keyFile)
+ if pubKeyFile != nil {
+ implicitInputs = append(implicitInputs, pubKeyFile)
+ optFlags = append(optFlags, "--pubkey "+pubKeyFile.String())
+ }
ctx.Build(pctx, android.BuildParams{
Rule: apexRule,
@@ -755,6 +769,7 @@
"file_contexts": fileContexts.String(),
"canned_fs_config": cannedFsConfig.String(),
"key": keyFile.String(),
+ "opt_flags": strings.Join(optFlags, " "),
},
})
@@ -863,7 +878,7 @@
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w, "LOCAL_MODULE :=", fi.moduleName)
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString(), name, fi.installDir))
- fmt.Fprintln(w, "LOCAL_INSTALLED_MODULE_STEM :=", fi.builtFile.Base())
+ fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.builtFile.Base())
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", fi.builtFile.String())
fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", fi.class.NameInMake())
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
@@ -897,7 +912,7 @@
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class?
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFiles[apexType].String())
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join("$(OUT_DIR)", a.installDir.RelPathString()))
- fmt.Fprintln(w, "LOCAL_INSTALLED_MODULE_STEM :=", name+apexType.suffix())
+ fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", name+apexType.suffix())
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !a.installable())
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", String(a.properties.Key))
fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
diff --git a/apex/apex_test.go b/apex/apex_test.go
index dd5bf70..f8f9b33 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -227,6 +227,10 @@
// Ensure that both direct and indirect deps are copied into apex
ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
+
+ // Ensure that the platform variant ends with _core_shared
+ ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
+ ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
}
func TestBasicZipApex(t *testing.T) {
diff --git a/apex/key.go b/apex/key.go
index ff348a8..6fbc9b0 100644
--- a/apex/key.go
+++ b/apex/key.go
@@ -45,6 +45,9 @@
Public_key *string
// Path to the private key file in pem format. Used to sign APEXs.
Private_key *string
+
+ // Whether this key is installable to one of the partitions. Defualt: true.
+ Installable *bool
}
func apexKeyFactory() android.Module {
@@ -54,6 +57,10 @@
return module
}
+func (m *apexKey) installable() bool {
+ return m.properties.Installable == nil || proptools.Bool(m.properties.Installable)
+}
+
func (m *apexKey) DepsMutator(ctx android.BottomUpMutatorContext) {
}
@@ -71,7 +78,9 @@
}
m.keyName = pubKeyName
- ctx.InstallFile(android.PathForModuleInstall(ctx, "etc/security/apex"), m.keyName, m.public_key_file)
+ if m.installable() {
+ ctx.InstallFile(android.PathForModuleInstall(ctx, "etc/security/apex"), m.keyName, m.public_key_file)
+ }
}
func (m *apexKey) AndroidMk() android.AndroidMkData {
@@ -82,6 +91,7 @@
func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", "$(TARGET_OUT)/etc/security/apex")
fmt.Fprintln(w, "LOCAL_INSTALLED_MODULE_STEM :=", m.keyName)
+ fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE :=", !m.installable())
},
},
}
diff --git a/bpf/bpf.go b/bpf/bpf.go
index fa1f3ff..3ef35b7 100644
--- a/bpf/bpf.go
+++ b/bpf/bpf.go
@@ -125,6 +125,14 @@
}
}
+// Implements SourceFileProducer interface so that the obj output can be used in the data property
+// of other modules.
+func (bpf *bpf) Srcs() android.Paths {
+ return bpf.objs
+}
+
+var _ android.SourceFileProducer = (*bpf)(nil)
+
func bpfFactory() android.Module {
module := &bpf{}
diff --git a/bpf/bpf_test.go b/bpf/bpf_test.go
new file mode 100644
index 0000000..1d53e41
--- /dev/null
+++ b/bpf/bpf_test.go
@@ -0,0 +1,192 @@
+// Copyright 2018 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package bpf
+
+import (
+ "io/ioutil"
+ "os"
+ "testing"
+
+ "android/soong/android"
+ cc2 "android/soong/cc"
+)
+
+var buildDir string
+
+func setUp() {
+ var err error
+ buildDir, err = ioutil.TempDir("", "genrule_test")
+ if err != nil {
+ panic(err)
+ }
+}
+
+func tearDown() {
+ os.RemoveAll(buildDir)
+}
+
+func TestMain(m *testing.M) {
+ run := func() int {
+ setUp()
+ defer tearDown()
+
+ return m.Run()
+ }
+
+ os.Exit(run())
+}
+
+func testContext(bp string) *android.TestContext {
+ ctx := android.NewTestArchContext()
+ ctx.RegisterModuleType("bpf", android.ModuleFactoryAdaptor(bpfFactory))
+ ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc2.TestFactory))
+ ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc2.LibraryFactory))
+ ctx.RegisterModuleType("cc_library_static", android.ModuleFactoryAdaptor(cc2.LibraryStaticFactory))
+ ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc2.ObjectFactory))
+ ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc2.ToolchainLibraryFactory))
+ ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
+ ctx.BottomUp("link", cc2.LinkageMutator).Parallel()
+ })
+ ctx.Register()
+
+ // Add some modules that are required by the compiler and/or linker
+ bp = bp + `
+ toolchain_library {
+ name: "libatomic",
+ vendor_available: true,
+ recovery_available: true,
+ src: "",
+ }
+
+ toolchain_library {
+ name: "libclang_rt.builtins-arm-android",
+ vendor_available: true,
+ recovery_available: true,
+ src: "",
+ }
+
+ toolchain_library {
+ name: "libclang_rt.builtins-aarch64-android",
+ vendor_available: true,
+ recovery_available: true,
+ src: "",
+ }
+
+ toolchain_library {
+ name: "libgcc",
+ vendor_available: true,
+ recovery_available: true,
+ src: "",
+ }
+
+ cc_library {
+ name: "libc",
+ no_libgcc: true,
+ nocrt: true,
+ system_shared_libs: [],
+ recovery_available: true,
+ }
+
+ cc_library {
+ name: "libm",
+ no_libgcc: true,
+ nocrt: true,
+ system_shared_libs: [],
+ recovery_available: true,
+ }
+
+ cc_library {
+ name: "libdl",
+ no_libgcc: true,
+ nocrt: true,
+ system_shared_libs: [],
+ recovery_available: true,
+ }
+
+ cc_library {
+ name: "libgtest",
+ host_supported: true,
+ vendor_available: true,
+ }
+
+ cc_library {
+ name: "libgtest_main",
+ host_supported: true,
+ vendor_available: true,
+ }
+
+ cc_object {
+ name: "crtbegin_dynamic",
+ recovery_available: true,
+ vendor_available: true,
+ }
+
+ cc_object {
+ name: "crtend_android",
+ recovery_available: true,
+ vendor_available: true,
+ }
+
+ cc_object {
+ name: "crtbegin_so",
+ recovery_available: true,
+ vendor_available: true,
+ }
+
+ cc_object {
+ name: "crtend_so",
+ recovery_available: true,
+ vendor_available: true,
+ }
+ `
+ mockFS := map[string][]byte{
+ "Android.bp": []byte(bp),
+ "bpf.c": nil,
+ "BpfTest.cpp": nil,
+ }
+
+ ctx.MockFileSystem(mockFS)
+
+ return ctx
+}
+
+func TestBpfDataDependency(t *testing.T) {
+ config := android.TestArchConfig(buildDir, nil)
+ bp := `
+ bpf {
+ name: "bpf.o",
+ srcs: ["bpf.c"],
+ }
+
+ cc_test {
+ name: "vts_test_binary_bpf_module",
+ srcs: ["BpfTest.cpp"],
+ data: [":bpf.o"],
+ }
+ `
+
+ ctx := testContext(bp)
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ if errs == nil {
+ _, errs = ctx.PrepareBuildActions(config)
+ }
+ if errs != nil {
+ t.Fatal(errs)
+ }
+
+ // We only verify the above BP configuration is processed successfully since the data property
+ // value is not available for testing from this package.
+ // TODO(jungjw): Add a check for data or move this test to the cc package.
+}
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 1f5a8ad..82feec8 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -59,7 +59,7 @@
ret := android.AndroidMkData{
OutputFile: c.outputFile,
- Required: c.Properties.AndroidMkRuntimeLibs,
+ Required: append(c.Properties.AndroidMkRuntimeLibs, c.Properties.ApexesProvidingSharedLibs...),
Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Extra: []android.AndroidMkExtraFunc{
@@ -76,9 +76,6 @@
if len(c.Properties.AndroidMkWholeStaticLibs) > 0 {
fmt.Fprintln(w, "LOCAL_WHOLE_STATIC_LIBRARIES := "+strings.Join(c.Properties.AndroidMkWholeStaticLibs, " "))
}
- if len(c.Properties.ApexesProvidingSharedLibs) > 0 {
- fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(c.Properties.ApexesProvidingSharedLibs, " "))
- }
fmt.Fprintln(w, "LOCAL_SOONG_LINK_TYPE :=", c.getMakeLinkType())
if c.useVndk() {
fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
diff --git a/cc/builder.go b/cc/builder.go
index bf35f84..5dbd23e 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -55,6 +55,13 @@
},
"ccCmd", "cFlags")
+ ccNoDeps = pctx.AndroidGomaStaticRule("ccNoDeps",
+ blueprint.RuleParams{
+ Command: "$relPwd ${config.CcWrapper}$ccCmd -c $cFlags -o $out $in",
+ CommandDeps: []string{"$ccCmd"},
+ },
+ "ccCmd", "cFlags")
+
ld = pctx.AndroidStaticRule("ld",
blueprint.RuleParams{
Command: "$ldCmd ${crtBegin} @${out}.rsp " +
@@ -383,9 +390,13 @@
tidy := flags.tidy
coverage := flags.coverage
dump := flags.sAbiDump
+ rule := cc
switch srcFile.Ext() {
- case ".S", ".s":
+ case ".s":
+ rule = ccNoDeps
+ fallthrough
+ case ".S":
ccCmd = "clang"
moduleCflags = asflags
tidy = false
@@ -416,7 +427,7 @@
}
ctx.Build(pctx, android.BuildParams{
- Rule: cc,
+ Rule: rule,
Description: ccDesc + " " + srcFile.Rel(),
Output: objFile,
ImplicitOutputs: implicitOutputs,
diff --git a/cc/cc.go b/cc/cc.go
index c3e554c..ce28a3b 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -634,6 +634,10 @@
// Host modules do not need ABI dumps.
return false
}
+ if !ctx.mod.IsForPlatform() {
+ // APEX variants do not need ABI dumps.
+ return false
+ }
if inList(ctx.baseModuleName(), llndkLibraries) {
return true
}
diff --git a/cc/library.go b/cc/library.go
index 40c1b4f..da223dc 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1059,7 +1059,7 @@
stubsVersionsFor(mctx.Config())[mctx.ModuleName()] = copiedVersions
// "" is for the non-stubs variant
- versions = append(versions, "")
+ versions = append([]string{""}, versions...)
modules := mctx.CreateVariations(versions...)
for i, m := range modules {
diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go
index b603571..2bd0cf4 100644
--- a/cmd/soong_ui/main.go
+++ b/cmd/soong_ui/main.go
@@ -26,6 +26,7 @@
"android/soong/ui/build"
"android/soong/ui/logger"
+ "android/soong/ui/metrics"
"android/soong/ui/status"
"android/soong/ui/terminal"
"android/soong/ui/tracer"
@@ -73,6 +74,8 @@
trace := tracer.New(log)
defer trace.Close()
+ met := metrics.New()
+
stat := &status.Status{}
defer stat.Finish()
stat.AddOutput(terminal.NewStatusOutput(writer, os.Getenv("NINJA_STATUS")))
@@ -87,6 +90,7 @@
buildCtx := build.Context{ContextImpl: &build.ContextImpl{
Context: ctx,
Logger: log,
+ Metrics: met,
Tracer: trace,
Writer: writer,
Status: stat,
@@ -100,6 +104,9 @@
build.SetupOutDir(buildCtx, config)
+ metricsPath := filepath.Join(config.OutDir(), "build_metrics")
+ defer met.Dump(metricsPath)
+
logsDir := config.OutDir()
if config.Dist() {
logsDir = filepath.Join(config.DistDir(), "logs")
@@ -116,7 +123,7 @@
if start_time, err := strconv.ParseUint(start, 10, 64); err == nil {
log.Verbosef("Took %dms to start up.",
time.Since(time.Unix(0, int64(start_time))).Nanoseconds()/time.Millisecond.Nanoseconds())
- buildCtx.CompleteTrace("startup", start_time, uint64(time.Now().UnixNano()))
+ buildCtx.CompleteTrace(metrics.RunSetupTool, "startup", start_time, uint64(time.Now().UnixNano()))
}
}
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 6a4fd4a..c24caac 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -83,14 +83,14 @@
}
type ModuleConfig struct {
- Name string
- DexLocation string // dex location on device
- BuildPath string
- DexPath string
- PreferIntegrity bool
- UncompressedDex bool
- HasApkLibraries bool
- PreoptFlags []string
+ Name string
+ DexLocation string // dex location on device
+ BuildPath string
+ DexPath string
+ PreferCodeIntegrity bool
+ UncompressedDex bool
+ HasApkLibraries bool
+ PreoptFlags []string
ProfileClassListing string
ProfileIsTextListing bool
diff --git a/dexpreopt/dexpreopt_test.go b/dexpreopt/dexpreopt_test.go
index 5265248..fef85a7 100644
--- a/dexpreopt/dexpreopt_test.go
+++ b/dexpreopt/dexpreopt_test.go
@@ -66,7 +66,7 @@
DexLocation: "",
BuildPath: "",
DexPath: "",
- PreferIntegrity: false,
+ PreferCodeIntegrity: false,
UncompressedDex: false,
HasApkLibraries: false,
PreoptFlags: nil,
diff --git a/genrule/genrule.go b/genrule/genrule.go
index b70c075..77bc196 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -28,6 +28,8 @@
)
func init() {
+ android.RegisterModuleType("genrule_defaults", defaultsFactory)
+
android.RegisterModuleType("gensrcs", GenSrcsFactory)
android.RegisterModuleType("genrule", GenRuleFactory)
}
@@ -95,6 +97,7 @@
type Module struct {
android.ModuleBase
+ android.DefaultableModuleBase
// For other packages to make their own genrules with extra
// properties
@@ -502,6 +505,7 @@
func GenRuleFactory() android.Module {
m := NewGenRule()
android.InitAndroidModule(m)
+ android.InitDefaultableModule(m)
return m
}
@@ -512,3 +516,35 @@
var Bool = proptools.Bool
var String = proptools.String
+
+//
+// Defaults
+//
+type Defaults struct {
+ android.ModuleBase
+ android.DefaultsModuleBase
+}
+
+func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+}
+
+func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
+}
+
+func defaultsFactory() android.Module {
+ return DefaultsFactory()
+}
+
+func DefaultsFactory(props ...interface{}) android.Module {
+ module := &Defaults{}
+
+ module.AddProperties(props...)
+ module.AddProperties(
+ &generatorProperties{},
+ &genRuleProperties{},
+ )
+
+ android.InitDefaultsModule(module)
+
+ return module
+}
diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go
index a99fa18..70b9090 100644
--- a/genrule/genrule_test.go
+++ b/genrule/genrule_test.go
@@ -21,6 +21,7 @@
"testing"
"android/soong/android"
+ "reflect"
)
var buildDir string
@@ -54,7 +55,9 @@
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(GenRuleFactory))
+ ctx.RegisterModuleType("genrule_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
ctx.RegisterModuleType("tool", android.ModuleFactoryAdaptor(toolFactory))
+ ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
ctx.Register()
bp += `
@@ -465,6 +468,46 @@
}
+func TestGenruleDefaults(t *testing.T) {
+ config := android.TestArchConfig(buildDir, nil)
+ bp := `
+ genrule_defaults {
+ name: "gen_defaults1",
+ cmd: "cp $(in) $(out)",
+ }
+
+ genrule_defaults {
+ name: "gen_defaults2",
+ srcs: ["in1"],
+ }
+
+ genrule {
+ name: "gen",
+ out: ["out"],
+ defaults: ["gen_defaults1", "gen_defaults2"],
+ }
+ `
+ ctx := testContext(config, bp, nil)
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ if errs == nil {
+ _, errs = ctx.PrepareBuildActions(config)
+ }
+ if errs != nil {
+ t.Fatal(errs)
+ }
+ gen := ctx.ModuleForTests("gen", "").Module().(*Module)
+
+ expectedCmd := "'cp ${in} __SBOX_OUT_FILES__'"
+ if gen.rawCommand != expectedCmd {
+ t.Errorf("Expected cmd: %q, actual: %q", expectedCmd, gen.rawCommand)
+ }
+
+ expectedSrcs := []string{"in1"}
+ if !reflect.DeepEqual(expectedSrcs, gen.properties.Srcs) {
+ t.Errorf("Expected srcs: %q, actual: %q", expectedSrcs, gen.properties.Srcs)
+ }
+}
+
type testTool struct {
android.ModuleBase
outputFile android.Path
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index ae8d369..de9c5f3 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -147,14 +147,14 @@
}
dexpreoptConfig := dexpreopt.ModuleConfig{
- Name: ctx.ModuleName(),
- DexLocation: dexLocation,
- BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").String(),
- DexPath: dexJarFile.String(),
- PreferIntegrity: false,
- UncompressedDex: uncompressedDex,
- HasApkLibraries: false,
- PreoptFlags: nil,
+ Name: ctx.ModuleName(),
+ DexLocation: dexLocation,
+ BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").String(),
+ DexPath: dexJarFile.String(),
+ PreferCodeIntegrity: false,
+ UncompressedDex: uncompressedDex,
+ HasApkLibraries: false,
+ PreoptFlags: nil,
ProfileClassListing: profileClassListing.String(),
ProfileIsTextListing: profileIsTextListing,
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 8e0a62a..bd3b3ab 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -400,6 +400,7 @@
metalavaStubsFlags string
metalavaAnnotationsFlags string
+ metalavaMergeAnnoDirFlags string
metalavaInclusionAnnotationsFlags string
metalavaApiLevelsAnnotationsFlags string
@@ -1413,8 +1414,8 @@
}
func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
- implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
- var flags string
+ implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
+ var flags, mergeAnnoDirFlags string
if Bool(d.properties.Annotations_enabled) {
flags += " --include-annotations"
validatingNullability :=
@@ -1451,17 +1452,18 @@
ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
if t, ok := m.(*ExportedDroiddocDir); ok {
*implicits = append(*implicits, t.deps...)
- flags += " --merge-qualifier-annotations " + t.dir.String()
+ mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
} else {
ctx.PropertyErrorf("merge_annotations_dirs",
"module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
}
})
+ flags += mergeAnnoDirFlags
// TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
}
- return flags
+ return flags, mergeAnnoDirFlags
}
func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
@@ -1644,7 +1646,8 @@
}
flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
- flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
+ flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
+ d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
@@ -1670,7 +1673,7 @@
d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
" --check-compatibility:removed:current " + removedApiFile.String() +
- flags.metalavaInclusionAnnotationsFlags
+ flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
@@ -1701,7 +1704,7 @@
d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
- removedApiFile.String() + " "
+ removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
diff --git a/java/java.go b/java/java.go
index 71967a8..c02ccd3 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1011,8 +1011,15 @@
}
if j.properties.Patch_module != nil && flags.javaVersion == "1.9" {
- patchClasspath := ".:" + flags.classpath.FormJavaClassPath("")
- javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchClasspath)
+ // Manually specify build directory in case it is not under the repo root.
+ // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
+ // just adding a symlink under the root doesn't help.)
+ patchPaths := ".:" + ctx.Config().BuildDir()
+ classPath := flags.classpath.FormJavaClassPath("")
+ if classPath != "" {
+ patchPaths += ":" + classPath
+ }
+ javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths)
}
// systemModules
diff --git a/java/java_test.go b/java/java_test.go
index 4d4b836..2a54f69 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -1185,3 +1185,65 @@
}
}
}
+
+// TODO(jungjw): Consider making this more robust by ignoring path order.
+func checkPatchModuleFlag(t *testing.T, ctx *android.TestContext, moduleName string, expected string) {
+ variables := ctx.ModuleForTests(moduleName, "android_common").Module().VariablesForTests()
+ flags := strings.Split(variables["javacFlags"], " ")
+ got := ""
+ for _, flag := range flags {
+ keyEnd := strings.Index(flag, "=")
+ if keyEnd > -1 && flag[:keyEnd] == "--patch-module" {
+ got = flag[keyEnd+1:]
+ break
+ }
+ }
+ if expected != got {
+ t.Errorf("Unexpected patch-module flag for module %q - expected %q, but got %q", moduleName, expected, got)
+ }
+}
+
+func TestPatchModule(t *testing.T) {
+ bp := `
+ java_library {
+ name: "foo",
+ srcs: ["a.java"],
+ }
+
+ java_library {
+ name: "bar",
+ srcs: ["b.java"],
+ no_standard_libs: true,
+ system_modules: "none",
+ patch_module: "java.base",
+ }
+
+ java_library {
+ name: "baz",
+ srcs: ["c.java"],
+ patch_module: "java.base",
+ }
+ `
+
+ t.Run("1.8", func(t *testing.T) {
+ // Test default javac 1.8
+ ctx := testJava(t, bp)
+
+ checkPatchModuleFlag(t, ctx, "foo", "")
+ checkPatchModuleFlag(t, ctx, "bar", "")
+ checkPatchModuleFlag(t, ctx, "baz", "")
+ })
+
+ t.Run("1.9", func(t *testing.T) {
+ // Test again with javac 1.9
+ config := testConfig(map[string]string{"EXPERIMENTAL_USE_OPENJDK9": "true"})
+ ctx := testContext(config, bp, nil)
+ run(t, ctx, config)
+
+ checkPatchModuleFlag(t, ctx, "foo", "")
+ expected := "java.base=.:" + buildDir
+ checkPatchModuleFlag(t, ctx, "bar", expected)
+ expected = "java.base=" + strings.Join([]string{".", buildDir, moduleToPath("ext"), moduleToPath("framework")}, ":")
+ checkPatchModuleFlag(t, ctx, "baz", expected)
+ })
+}
diff --git a/python/scripts/stub_template_host.txt b/python/scripts/stub_template_host.txt
index 213401d..a48a86f 100644
--- a/python/scripts/stub_template_host.txt
+++ b/python/scripts/stub_template_host.txt
@@ -12,6 +12,9 @@
MAIN_FILE = '%main%'
PYTHON_PATH = 'PYTHONPATH'
+# Don't imply 'import site' on initialization
+PYTHON_ARG = '-S'
+
def SearchPathEnv(name):
search_path = os.getenv('PATH', os.defpath).split(os.pathsep)
for directory in search_path:
@@ -73,7 +76,7 @@
python_program = FindPythonBinary()
if python_program is None:
raise AssertionError('Could not find python binary: ' + PYTHON_BINARY)
- args = [python_program, main_filepath] + args
+ args = [python_program, PYTHON_ARG, main_filepath] + args
os.environ.update(new_env)
diff --git a/scripts/manifest_fixer.py b/scripts/manifest_fixer.py
index 64f49cb..ebfc4d8 100755
--- a/scripts/manifest_fixer.py
+++ b/scripts/manifest_fixer.py
@@ -61,9 +61,9 @@
help='specify additional <uses-library> tag to add. android:requred is set to false')
parser.add_argument('--uses-non-sdk-api', dest='uses_non_sdk_api', action='store_true',
help='manifest is for a package built against the platform')
- parser.add_argument('--prefer-integrity', dest='prefer_integrity', action='store_true',
- help=('specify if the app prefers strict integrity. Should not be conflict if ' +
- 'already declared in the manifest.'))
+ parser.add_argument('--prefer-code-integrity', dest='prefer_code_integrity', action='store_true',
+ help=('specify if the app prefers strict code integrity. Should not be conflict '
+ 'if already declared in the manifest.'))
parser.add_argument('input', help='input AndroidManifest.xml file')
parser.add_argument('output', help='output AndroidManifest.xml file')
return parser.parse_args()
@@ -272,7 +272,7 @@
application.setAttributeNode(attr)
-def add_prefer_integrity(doc):
+def add_prefer_code_integrity(doc):
manifest = parse_manifest(doc)
elems = get_children_with_tag(manifest, 'application')
application = elems[0] if len(elems) == 1 else None
@@ -285,13 +285,13 @@
manifest.insertBefore(doc.createTextNode(indent), first)
manifest.insertBefore(application, first)
- attr = application.getAttributeNodeNS(android_ns, 'preferIntegrity')
+ attr = application.getAttributeNodeNS(android_ns, 'preferCodeIntegrity')
if attr is None:
- attr = doc.createAttributeNS(android_ns, 'android:preferIntegrity')
+ attr = doc.createAttributeNS(android_ns, 'android:preferCodeIntegrity')
attr.value = 'true'
application.setAttributeNode(attr)
elif attr.value != 'true':
- raise RuntimeError('existing attribute mismatches the option of --prefer-integrity')
+ raise RuntimeError('existing attribute mismatches the option of --prefer-code-integrity')
def write_xml(f, doc):
@@ -321,8 +321,8 @@
if args.uses_non_sdk_api:
add_uses_non_sdk_api(doc)
- if args.prefer_integrity:
- add_prefer_integrity(doc)
+ if args.prefer_code_integrity:
+ add_prefer_code_integrity(doc)
with open(args.output, 'wb') as f:
write_xml(f, doc)
diff --git a/scripts/manifest_fixer_test.py b/scripts/manifest_fixer_test.py
index a621445..edc98cd 100755
--- a/scripts/manifest_fixer_test.py
+++ b/scripts/manifest_fixer_test.py
@@ -346,12 +346,12 @@
self.assertEqual(output, expected)
-class PreferIntegrityTest(unittest.TestCase):
- """Unit tests for add_prefer_integrity function."""
+class PreferCodeIntegrityTest(unittest.TestCase):
+ """Unit tests for add_prefer_code_integrity function."""
def run_test(self, input_manifest):
doc = minidom.parseString(input_manifest)
- manifest_fixer.add_prefer_integrity(doc)
+ manifest_fixer.add_prefer_code_integrity(doc)
output = StringIO.StringIO()
manifest_fixer.write_xml(output, doc)
return output.getvalue()
@@ -362,23 +362,23 @@
' <application%s/>\n'
'</manifest>\n')
- def prefer_integrity(self, value):
- return ' android:preferIntegrity="%s"' % value
+ def prefer_code_integrity(self, value):
+ return ' android:preferCodeIntegrity="%s"' % value
def test_manifest_with_undeclared_preference(self):
manifest_input = self.manifest_tmpl % ''
- expected = self.manifest_tmpl % self.prefer_integrity('true')
+ expected = self.manifest_tmpl % self.prefer_code_integrity('true')
output = self.run_test(manifest_input)
self.assertEqual(output, expected)
- def test_manifest_with_prefer_integrity(self):
- manifest_input = self.manifest_tmpl % self.prefer_integrity('true')
+ def test_manifest_with_prefer_code_integrity(self):
+ manifest_input = self.manifest_tmpl % self.prefer_code_integrity('true')
expected = manifest_input
output = self.run_test(manifest_input)
self.assertEqual(output, expected)
- def test_manifest_with_not_prefer_integrity(self):
- manifest_input = self.manifest_tmpl % self.prefer_integrity('false')
+ def test_manifest_with_not_prefer_code_integrity(self):
+ manifest_input = self.manifest_tmpl % self.prefer_code_integrity('false')
self.assertRaises(RuntimeError, self.run_test, manifest_input)
if __name__ == '__main__':
diff --git a/soong_ui.bash b/soong_ui.bash
index a39aa9c..c1c236b 100755
--- a/soong_ui.bash
+++ b/soong_ui.bash
@@ -23,7 +23,7 @@
function gettop
{
local TOPFILE=build/soong/root.bp
- if [ -z "${TOP-}" -a -f "${TOP-}/${TOPFILE}" ] ; then
+ if [ -n "${TOP-}" -a -f "${TOP-}/${TOPFILE}" ] ; then
# The following circumlocution ensures we remove symlinks from TOP.
(cd $TOP; PWD= /bin/pwd)
else
diff --git a/ui/build/Android.bp b/ui/build/Android.bp
index a48a314..0eba5ce 100644
--- a/ui/build/Android.bp
+++ b/ui/build/Android.bp
@@ -30,6 +30,7 @@
deps: [
"soong-ui-build-paths",
"soong-ui-logger",
+ "soong-ui-metrics",
"soong-ui-status",
"soong-ui-terminal",
"soong-ui-tracer",
diff --git a/ui/build/cleanbuild.go b/ui/build/cleanbuild.go
index 4dee638..c47f614 100644
--- a/ui/build/cleanbuild.go
+++ b/ui/build/cleanbuild.go
@@ -20,6 +20,8 @@
"os"
"path/filepath"
"strings"
+
+ "android/soong/ui/metrics"
)
func removeGlobs(ctx Context, globs ...string) {
@@ -158,7 +160,7 @@
return
}
- ctx.BeginTrace("installclean")
+ ctx.BeginTrace(metrics.PrimaryNinja, "installclean")
defer ctx.EndTrace()
prevConfig := strings.TrimPrefix(strings.TrimSuffix(string(prev), suffix), prefix)
diff --git a/ui/build/config.go b/ui/build/config.go
index 5a6d5db..97b009a 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -217,6 +217,9 @@
} else {
content = strconv.FormatInt(time.Now().Unix(), 10)
}
+ if ctx.Metrics != nil {
+ ctx.Metrics.SetBuildDateTime(content)
+ }
err := ioutil.WriteFile(buildDateTimeFile, []byte(content), 0777)
if err != nil {
ctx.Fatalln("Failed to write BUILD_DATETIME to file:", err)
diff --git a/ui/build/context.go b/ui/build/context.go
index c8b00c3..249e898 100644
--- a/ui/build/context.go
+++ b/ui/build/context.go
@@ -18,6 +18,8 @@
"context"
"android/soong/ui/logger"
+ "android/soong/ui/metrics"
+ "android/soong/ui/metrics/metrics_proto"
"android/soong/ui/status"
"android/soong/ui/terminal"
"android/soong/ui/tracer"
@@ -31,6 +33,8 @@
context.Context
logger.Logger
+ Metrics *metrics.Metrics
+
Writer terminal.Writer
Status *status.Status
@@ -39,9 +43,12 @@
}
// BeginTrace starts a new Duration Event.
-func (c ContextImpl) BeginTrace(name string) {
+func (c ContextImpl) BeginTrace(name, desc string) {
if c.Tracer != nil {
- c.Tracer.Begin(name, c.Thread)
+ c.Tracer.Begin(desc, c.Thread)
+ }
+ if c.Metrics != nil {
+ c.Metrics.TimeTracer.Begin(name, desc, c.Thread)
}
}
@@ -50,11 +57,23 @@
if c.Tracer != nil {
c.Tracer.End(c.Thread)
}
+ if c.Metrics != nil {
+ c.Metrics.SetTimeMetrics(c.Metrics.TimeTracer.End(c.Thread))
+ }
}
// CompleteTrace writes a trace with a beginning and end times.
-func (c ContextImpl) CompleteTrace(name string, begin, end uint64) {
+func (c ContextImpl) CompleteTrace(name, desc string, begin, end uint64) {
if c.Tracer != nil {
- c.Tracer.Complete(name, c.Thread, begin, end)
+ c.Tracer.Complete(desc, c.Thread, begin, end)
+ }
+ if c.Metrics != nil {
+ realTime := end - begin
+ c.Metrics.SetTimeMetrics(
+ metrics_proto.PerfInfo{
+ Desc: &desc,
+ Name: &name,
+ StartTime: &begin,
+ RealTime: &realTime})
}
}
diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go
index ad57d02..1ab855d 100644
--- a/ui/build/dumpvars.go
+++ b/ui/build/dumpvars.go
@@ -19,6 +19,7 @@
"fmt"
"strings"
+ "android/soong/ui/metrics"
"android/soong/ui/status"
)
@@ -69,7 +70,7 @@
}
func dumpMakeVars(ctx Context, config Config, goals, vars []string, write_soong_vars bool) (map[string]string, error) {
- ctx.BeginTrace("dumpvars")
+ ctx.BeginTrace(metrics.RunKati, "dumpvars")
defer ctx.EndTrace()
cmd := Command(ctx, config, "dumpvars",
@@ -113,6 +114,9 @@
return nil, fmt.Errorf("Failed to parse make line: %q", line)
}
}
+ if ctx.Metrics != nil {
+ ctx.Metrics.SetMetadataMetrics(ret)
+ }
return ret, nil
}
diff --git a/ui/build/finder.go b/ui/build/finder.go
index 3130f74..0f34b5e 100644
--- a/ui/build/finder.go
+++ b/ui/build/finder.go
@@ -23,6 +23,8 @@
"os"
"path/filepath"
"strings"
+
+ "android/soong/ui/metrics"
)
// This file provides an interface to the Finder for use in Soong UI
@@ -31,7 +33,7 @@
// NewSourceFinder returns a new Finder configured to search for source files.
// Callers of NewSourceFinder should call <f.Shutdown()> when done
func NewSourceFinder(ctx Context, config Config) (f *finder.Finder) {
- ctx.BeginTrace("find modules")
+ ctx.BeginTrace(metrics.RunSetupTool, "find modules")
defer ctx.EndTrace()
dir, err := os.Getwd()
diff --git a/ui/build/kati.go b/ui/build/kati.go
index d2e9fe9..205d5ae 100644
--- a/ui/build/kati.go
+++ b/ui/build/kati.go
@@ -21,6 +21,7 @@
"path/filepath"
"strings"
+ "android/soong/ui/metrics"
"android/soong/ui/status"
)
@@ -101,7 +102,7 @@
}
func runKatiBuild(ctx Context, config Config) {
- ctx.BeginTrace("kati build")
+ ctx.BeginTrace(metrics.RunKati, "kati build")
defer ctx.EndTrace()
args := []string{
@@ -137,7 +138,7 @@
}
func runKatiPackage(ctx Context, config Config) {
- ctx.BeginTrace("kati package")
+ ctx.BeginTrace(metrics.RunKati, "kati package")
defer ctx.EndTrace()
args := []string{
@@ -178,7 +179,7 @@
}
func runKatiCleanSpec(ctx Context, config Config) {
- ctx.BeginTrace("kati cleanspec")
+ ctx.BeginTrace(metrics.RunKati, "kati cleanspec")
defer ctx.EndTrace()
runKati(ctx, config, katiCleanspecSuffix, []string{
diff --git a/ui/build/ninja.go b/ui/build/ninja.go
index c8f19d1..e5d6da1 100644
--- a/ui/build/ninja.go
+++ b/ui/build/ninja.go
@@ -22,11 +22,12 @@
"strings"
"time"
+ "android/soong/ui/metrics"
"android/soong/ui/status"
)
func runNinja(ctx Context, config Config) {
- ctx.BeginTrace("ninja")
+ ctx.BeginTrace(metrics.PrimaryNinja, "ninja")
defer ctx.EndTrace()
fifo := filepath.Join(config.OutDir(), ".ninja_fifo")
@@ -97,6 +98,7 @@
}
}()
+ ctx.Status.Status("Starting ninja...")
cmd.RunAndPrintOrFatal()
}
diff --git a/ui/build/path.go b/ui/build/path.go
index 8260ff9..ee72cfd 100644
--- a/ui/build/path.go
+++ b/ui/build/path.go
@@ -25,6 +25,7 @@
"github.com/google/blueprint/microfactory"
"android/soong/ui/build/paths"
+ "android/soong/ui/metrics"
)
func parsePathDir(dir string) []string {
@@ -57,7 +58,7 @@
return
}
- ctx.BeginTrace("path")
+ ctx.BeginTrace(metrics.RunSetupTool, "path")
defer ctx.EndTrace()
origPath, _ := config.Environment().Get("PATH")
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 478c02c..c89f0d5 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -22,15 +22,16 @@
"github.com/google/blueprint/microfactory"
+ "android/soong/ui/metrics"
"android/soong/ui/status"
)
func runSoong(ctx Context, config Config) {
- ctx.BeginTrace("soong")
+ ctx.BeginTrace(metrics.RunSoong, "soong")
defer ctx.EndTrace()
func() {
- ctx.BeginTrace("blueprint bootstrap")
+ ctx.BeginTrace(metrics.RunSoong, "blueprint bootstrap")
defer ctx.EndTrace()
cmd := Command(ctx, config, "blueprint bootstrap", "build/blueprint/bootstrap.bash", "-t")
@@ -48,7 +49,7 @@
}()
func() {
- ctx.BeginTrace("environment check")
+ ctx.BeginTrace(metrics.RunSoong, "environment check")
defer ctx.EndTrace()
envFile := filepath.Join(config.SoongOutDir(), ".soong.environment")
@@ -84,7 +85,7 @@
cfg.TrimPath = absPath(ctx, ".")
func() {
- ctx.BeginTrace("minibp")
+ ctx.BeginTrace(metrics.RunSoong, "minibp")
defer ctx.EndTrace()
minibp := filepath.Join(config.SoongOutDir(), ".minibootstrap/minibp")
@@ -94,7 +95,7 @@
}()
func() {
- ctx.BeginTrace("bpglob")
+ ctx.BeginTrace(metrics.RunSoong, "bpglob")
defer ctx.EndTrace()
bpglob := filepath.Join(config.SoongOutDir(), ".minibootstrap/bpglob")
@@ -104,7 +105,7 @@
}()
ninja := func(name, file string) {
- ctx.BeginTrace(name)
+ ctx.BeginTrace(metrics.RunSoong, name)
defer ctx.EndTrace()
fifo := filepath.Join(config.OutDir(), ".ninja_fifo")
diff --git a/ui/build/test_build.go b/ui/build/test_build.go
index 348d41f..5109465 100644
--- a/ui/build/test_build.go
+++ b/ui/build/test_build.go
@@ -22,6 +22,7 @@
"sort"
"strings"
+ "android/soong/ui/metrics"
"android/soong/ui/status"
)
@@ -37,7 +38,7 @@
return
}
- ctx.BeginTrace("test for dangling rules")
+ ctx.BeginTrace(metrics.TestRun, "test for dangling rules")
defer ctx.EndTrace()
ts := ctx.Status.StartTool()
diff --git a/ui/metrics/Android.bp b/ui/metrics/Android.bp
new file mode 100644
index 0000000..529639d
--- /dev/null
+++ b/ui/metrics/Android.bp
@@ -0,0 +1,37 @@
+// Copyright 2018 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+bootstrap_go_package {
+ name: "soong-ui-metrics",
+ pkgPath: "android/soong/ui/metrics",
+ deps: [
+ "golang-protobuf-proto",
+ "soong-ui-metrics_proto",
+ "soong-ui-tracer",
+ ],
+ srcs: [
+ "metrics.go",
+ "time.go",
+ ],
+}
+
+bootstrap_go_package {
+ name: "soong-ui-metrics_proto",
+ pkgPath: "android/soong/ui/metrics/metrics_proto",
+ deps: ["golang-protobuf-proto"],
+ srcs: [
+ "metrics_proto/metrics.pb.go",
+ ],
+}
+
diff --git a/ui/metrics/metrics.go b/ui/metrics/metrics.go
new file mode 100644
index 0000000..790b67a
--- /dev/null
+++ b/ui/metrics/metrics.go
@@ -0,0 +1,161 @@
+// Copyright 2018 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package metrics
+
+import (
+ "io/ioutil"
+ "os"
+ "strconv"
+
+ "android/soong/ui/metrics/metrics_proto"
+
+ "github.com/golang/protobuf/proto"
+)
+
+const (
+ RunSetupTool = "setup"
+ RunKati = "kati"
+ RunSoong = "soong"
+ PrimaryNinja = "ninja"
+ TestRun = "test"
+)
+
+type Metrics struct {
+ metrics metrics_proto.MetricsBase
+ TimeTracer TimeTracer
+}
+
+func New() (metrics *Metrics) {
+ m := &Metrics{
+ metrics: metrics_proto.MetricsBase{},
+ TimeTracer: &timeTracerImpl{},
+ }
+ return m
+}
+
+func (m *Metrics) SetTimeMetrics(perf metrics_proto.PerfInfo) {
+ switch perf.GetName() {
+ case RunKati:
+ m.metrics.KatiRuns = append(m.metrics.KatiRuns, &perf)
+ break
+ case RunSoong:
+ m.metrics.SoongRuns = append(m.metrics.SoongRuns, &perf)
+ break
+ case PrimaryNinja:
+ m.metrics.NinjaRuns = append(m.metrics.NinjaRuns, &perf)
+ break
+ default:
+ // ignored
+ }
+}
+
+func (m *Metrics) SetMetadataMetrics(metadata map[string]string) {
+ for k, v := range metadata {
+ switch k {
+ case "BUILD_ID":
+ m.metrics.BuildId = proto.String(v)
+ break
+ case "PLATFORM_VERSION_CODENAME":
+ m.metrics.PlatformVersionCodename = proto.String(v)
+ break
+ case "TARGET_PRODUCT":
+ m.metrics.TargetProduct = proto.String(v)
+ break
+ case "TARGET_BUILD_VARIANT":
+ switch v {
+ case "user":
+ m.metrics.TargetBuildVariant = metrics_proto.MetricsBase_USER.Enum()
+ case "userdebug":
+ m.metrics.TargetBuildVariant = metrics_proto.MetricsBase_USERDEBUG.Enum()
+ case "eng":
+ m.metrics.TargetBuildVariant = metrics_proto.MetricsBase_ENG.Enum()
+ default:
+ // ignored
+ }
+ case "TARGET_ARCH":
+ m.metrics.TargetArch = m.getArch(v)
+ case "TARGET_ARCH_VARIANT":
+ m.metrics.TargetArchVariant = proto.String(v)
+ case "TARGET_CPU_VARIANT":
+ m.metrics.TargetCpuVariant = proto.String(v)
+ case "HOST_ARCH":
+ m.metrics.HostArch = m.getArch(v)
+ case "HOST_2ND_ARCH":
+ m.metrics.Host_2NdArch = m.getArch(v)
+ case "HOST_OS":
+ m.metrics.HostOs = proto.String(v)
+ case "HOST_OS_EXTRA":
+ m.metrics.HostOsExtra = proto.String(v)
+ case "HOST_CROSS_OS":
+ m.metrics.HostCrossOs = proto.String(v)
+ case "HOST_CROSS_ARCH":
+ m.metrics.HostCrossArch = proto.String(v)
+ case "HOST_CROSS_2ND_ARCH":
+ m.metrics.HostCross_2NdArch = proto.String(v)
+ case "OUT_DIR":
+ m.metrics.OutDir = proto.String(v)
+ default:
+ // ignored
+ }
+ }
+}
+
+func (m *Metrics) getArch(arch string) *metrics_proto.MetricsBase_ARCH {
+ switch arch {
+ case "arm":
+ return metrics_proto.MetricsBase_ARM.Enum()
+ case "arm64":
+ return metrics_proto.MetricsBase_ARM64.Enum()
+ case "x86":
+ return metrics_proto.MetricsBase_X86.Enum()
+ case "x86_64":
+ return metrics_proto.MetricsBase_X86_64.Enum()
+ default:
+ return metrics_proto.MetricsBase_UNKNOWN.Enum()
+ }
+}
+
+func (m *Metrics) SetBuildDateTime(date_time string) {
+ if date_time != "" {
+ date_time_timestamp, err := strconv.ParseInt(date_time, 10, 64)
+ if err != nil {
+ panic(err)
+ }
+ m.metrics.BuildDateTimestamp = &date_time_timestamp
+ }
+}
+
+func (m *Metrics) Serialize() (data []byte, err error) {
+ return proto.Marshal(&m.metrics)
+}
+
+// exports the output to the file at outputPath
+func (m *Metrics) Dump(outputPath string) (err error) {
+ data, err := m.Serialize()
+ if err != nil {
+ return err
+ }
+ tempPath := outputPath + ".tmp"
+ err = ioutil.WriteFile(tempPath, []byte(data), 0777)
+ if err != nil {
+ return err
+ }
+ err = os.Rename(tempPath, outputPath)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
diff --git a/ui/metrics/metrics_proto/metrics.pb.go b/ui/metrics/metrics_proto/metrics.pb.go
new file mode 100644
index 0000000..feefc89
--- /dev/null
+++ b/ui/metrics/metrics_proto/metrics.pb.go
@@ -0,0 +1,557 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// source: metrics.proto
+
+package metrics_proto
+
+import proto "github.com/golang/protobuf/proto"
+import fmt "fmt"
+import math "math"
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ = proto.Marshal
+var _ = fmt.Errorf
+var _ = math.Inf
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the proto package it is being compiled against.
+// A compilation error at this line likely means your copy of the
+// proto package needs to be updated.
+const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
+
+type MetricsBase_BUILDVARIANT int32
+
+const (
+ MetricsBase_USER MetricsBase_BUILDVARIANT = 0
+ MetricsBase_USERDEBUG MetricsBase_BUILDVARIANT = 1
+ MetricsBase_ENG MetricsBase_BUILDVARIANT = 2
+)
+
+var MetricsBase_BUILDVARIANT_name = map[int32]string{
+ 0: "USER",
+ 1: "USERDEBUG",
+ 2: "ENG",
+}
+var MetricsBase_BUILDVARIANT_value = map[string]int32{
+ "USER": 0,
+ "USERDEBUG": 1,
+ "ENG": 2,
+}
+
+func (x MetricsBase_BUILDVARIANT) Enum() *MetricsBase_BUILDVARIANT {
+ p := new(MetricsBase_BUILDVARIANT)
+ *p = x
+ return p
+}
+func (x MetricsBase_BUILDVARIANT) String() string {
+ return proto.EnumName(MetricsBase_BUILDVARIANT_name, int32(x))
+}
+func (x *MetricsBase_BUILDVARIANT) UnmarshalJSON(data []byte) error {
+ value, err := proto.UnmarshalJSONEnum(MetricsBase_BUILDVARIANT_value, data, "MetricsBase_BUILDVARIANT")
+ if err != nil {
+ return err
+ }
+ *x = MetricsBase_BUILDVARIANT(value)
+ return nil
+}
+func (MetricsBase_BUILDVARIANT) EnumDescriptor() ([]byte, []int) {
+ return fileDescriptor_metrics_9e7b895801991242, []int{0, 0}
+}
+
+type MetricsBase_ARCH int32
+
+const (
+ MetricsBase_UNKNOWN MetricsBase_ARCH = 0
+ MetricsBase_ARM MetricsBase_ARCH = 1
+ MetricsBase_ARM64 MetricsBase_ARCH = 2
+ MetricsBase_X86 MetricsBase_ARCH = 3
+ MetricsBase_X86_64 MetricsBase_ARCH = 4
+)
+
+var MetricsBase_ARCH_name = map[int32]string{
+ 0: "UNKNOWN",
+ 1: "ARM",
+ 2: "ARM64",
+ 3: "X86",
+ 4: "X86_64",
+}
+var MetricsBase_ARCH_value = map[string]int32{
+ "UNKNOWN": 0,
+ "ARM": 1,
+ "ARM64": 2,
+ "X86": 3,
+ "X86_64": 4,
+}
+
+func (x MetricsBase_ARCH) Enum() *MetricsBase_ARCH {
+ p := new(MetricsBase_ARCH)
+ *p = x
+ return p
+}
+func (x MetricsBase_ARCH) String() string {
+ return proto.EnumName(MetricsBase_ARCH_name, int32(x))
+}
+func (x *MetricsBase_ARCH) UnmarshalJSON(data []byte) error {
+ value, err := proto.UnmarshalJSONEnum(MetricsBase_ARCH_value, data, "MetricsBase_ARCH")
+ if err != nil {
+ return err
+ }
+ *x = MetricsBase_ARCH(value)
+ return nil
+}
+func (MetricsBase_ARCH) EnumDescriptor() ([]byte, []int) {
+ return fileDescriptor_metrics_9e7b895801991242, []int{0, 1}
+}
+
+type ModuleTypeInfo_BUILDSYSTEM int32
+
+const (
+ ModuleTypeInfo_UNKNOWN ModuleTypeInfo_BUILDSYSTEM = 0
+ ModuleTypeInfo_SOONG ModuleTypeInfo_BUILDSYSTEM = 1
+ ModuleTypeInfo_MAKE ModuleTypeInfo_BUILDSYSTEM = 2
+)
+
+var ModuleTypeInfo_BUILDSYSTEM_name = map[int32]string{
+ 0: "UNKNOWN",
+ 1: "SOONG",
+ 2: "MAKE",
+}
+var ModuleTypeInfo_BUILDSYSTEM_value = map[string]int32{
+ "UNKNOWN": 0,
+ "SOONG": 1,
+ "MAKE": 2,
+}
+
+func (x ModuleTypeInfo_BUILDSYSTEM) Enum() *ModuleTypeInfo_BUILDSYSTEM {
+ p := new(ModuleTypeInfo_BUILDSYSTEM)
+ *p = x
+ return p
+}
+func (x ModuleTypeInfo_BUILDSYSTEM) String() string {
+ return proto.EnumName(ModuleTypeInfo_BUILDSYSTEM_name, int32(x))
+}
+func (x *ModuleTypeInfo_BUILDSYSTEM) UnmarshalJSON(data []byte) error {
+ value, err := proto.UnmarshalJSONEnum(ModuleTypeInfo_BUILDSYSTEM_value, data, "ModuleTypeInfo_BUILDSYSTEM")
+ if err != nil {
+ return err
+ }
+ *x = ModuleTypeInfo_BUILDSYSTEM(value)
+ return nil
+}
+func (ModuleTypeInfo_BUILDSYSTEM) EnumDescriptor() ([]byte, []int) {
+ return fileDescriptor_metrics_9e7b895801991242, []int{2, 0}
+}
+
+type MetricsBase struct {
+ // Timestamp generated when the build starts.
+ BuildDateTimestamp *int64 `protobuf:"varint,1,opt,name=build_date_timestamp,json=buildDateTimestamp" json:"build_date_timestamp,omitempty"`
+ // It is usually used to specify the branch name [and release candidate].
+ BuildId *string `protobuf:"bytes,2,opt,name=build_id,json=buildId" json:"build_id,omitempty"`
+ // The platform version codename, eg. P, Q, REL.
+ PlatformVersionCodename *string `protobuf:"bytes,3,opt,name=platform_version_codename,json=platformVersionCodename" json:"platform_version_codename,omitempty"`
+ // The target product information, eg. aosp_arm.
+ TargetProduct *string `protobuf:"bytes,4,opt,name=target_product,json=targetProduct" json:"target_product,omitempty"`
+ // The target build variant information, eg. eng.
+ TargetBuildVariant *MetricsBase_BUILDVARIANT `protobuf:"varint,5,opt,name=target_build_variant,json=targetBuildVariant,enum=build_metrics.MetricsBase_BUILDVARIANT,def=2" json:"target_build_variant,omitempty"`
+ // The target arch information, eg. arm.
+ TargetArch *MetricsBase_ARCH `protobuf:"varint,6,opt,name=target_arch,json=targetArch,enum=build_metrics.MetricsBase_ARCH,def=0" json:"target_arch,omitempty"`
+ // The target arch variant information, eg. armv7-a-neon.
+ TargetArchVariant *string `protobuf:"bytes,7,opt,name=target_arch_variant,json=targetArchVariant" json:"target_arch_variant,omitempty"`
+ // The target cpu variant information, eg. generic.
+ TargetCpuVariant *string `protobuf:"bytes,8,opt,name=target_cpu_variant,json=targetCpuVariant" json:"target_cpu_variant,omitempty"`
+ // The host arch information, eg. x86_64.
+ HostArch *MetricsBase_ARCH `protobuf:"varint,9,opt,name=host_arch,json=hostArch,enum=build_metrics.MetricsBase_ARCH,def=0" json:"host_arch,omitempty"`
+ // The host 2nd arch information, eg. x86.
+ Host_2NdArch *MetricsBase_ARCH `protobuf:"varint,10,opt,name=host_2nd_arch,json=host2ndArch,enum=build_metrics.MetricsBase_ARCH,def=0" json:"host_2nd_arch,omitempty"`
+ // The host os information, eg. linux.
+ HostOs *string `protobuf:"bytes,11,opt,name=host_os,json=hostOs" json:"host_os,omitempty"`
+ // The host os extra information, eg. Linux-4.17.0-3rodete2-amd64-x86_64-Debian-GNU.
+ HostOsExtra *string `protobuf:"bytes,12,opt,name=host_os_extra,json=hostOsExtra" json:"host_os_extra,omitempty"`
+ // The host cross os information, eg. windows.
+ HostCrossOs *string `protobuf:"bytes,13,opt,name=host_cross_os,json=hostCrossOs" json:"host_cross_os,omitempty"`
+ // The host cross arch information, eg. x86.
+ HostCrossArch *string `protobuf:"bytes,14,opt,name=host_cross_arch,json=hostCrossArch" json:"host_cross_arch,omitempty"`
+ // The host cross 2nd arch information, eg. x86_64.
+ HostCross_2NdArch *string `protobuf:"bytes,15,opt,name=host_cross_2nd_arch,json=hostCross2ndArch" json:"host_cross_2nd_arch,omitempty"`
+ // The directory for generated built artifacts installation, eg. out.
+ OutDir *string `protobuf:"bytes,16,opt,name=out_dir,json=outDir" json:"out_dir,omitempty"`
+ // The metrics for calling various tools (microfactory) before Soong_UI starts.
+ SetupTools []*PerfInfo `protobuf:"bytes,17,rep,name=setup_tools,json=setupTools" json:"setup_tools,omitempty"`
+ // The metrics for calling Kati by multiple times.
+ KatiRuns []*PerfInfo `protobuf:"bytes,18,rep,name=kati_runs,json=katiRuns" json:"kati_runs,omitempty"`
+ // The metrics for calling Soong.
+ SoongRuns []*PerfInfo `protobuf:"bytes,19,rep,name=soong_runs,json=soongRuns" json:"soong_runs,omitempty"`
+ // The metrics for calling Ninja.
+ NinjaRuns []*PerfInfo `protobuf:"bytes,20,rep,name=ninja_runs,json=ninjaRuns" json:"ninja_runs,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized []byte `json:"-"`
+ XXX_sizecache int32 `json:"-"`
+}
+
+func (m *MetricsBase) Reset() { *m = MetricsBase{} }
+func (m *MetricsBase) String() string { return proto.CompactTextString(m) }
+func (*MetricsBase) ProtoMessage() {}
+func (*MetricsBase) Descriptor() ([]byte, []int) {
+ return fileDescriptor_metrics_9e7b895801991242, []int{0}
+}
+func (m *MetricsBase) XXX_Unmarshal(b []byte) error {
+ return xxx_messageInfo_MetricsBase.Unmarshal(m, b)
+}
+func (m *MetricsBase) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+ return xxx_messageInfo_MetricsBase.Marshal(b, m, deterministic)
+}
+func (dst *MetricsBase) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_MetricsBase.Merge(dst, src)
+}
+func (m *MetricsBase) XXX_Size() int {
+ return xxx_messageInfo_MetricsBase.Size(m)
+}
+func (m *MetricsBase) XXX_DiscardUnknown() {
+ xxx_messageInfo_MetricsBase.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_MetricsBase proto.InternalMessageInfo
+
+const Default_MetricsBase_TargetBuildVariant MetricsBase_BUILDVARIANT = MetricsBase_ENG
+const Default_MetricsBase_TargetArch MetricsBase_ARCH = MetricsBase_UNKNOWN
+const Default_MetricsBase_HostArch MetricsBase_ARCH = MetricsBase_UNKNOWN
+const Default_MetricsBase_Host_2NdArch MetricsBase_ARCH = MetricsBase_UNKNOWN
+
+func (m *MetricsBase) GetBuildDateTimestamp() int64 {
+ if m != nil && m.BuildDateTimestamp != nil {
+ return *m.BuildDateTimestamp
+ }
+ return 0
+}
+
+func (m *MetricsBase) GetBuildId() string {
+ if m != nil && m.BuildId != nil {
+ return *m.BuildId
+ }
+ return ""
+}
+
+func (m *MetricsBase) GetPlatformVersionCodename() string {
+ if m != nil && m.PlatformVersionCodename != nil {
+ return *m.PlatformVersionCodename
+ }
+ return ""
+}
+
+func (m *MetricsBase) GetTargetProduct() string {
+ if m != nil && m.TargetProduct != nil {
+ return *m.TargetProduct
+ }
+ return ""
+}
+
+func (m *MetricsBase) GetTargetBuildVariant() MetricsBase_BUILDVARIANT {
+ if m != nil && m.TargetBuildVariant != nil {
+ return *m.TargetBuildVariant
+ }
+ return Default_MetricsBase_TargetBuildVariant
+}
+
+func (m *MetricsBase) GetTargetArch() MetricsBase_ARCH {
+ if m != nil && m.TargetArch != nil {
+ return *m.TargetArch
+ }
+ return Default_MetricsBase_TargetArch
+}
+
+func (m *MetricsBase) GetTargetArchVariant() string {
+ if m != nil && m.TargetArchVariant != nil {
+ return *m.TargetArchVariant
+ }
+ return ""
+}
+
+func (m *MetricsBase) GetTargetCpuVariant() string {
+ if m != nil && m.TargetCpuVariant != nil {
+ return *m.TargetCpuVariant
+ }
+ return ""
+}
+
+func (m *MetricsBase) GetHostArch() MetricsBase_ARCH {
+ if m != nil && m.HostArch != nil {
+ return *m.HostArch
+ }
+ return Default_MetricsBase_HostArch
+}
+
+func (m *MetricsBase) GetHost_2NdArch() MetricsBase_ARCH {
+ if m != nil && m.Host_2NdArch != nil {
+ return *m.Host_2NdArch
+ }
+ return Default_MetricsBase_Host_2NdArch
+}
+
+func (m *MetricsBase) GetHostOs() string {
+ if m != nil && m.HostOs != nil {
+ return *m.HostOs
+ }
+ return ""
+}
+
+func (m *MetricsBase) GetHostOsExtra() string {
+ if m != nil && m.HostOsExtra != nil {
+ return *m.HostOsExtra
+ }
+ return ""
+}
+
+func (m *MetricsBase) GetHostCrossOs() string {
+ if m != nil && m.HostCrossOs != nil {
+ return *m.HostCrossOs
+ }
+ return ""
+}
+
+func (m *MetricsBase) GetHostCrossArch() string {
+ if m != nil && m.HostCrossArch != nil {
+ return *m.HostCrossArch
+ }
+ return ""
+}
+
+func (m *MetricsBase) GetHostCross_2NdArch() string {
+ if m != nil && m.HostCross_2NdArch != nil {
+ return *m.HostCross_2NdArch
+ }
+ return ""
+}
+
+func (m *MetricsBase) GetOutDir() string {
+ if m != nil && m.OutDir != nil {
+ return *m.OutDir
+ }
+ return ""
+}
+
+func (m *MetricsBase) GetSetupTools() []*PerfInfo {
+ if m != nil {
+ return m.SetupTools
+ }
+ return nil
+}
+
+func (m *MetricsBase) GetKatiRuns() []*PerfInfo {
+ if m != nil {
+ return m.KatiRuns
+ }
+ return nil
+}
+
+func (m *MetricsBase) GetSoongRuns() []*PerfInfo {
+ if m != nil {
+ return m.SoongRuns
+ }
+ return nil
+}
+
+func (m *MetricsBase) GetNinjaRuns() []*PerfInfo {
+ if m != nil {
+ return m.NinjaRuns
+ }
+ return nil
+}
+
+type PerfInfo struct {
+ // The description for the phase/action/part while the tool running.
+ Desc *string `protobuf:"bytes,1,opt,name=desc" json:"desc,omitempty"`
+ // The name for the running phase/action/part.
+ Name *string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
+ // The absolute start time.
+ // The number of nanoseconds elapsed since January 1, 1970 UTC.
+ StartTime *uint64 `protobuf:"varint,3,opt,name=start_time,json=startTime" json:"start_time,omitempty"`
+ // The real running time.
+ // The number of nanoseconds elapsed since start_time.
+ RealTime *uint64 `protobuf:"varint,4,opt,name=real_time,json=realTime" json:"real_time,omitempty"`
+ // The number of MB for memory use.
+ MemoryUse *uint64 `protobuf:"varint,5,opt,name=memory_use,json=memoryUse" json:"memory_use,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized []byte `json:"-"`
+ XXX_sizecache int32 `json:"-"`
+}
+
+func (m *PerfInfo) Reset() { *m = PerfInfo{} }
+func (m *PerfInfo) String() string { return proto.CompactTextString(m) }
+func (*PerfInfo) ProtoMessage() {}
+func (*PerfInfo) Descriptor() ([]byte, []int) {
+ return fileDescriptor_metrics_9e7b895801991242, []int{1}
+}
+func (m *PerfInfo) XXX_Unmarshal(b []byte) error {
+ return xxx_messageInfo_PerfInfo.Unmarshal(m, b)
+}
+func (m *PerfInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+ return xxx_messageInfo_PerfInfo.Marshal(b, m, deterministic)
+}
+func (dst *PerfInfo) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_PerfInfo.Merge(dst, src)
+}
+func (m *PerfInfo) XXX_Size() int {
+ return xxx_messageInfo_PerfInfo.Size(m)
+}
+func (m *PerfInfo) XXX_DiscardUnknown() {
+ xxx_messageInfo_PerfInfo.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_PerfInfo proto.InternalMessageInfo
+
+func (m *PerfInfo) GetDesc() string {
+ if m != nil && m.Desc != nil {
+ return *m.Desc
+ }
+ return ""
+}
+
+func (m *PerfInfo) GetName() string {
+ if m != nil && m.Name != nil {
+ return *m.Name
+ }
+ return ""
+}
+
+func (m *PerfInfo) GetStartTime() uint64 {
+ if m != nil && m.StartTime != nil {
+ return *m.StartTime
+ }
+ return 0
+}
+
+func (m *PerfInfo) GetRealTime() uint64 {
+ if m != nil && m.RealTime != nil {
+ return *m.RealTime
+ }
+ return 0
+}
+
+func (m *PerfInfo) GetMemoryUse() uint64 {
+ if m != nil && m.MemoryUse != nil {
+ return *m.MemoryUse
+ }
+ return 0
+}
+
+type ModuleTypeInfo struct {
+ // The build system, eg. Soong or Make.
+ BuildSystem *ModuleTypeInfo_BUILDSYSTEM `protobuf:"varint,1,opt,name=build_system,json=buildSystem,enum=build_metrics.ModuleTypeInfo_BUILDSYSTEM,def=0" json:"build_system,omitempty"`
+ // The module type, eg. java_library, cc_binary, and etc.
+ ModuleType *string `protobuf:"bytes,2,opt,name=module_type,json=moduleType" json:"module_type,omitempty"`
+ // The number of logical modules.
+ NumOfModules *uint32 `protobuf:"varint,3,opt,name=num_of_modules,json=numOfModules" json:"num_of_modules,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized []byte `json:"-"`
+ XXX_sizecache int32 `json:"-"`
+}
+
+func (m *ModuleTypeInfo) Reset() { *m = ModuleTypeInfo{} }
+func (m *ModuleTypeInfo) String() string { return proto.CompactTextString(m) }
+func (*ModuleTypeInfo) ProtoMessage() {}
+func (*ModuleTypeInfo) Descriptor() ([]byte, []int) {
+ return fileDescriptor_metrics_9e7b895801991242, []int{2}
+}
+func (m *ModuleTypeInfo) XXX_Unmarshal(b []byte) error {
+ return xxx_messageInfo_ModuleTypeInfo.Unmarshal(m, b)
+}
+func (m *ModuleTypeInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+ return xxx_messageInfo_ModuleTypeInfo.Marshal(b, m, deterministic)
+}
+func (dst *ModuleTypeInfo) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_ModuleTypeInfo.Merge(dst, src)
+}
+func (m *ModuleTypeInfo) XXX_Size() int {
+ return xxx_messageInfo_ModuleTypeInfo.Size(m)
+}
+func (m *ModuleTypeInfo) XXX_DiscardUnknown() {
+ xxx_messageInfo_ModuleTypeInfo.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_ModuleTypeInfo proto.InternalMessageInfo
+
+const Default_ModuleTypeInfo_BuildSystem ModuleTypeInfo_BUILDSYSTEM = ModuleTypeInfo_UNKNOWN
+
+func (m *ModuleTypeInfo) GetBuildSystem() ModuleTypeInfo_BUILDSYSTEM {
+ if m != nil && m.BuildSystem != nil {
+ return *m.BuildSystem
+ }
+ return Default_ModuleTypeInfo_BuildSystem
+}
+
+func (m *ModuleTypeInfo) GetModuleType() string {
+ if m != nil && m.ModuleType != nil {
+ return *m.ModuleType
+ }
+ return ""
+}
+
+func (m *ModuleTypeInfo) GetNumOfModules() uint32 {
+ if m != nil && m.NumOfModules != nil {
+ return *m.NumOfModules
+ }
+ return 0
+}
+
+func init() {
+ proto.RegisterType((*MetricsBase)(nil), "build_metrics.MetricsBase")
+ proto.RegisterType((*PerfInfo)(nil), "build_metrics.PerfInfo")
+ proto.RegisterType((*ModuleTypeInfo)(nil), "build_metrics.ModuleTypeInfo")
+ proto.RegisterEnum("build_metrics.MetricsBase_BUILDVARIANT", MetricsBase_BUILDVARIANT_name, MetricsBase_BUILDVARIANT_value)
+ proto.RegisterEnum("build_metrics.MetricsBase_ARCH", MetricsBase_ARCH_name, MetricsBase_ARCH_value)
+ proto.RegisterEnum("build_metrics.ModuleTypeInfo_BUILDSYSTEM", ModuleTypeInfo_BUILDSYSTEM_name, ModuleTypeInfo_BUILDSYSTEM_value)
+}
+
+func init() { proto.RegisterFile("metrics.proto", fileDescriptor_metrics_9e7b895801991242) }
+
+var fileDescriptor_metrics_9e7b895801991242 = []byte{
+ // 783 bytes of a gzipped FileDescriptorProto
+ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xdd, 0x6e, 0xdb, 0x36,
+ 0x14, 0xae, 0x62, 0x25, 0x96, 0x8e, 0x62, 0x57, 0x61, 0x02, 0x44, 0xc5, 0x50, 0x34, 0x30, 0xf6,
+ 0x93, 0x01, 0x9b, 0x57, 0x18, 0x81, 0x11, 0x04, 0xbb, 0xb1, 0x13, 0xa3, 0x35, 0x5a, 0xdb, 0x85,
+ 0x6c, 0x67, 0xdd, 0x2e, 0x46, 0x68, 0x12, 0xdd, 0x68, 0xb3, 0x44, 0x81, 0xa4, 0x8a, 0xf9, 0x21,
+ 0xf6, 0x8c, 0x7b, 0x91, 0x5d, 0x0c, 0x3c, 0xb4, 0x5c, 0xa5, 0x17, 0x29, 0x72, 0x47, 0x9d, 0xef,
+ 0x87, 0xdf, 0x91, 0xc8, 0x23, 0x68, 0x65, 0x4c, 0x89, 0x34, 0x96, 0xdd, 0x42, 0x70, 0xc5, 0x49,
+ 0xeb, 0x8f, 0x32, 0x5d, 0x27, 0x74, 0x5b, 0xec, 0xfc, 0xe7, 0x80, 0x37, 0x31, 0xeb, 0x61, 0x24,
+ 0x19, 0x79, 0x09, 0x27, 0x86, 0x90, 0x44, 0x8a, 0x51, 0x95, 0x66, 0x4c, 0xaa, 0x28, 0x2b, 0x02,
+ 0xeb, 0xcc, 0x3a, 0x6f, 0x84, 0x04, 0xb1, 0x9b, 0x48, 0xb1, 0x45, 0x85, 0x90, 0x67, 0xe0, 0x18,
+ 0x45, 0x9a, 0x04, 0x7b, 0x67, 0xd6, 0xb9, 0x1b, 0x36, 0xf1, 0x79, 0x9c, 0x90, 0x2b, 0x78, 0x56,
+ 0xac, 0x23, 0xb5, 0xe2, 0x22, 0xa3, 0x1f, 0x99, 0x90, 0x29, 0xcf, 0x69, 0xcc, 0x13, 0x96, 0x47,
+ 0x19, 0x0b, 0x1a, 0xc8, 0x3d, 0xad, 0x08, 0xb7, 0x06, 0xbf, 0xde, 0xc2, 0xe4, 0x1b, 0x68, 0xab,
+ 0x48, 0x7c, 0x60, 0x8a, 0x16, 0x82, 0x27, 0x65, 0xac, 0x02, 0x1b, 0x05, 0x2d, 0x53, 0x7d, 0x67,
+ 0x8a, 0xe4, 0x77, 0x38, 0xd9, 0xd2, 0x4c, 0x88, 0x8f, 0x91, 0x48, 0xa3, 0x5c, 0x05, 0xfb, 0x67,
+ 0xd6, 0x79, 0xbb, 0xf7, 0x5d, 0xf7, 0x5e, 0xb7, 0xdd, 0x5a, 0xa7, 0xdd, 0xe1, 0x72, 0xfc, 0xf6,
+ 0xe6, 0x76, 0x10, 0x8e, 0x07, 0xd3, 0xc5, 0x55, 0x63, 0x34, 0x7d, 0x15, 0x12, 0xe3, 0x34, 0xd4,
+ 0x92, 0x5b, 0xe3, 0x43, 0xc6, 0xe0, 0x6d, 0xfd, 0x23, 0x11, 0xdf, 0x05, 0x07, 0x68, 0xfb, 0xe2,
+ 0x01, 0xdb, 0x41, 0x78, 0xfd, 0xfa, 0xaa, 0xb9, 0x9c, 0xbe, 0x99, 0xce, 0x7e, 0x99, 0x86, 0x60,
+ 0xc4, 0x03, 0x11, 0xdf, 0x91, 0x2e, 0x1c, 0xd7, 0xac, 0x76, 0x49, 0x9b, 0xd8, 0xd6, 0xd1, 0x27,
+ 0x62, 0xb5, 0xf5, 0x0f, 0xb0, 0x0d, 0x44, 0xe3, 0xa2, 0xdc, 0xd1, 0x1d, 0xa4, 0xfb, 0x06, 0xb9,
+ 0x2e, 0xca, 0x8a, 0x3d, 0x02, 0xf7, 0x8e, 0xcb, 0x6d, 0x4c, 0xf7, 0x91, 0x31, 0x1d, 0x2d, 0xc5,
+ 0x90, 0x6f, 0xa1, 0x85, 0x36, 0xbd, 0x3c, 0x31, 0x56, 0xf0, 0x48, 0x2b, 0x4f, 0xcb, 0x7b, 0x79,
+ 0x82, 0x6e, 0xa7, 0xd0, 0x44, 0x37, 0x2e, 0x03, 0x0f, 0x73, 0x1f, 0xe8, 0xc7, 0x99, 0x24, 0x9d,
+ 0xed, 0x36, 0x5c, 0x52, 0xf6, 0xb7, 0x12, 0x51, 0x70, 0x88, 0xb0, 0x67, 0xe0, 0x91, 0x2e, 0xed,
+ 0x38, 0xb1, 0xe0, 0x52, 0x6a, 0x8b, 0xd6, 0x27, 0xce, 0xb5, 0xae, 0xcd, 0x24, 0xf9, 0x16, 0x9e,
+ 0xd6, 0x38, 0x18, 0xb8, 0x6d, 0x8e, 0xc9, 0x8e, 0x85, 0x41, 0x7e, 0x84, 0xe3, 0x1a, 0x6f, 0xd7,
+ 0xdc, 0x53, 0xf3, 0x32, 0x77, 0xdc, 0x5a, 0x6e, 0x5e, 0x2a, 0x9a, 0xa4, 0x22, 0xf0, 0x4d, 0x6e,
+ 0x5e, 0xaa, 0x9b, 0x54, 0x90, 0x4b, 0xf0, 0x24, 0x53, 0x65, 0x41, 0x15, 0xe7, 0x6b, 0x19, 0x1c,
+ 0x9d, 0x35, 0xce, 0xbd, 0xde, 0xe9, 0x67, 0x2f, 0xe7, 0x1d, 0x13, 0xab, 0x71, 0xbe, 0xe2, 0x21,
+ 0x20, 0x77, 0xa1, 0xa9, 0xe4, 0x02, 0xdc, 0xbf, 0x22, 0x95, 0x52, 0x51, 0xe6, 0x32, 0x20, 0x0f,
+ 0xeb, 0x1c, 0xcd, 0x0c, 0xcb, 0x5c, 0x92, 0x3e, 0x80, 0xe4, 0x3c, 0xff, 0x60, 0x64, 0xc7, 0x0f,
+ 0xcb, 0x5c, 0xa4, 0x56, 0xba, 0x3c, 0xcd, 0xff, 0x8c, 0x8c, 0xee, 0xe4, 0x0b, 0x3a, 0xa4, 0x6a,
+ 0x5d, 0xe7, 0x25, 0x1c, 0xd6, 0xef, 0x05, 0x71, 0xc0, 0x5e, 0xce, 0x47, 0xa1, 0xff, 0x84, 0xb4,
+ 0xc0, 0xd5, 0xab, 0x9b, 0xd1, 0x70, 0xf9, 0xca, 0xb7, 0x48, 0x13, 0xf4, 0x95, 0xf1, 0xf7, 0x3a,
+ 0x3f, 0x83, 0xad, 0x0f, 0x00, 0xf1, 0xa0, 0x3a, 0x02, 0xfe, 0x13, 0x8d, 0x0e, 0xc2, 0x89, 0x6f,
+ 0x11, 0x17, 0xf6, 0x07, 0xe1, 0xa4, 0x7f, 0xe1, 0xef, 0xe9, 0xda, 0xfb, 0xcb, 0xbe, 0xdf, 0x20,
+ 0x00, 0x07, 0xef, 0x2f, 0xfb, 0xb4, 0x7f, 0xe1, 0xdb, 0x9d, 0x7f, 0x2c, 0x70, 0xaa, 0x1c, 0x84,
+ 0x80, 0x9d, 0x30, 0x19, 0xe3, 0xac, 0x71, 0x43, 0x5c, 0xeb, 0x1a, 0x4e, 0x0b, 0x33, 0x59, 0x70,
+ 0x4d, 0x9e, 0x03, 0x48, 0x15, 0x09, 0x85, 0xe3, 0x09, 0xe7, 0x88, 0x1d, 0xba, 0x58, 0xd1, 0x53,
+ 0x89, 0x7c, 0x05, 0xae, 0x60, 0xd1, 0xda, 0xa0, 0x36, 0xa2, 0x8e, 0x2e, 0x20, 0xf8, 0x1c, 0x20,
+ 0x63, 0x19, 0x17, 0x1b, 0x5a, 0x4a, 0x86, 0x53, 0xc2, 0x0e, 0x5d, 0x53, 0x59, 0x4a, 0xd6, 0xf9,
+ 0xd7, 0x82, 0xf6, 0x84, 0x27, 0xe5, 0x9a, 0x2d, 0x36, 0x05, 0xc3, 0x54, 0x4b, 0x38, 0x34, 0xef,
+ 0x4d, 0x6e, 0xa4, 0x62, 0x19, 0xa6, 0x6b, 0xf7, 0xbe, 0xff, 0xfc, 0x42, 0xdc, 0x13, 0x99, 0xe1,
+ 0x32, 0xff, 0x75, 0xbe, 0x18, 0x4d, 0x6a, 0x57, 0x03, 0x25, 0x73, 0xb4, 0x21, 0x2f, 0xc0, 0xcb,
+ 0x50, 0x43, 0xd5, 0xa6, 0xa8, 0xfa, 0x83, 0x6c, 0x67, 0x43, 0xbe, 0x86, 0x76, 0x5e, 0x66, 0x94,
+ 0xaf, 0xa8, 0x29, 0x4a, 0xec, 0xb4, 0x15, 0x1e, 0xe6, 0x65, 0x36, 0x5b, 0x99, 0xfd, 0x64, 0xe7,
+ 0x27, 0xf0, 0x6a, 0x7b, 0xdd, 0xff, 0x0a, 0x2e, 0xec, 0xcf, 0x67, 0xb3, 0xa9, 0xfe, 0x5c, 0x0e,
+ 0xd8, 0x93, 0xc1, 0x9b, 0x91, 0xbf, 0x37, 0x3c, 0x7a, 0xdd, 0xf8, 0xad, 0xfa, 0x25, 0x50, 0xfc,
+ 0x25, 0xfc, 0x1f, 0x00, 0x00, 0xff, 0xff, 0xd4, 0x8d, 0x19, 0x89, 0x22, 0x06, 0x00, 0x00,
+}
diff --git a/ui/metrics/metrics_proto/metrics.proto b/ui/metrics/metrics_proto/metrics.proto
new file mode 100644
index 0000000..b3de2f4
--- /dev/null
+++ b/ui/metrics/metrics_proto/metrics.proto
@@ -0,0 +1,129 @@
+// Copyright 2018 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+syntax = "proto2";
+
+option optimize_for = LITE_RUNTIME;
+
+package build_metrics;
+option go_package = "metrics_proto";
+
+message MetricsBase {
+ // Timestamp generated when the build starts.
+ optional int64 build_date_timestamp = 1;
+
+ // It is usually used to specify the branch name [and release candidate].
+ optional string build_id = 2;
+
+ // The platform version codename, eg. P, Q, REL.
+ optional string platform_version_codename = 3;
+
+ // The target product information, eg. aosp_arm.
+ optional string target_product = 4;
+
+ enum BUILDVARIANT {
+ USER = 0;
+ USERDEBUG = 1;
+ ENG = 2;
+ }
+ // The target build variant information, eg. eng.
+ optional BUILDVARIANT target_build_variant = 5 [default = ENG];
+
+ enum ARCH {
+ UNKNOWN = 0;
+ ARM = 1;
+ ARM64 = 2;
+ X86 = 3;
+ X86_64 = 4;
+ }
+ // The target arch information, eg. arm.
+ optional ARCH target_arch = 6 [default = UNKNOWN];
+
+ // The target arch variant information, eg. armv7-a-neon.
+ optional string target_arch_variant = 7;
+
+ // The target cpu variant information, eg. generic.
+ optional string target_cpu_variant = 8;
+
+ // The host arch information, eg. x86_64.
+ optional ARCH host_arch = 9 [default = UNKNOWN];
+
+ // The host 2nd arch information, eg. x86.
+ optional ARCH host_2nd_arch = 10 [default = UNKNOWN];
+
+ // The host os information, eg. linux.
+ optional string host_os = 11;
+
+ // The host os extra information, eg. Linux-4.17.0-3rodete2-amd64-x86_64-Debian-GNU.
+ optional string host_os_extra = 12;
+
+ // The host cross os information, eg. windows.
+ optional string host_cross_os = 13;
+
+ // The host cross arch information, eg. x86.
+ optional string host_cross_arch = 14;
+
+ // The host cross 2nd arch information, eg. x86_64.
+ optional string host_cross_2nd_arch = 15;
+
+ // The directory for generated built artifacts installation, eg. out.
+ optional string out_dir = 16;
+
+ // The metrics for calling various tools (microfactory) before Soong_UI starts.
+ repeated PerfInfo setup_tools = 17;
+
+ // The metrics for calling Kati by multiple times.
+ repeated PerfInfo kati_runs = 18;
+
+ // The metrics for calling Soong.
+ repeated PerfInfo soong_runs = 19;
+
+ // The metrics for calling Ninja.
+ repeated PerfInfo ninja_runs = 20;
+}
+
+message PerfInfo {
+ // The description for the phase/action/part while the tool running.
+ optional string desc = 1;
+
+ // The name for the running phase/action/part.
+ optional string name = 2;
+
+ // The absolute start time.
+ // The number of nanoseconds elapsed since January 1, 1970 UTC.
+ optional uint64 start_time = 3;
+
+ // The real running time.
+ // The number of nanoseconds elapsed since start_time.
+ optional uint64 real_time = 4;
+
+ // The number of MB for memory use.
+ optional uint64 memory_use = 5;
+}
+
+message ModuleTypeInfo {
+ enum BUILDSYSTEM {
+ UNKNOWN = 0;
+ SOONG = 1;
+ MAKE = 2;
+ }
+ // The build system, eg. Soong or Make.
+ optional BUILDSYSTEM build_system = 1 [default = UNKNOWN];
+
+ // The module type, eg. java_library, cc_binary, and etc.
+ optional string module_type = 2;
+
+ // The number of logical modules.
+ optional uint32 num_of_modules = 3;
+}
diff --git a/ui/metrics/metrics_proto/regen.sh b/ui/metrics/metrics_proto/regen.sh
new file mode 100755
index 0000000..343c638
--- /dev/null
+++ b/ui/metrics/metrics_proto/regen.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+aprotoc --go_out=paths=source_relative:. metrics.proto
diff --git a/ui/metrics/time.go b/ui/metrics/time.go
new file mode 100644
index 0000000..7e8801a
--- /dev/null
+++ b/ui/metrics/time.go
@@ -0,0 +1,71 @@
+// Copyright 2018 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package metrics
+
+import (
+ "time"
+
+ "android/soong/ui/metrics/metrics_proto"
+ "android/soong/ui/tracer"
+)
+
+type timeEvent struct {
+ desc string
+ name string
+
+ atNanos uint64 // timestamp measured in nanoseconds since the reference date
+}
+
+type TimeTracer interface {
+ Begin(name, desc string, thread tracer.Thread)
+ End(thread tracer.Thread) metrics_proto.PerfInfo
+}
+
+type timeTracerImpl struct {
+ activeEvents []timeEvent
+}
+
+var _ TimeTracer = &timeTracerImpl{}
+
+func (t *timeTracerImpl) now() uint64 {
+ return uint64(time.Now().UnixNano())
+}
+
+func (t *timeTracerImpl) Begin(name, desc string, thread tracer.Thread) {
+ t.beginAt(name, desc, t.now())
+}
+
+func (t *timeTracerImpl) beginAt(name, desc string, atNanos uint64) {
+ t.activeEvents = append(t.activeEvents, timeEvent{name: name, desc: desc, atNanos: atNanos})
+}
+
+func (t *timeTracerImpl) End(thread tracer.Thread) metrics_proto.PerfInfo {
+ return t.endAt(t.now())
+}
+
+func (t *timeTracerImpl) endAt(atNanos uint64) metrics_proto.PerfInfo {
+ if len(t.activeEvents) < 1 {
+ panic("Internal error: No pending events for endAt to end!")
+ }
+ lastEvent := t.activeEvents[len(t.activeEvents)-1]
+ t.activeEvents = t.activeEvents[:len(t.activeEvents)-1]
+ realTime := atNanos - lastEvent.atNanos
+
+ return metrics_proto.PerfInfo{
+ Desc: &lastEvent.desc,
+ Name: &lastEvent.name,
+ StartTime: &lastEvent.atNanos,
+ RealTime: &realTime}
+}
diff --git a/ui/status/status.go b/ui/status/status.go
index c851d7f..46ec72e 100644
--- a/ui/status/status.go
+++ b/ui/status/status.go
@@ -260,6 +260,10 @@
}
}
+func (s *Status) Status(msg string) {
+ s.message(StatusLvl, msg)
+}
+
type toolStatus struct {
status *Status