[fint] Record ninja duration to artifacts

Some dashboards rely on the "build.ninja.fuchsia" step name to measure
the time that ninja takes to build fuchsia. I would like to simplify the
step name to "build.ninja", and ideally remove the dependency on
specific step names, which is fragile, and instead expose the ninja
duration as a build output property.

However, to get an accurate ninja duration we need to exclude `fint
build`'s post-processing steps (which may take up to ~30 seconds) from
the duration, hence the need to record the ninja duration within fint
and expose it to recipes.

Bug: 67861
Change-Id: I0df173f194936fd2a0ef83b00827a06024a4b0ac
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/514960
Reviewed-by: Ina Huh <ihuh@google.com>
Commit-Queue: Oliver Newman <olivernewman@google.com>
Fuchsia-Auto-Submit: Oliver Newman <olivernewman@google.com>
diff --git a/tools/integration/fint/build.go b/tools/integration/fint/build.go
index 04baffd..8d47c92 100644
--- a/tools/integration/fint/build.go
+++ b/tools/integration/fint/build.go
@@ -8,10 +8,12 @@
 	"context"
 	"encoding/json"
 	"fmt"
+	"math"
 	"os"
 	"path/filepath"
 	"sort"
 	"strings"
+	"time"
 
 	"go.fuchsia.dev/fuchsia/tools/build"
 	fintpb "go.fuchsia.dev/fuchsia/tools/integration/fint/proto"
@@ -80,6 +82,7 @@
 		jobCount:  int(contextSpec.GomaJobCount),
 	}
 
+	ninjaStartTime := time.Now()
 	var ninjaErr error
 	if contextSpec.ArtifactDir == "" {
 		// If we don't care about collecting artifacts, which is generally the
@@ -91,6 +94,8 @@
 	} else {
 		artifacts.FailureSummary, ninjaErr = runNinja(ctx, runner, targets)
 	}
+	ninjaDuration := time.Since(ninjaStartTime)
+	artifacts.NinjaDurationSeconds = int32(math.Round(ninjaDuration.Seconds()))
 
 	// As an optimization, we only bother collecting graph and compdb data if we
 	// have a way to return it to the caller. We want to collect this data even
diff --git a/tools/integration/fint/proto/build_artifacts.pb.go b/tools/integration/fint/proto/build_artifacts.pb.go
index 0bd9c9e..31fe990 100644
--- a/tools/integration/fint/proto/build_artifacts.pb.go
+++ b/tools/integration/fint/proto/build_artifacts.pb.go
@@ -54,6 +54,8 @@
 	NinjaGraphPath string `protobuf:"bytes,8,opt,name=ninja_graph_path,json=ninjaGraphPath,proto3" json:"ninja_graph_path,omitempty"`
 	// Absolute path to a Ninja compdb file.
 	NinjaCompdbPath string `protobuf:"bytes,9,opt,name=ninja_compdb_path,json=ninjaCompdbPath,proto3" json:"ninja_compdb_path,omitempty"`
+	// The duration taken by the ninja build step.
+	NinjaDurationSeconds int32 `protobuf:"varint,10,opt,name=ninja_duration_seconds,json=ninjaDurationSeconds,proto3" json:"ninja_duration_seconds,omitempty"`
 }
 
 func (x *BuildArtifacts) Reset() {
@@ -151,13 +153,20 @@
 	return ""
 }
 
+func (x *BuildArtifacts) GetNinjaDurationSeconds() int32 {
+	if x != nil {
+		return x.NinjaDurationSeconds
+	}
+	return 0
+}
+
 var File_build_artifacts_proto protoreflect.FileDescriptor
 
 var file_build_artifacts_proto_rawDesc = []byte{
 	0x0a, 0x15, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x61, 0x72, 0x74, 0x69, 0x66, 0x61, 0x63, 0x74,
 	0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x66, 0x69, 0x6e, 0x74, 0x1a, 0x1c, 0x67,
 	0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x73,
-	0x74, 0x72, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xf7, 0x04, 0x0a, 0x0e,
+	0x74, 0x72, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xad, 0x05, 0x0a, 0x0e,
 	0x42, 0x75, 0x69, 0x6c, 0x64, 0x41, 0x72, 0x74, 0x69, 0x66, 0x61, 0x63, 0x74, 0x73, 0x12, 0x27,
 	0x0a, 0x0f, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65, 0x5f, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72,
 	0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65,
@@ -191,17 +200,20 @@
 	0x50, 0x61, 0x74, 0x68, 0x12, 0x2a, 0x0a, 0x11, 0x6e, 0x69, 0x6e, 0x6a, 0x61, 0x5f, 0x63, 0x6f,
 	0x6d, 0x70, 0x64, 0x62, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52,
 	0x0f, 0x6e, 0x69, 0x6e, 0x6a, 0x61, 0x43, 0x6f, 0x6d, 0x70, 0x64, 0x62, 0x50, 0x61, 0x74, 0x68,
-	0x1a, 0x63, 0x0a, 0x1c, 0x5a, 0x62, 0x69, 0x54, 0x65, 0x73, 0x74, 0x51, 0x65, 0x6d, 0x75, 0x4b,
-	0x65, 0x72, 0x6e, 0x65, 0x6c, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79,
-	0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b,
-	0x65, 0x79, 0x12, 0x2d, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
-	0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
-	0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75,
-	0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x35, 0x5a, 0x33, 0x67, 0x6f, 0x2e, 0x66, 0x75, 0x63, 0x68,
-	0x73, 0x69, 0x61, 0x2e, 0x64, 0x65, 0x76, 0x2f, 0x66, 0x75, 0x63, 0x68, 0x73, 0x69, 0x61, 0x2f,
-	0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f,
-	0x6e, 0x2f, 0x66, 0x69, 0x6e, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72,
-	0x6f, 0x74, 0x6f, 0x33,
+	0x12, 0x34, 0x0a, 0x16, 0x6e, 0x69, 0x6e, 0x6a, 0x61, 0x5f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69,
+	0x6f, 0x6e, 0x5f, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05,
+	0x52, 0x14, 0x6e, 0x69, 0x6e, 0x6a, 0x61, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53,
+	0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x1a, 0x63, 0x0a, 0x1c, 0x5a, 0x62, 0x69, 0x54, 0x65, 0x73,
+	0x74, 0x51, 0x65, 0x6d, 0x75, 0x4b, 0x65, 0x72, 0x6e, 0x65, 0x6c, 0x49, 0x6d, 0x61, 0x67, 0x65,
+	0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20,
+	0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2d, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75,
+	0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
+	0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74,
+	0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x35, 0x5a, 0x33, 0x67,
+	0x6f, 0x2e, 0x66, 0x75, 0x63, 0x68, 0x73, 0x69, 0x61, 0x2e, 0x64, 0x65, 0x76, 0x2f, 0x66, 0x75,
+	0x63, 0x68, 0x73, 0x69, 0x61, 0x2f, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2f, 0x69, 0x6e, 0x74, 0x65,
+	0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x66, 0x69, 0x6e, 0x74, 0x2f, 0x70, 0x72, 0x6f,
+	0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
diff --git a/tools/integration/fint/proto/build_artifacts.proto b/tools/integration/fint/proto/build_artifacts.proto
index f209bfc..d934350 100644
--- a/tools/integration/fint/proto/build_artifacts.proto
+++ b/tools/integration/fint/proto/build_artifacts.proto
@@ -43,4 +43,7 @@
 
   // Absolute path to a Ninja compdb file.
   string ninja_compdb_path = 9;
+
+  // The duration taken by the ninja build step.
+  int32 ninja_duration_seconds = 10;
 }