Report mkfile metrics with --mk-metrics

Combined with roboleaf CI changes to pass this flag and subsequent
pipeline changes, this will allow basic mkfile metrics to be
dashboarded, which will help track mk2bp progress.

Bug: 217764943
Test: manual; verified mk_metrics.pb is generated iff --mk-metrics is
specified, used printproto on result

Change-Id: I348994b4d7e3479d0dc04de0276b94a702aac95b
This commit is contained in:
Chris Parsons
2022-03-03 12:01:40 -05:00
parent 309ee8d398
commit 53f68ae3b8
7 changed files with 300 additions and 10 deletions

View File

@@ -41,6 +41,7 @@ import (
"google.golang.org/protobuf/proto"
soong_metrics_proto "android/soong/ui/metrics/metrics_proto"
mk_metrics_proto "android/soong/ui/metrics/mk_metrics_proto"
)
const (
@@ -62,14 +63,22 @@ const (
Total = "total"
)
// Metrics is a struct that stores collected metrics during the course
// of a build which later is dumped to a MetricsBase protobuf file.
// See ui/metrics/metrics_proto/metrics.proto for further details
// on what information is collected.
// Metrics is a struct that stores collected metrics during the course of a
// build. It is later dumped to protobuf files. See underlying metrics protos
// for further details on what information is collected.
type Metrics struct {
// The protobuf message that is later written to the file.
// Protobuf containing various top-level build metrics. These include:
// 1. Build identifiers (ex: branch ID, requested product, hostname,
// originating command)
// 2. Per-subprocess top-level metrics (ex: ninja process IO and runtime).
// Note that, since these metrics are reported by soong_ui, there is little
// insight that can be provided into performance breakdowns of individual
// subprocesses.
metrics soong_metrics_proto.MetricsBase
// Protobuf containing metrics pertaining to number of makefiles in a build.
mkMetrics mk_metrics_proto.MkMetrics
// A list of pending build events.
EventTracer *EventTracer
}
@@ -78,11 +87,24 @@ type Metrics struct {
func New() (metrics *Metrics) {
m := &Metrics{
metrics: soong_metrics_proto.MetricsBase{},
mkMetrics: mk_metrics_proto.MkMetrics{},
EventTracer: &EventTracer{},
}
return m
}
func (m *Metrics) SetTotalMakefiles(total int) {
m.mkMetrics.TotalMakefiles = uint32(total)
}
func (m *Metrics) SetToplevelMakefiles(total int) {
m.mkMetrics.ToplevelMakefiles = uint32(total)
}
func (m *Metrics) DumpMkMetrics(outPath string) {
shared.Save(&m.mkMetrics, outPath)
}
// SetTimeMetrics stores performance information from an executed block of
// code.
func (m *Metrics) SetTimeMetrics(perf soong_metrics_proto.PerfInfo) {