Add long running jobs info

For the data to prioritize long running tasks in ninja, I added the
information about that.

Bug: 271526845
Test: build and check metrics
Change-Id: I76807f9b0d6a50d940b5f35dd6a9ef3cf693eec5
This commit is contained in:
Jeongik Cha 2023-03-15 10:47:35 +09:00
parent 28c1fe5bc8
commit 4199d4796c
3 changed files with 55 additions and 23 deletions

View file

@ -1448,6 +1448,8 @@ type CriticalPathInfo struct {
CriticalPathTime *uint64 `protobuf:"varint,2,opt,name=critical_path_time,json=criticalPathTime" json:"critical_path_time,omitempty"`
// Detailed job information in a critical path.
CriticalPath []*JobInfo `protobuf:"bytes,4,rep,name=critical_path,json=criticalPath" json:"critical_path,omitempty"`
// Detailed job information for long running jobs (>30 seconds). These may or may not also be on a critical path.
LongRunningJobs []*JobInfo `protobuf:"bytes,5,rep,name=long_running_jobs,json=longRunningJobs" json:"long_running_jobs,omitempty"`
}
func (x *CriticalPathInfo) Reset() {
@ -1503,6 +1505,13 @@ func (x *CriticalPathInfo) GetCriticalPath() []*JobInfo {
return nil
}
func (x *CriticalPathInfo) GetLongRunningJobs() []*JobInfo {
if x != nil {
return x.LongRunningJobs
}
return nil
}
type JobInfo struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -1831,7 +1840,7 @@ var file_metrics_proto_rawDesc = []byte{
0x5f, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x19, 0x6d, 0x69, 0x78, 0x65, 0x64, 0x42, 0x75,
0x69, 0x6c, 0x64, 0x44, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x4d, 0x6f, 0x64, 0x75, 0x6c,
0x65, 0x73, 0x22, 0xa6, 0x01, 0x0a, 0x10, 0x43, 0x72, 0x69, 0x74, 0x69, 0x63, 0x61, 0x6c, 0x50,
0x65, 0x73, 0x22, 0xf0, 0x01, 0x0a, 0x10, 0x43, 0x72, 0x69, 0x74, 0x69, 0x63, 0x61, 0x6c, 0x50,
0x61, 0x74, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x21, 0x0a, 0x0c, 0x65, 0x6c, 0x61, 0x70, 0x73,
0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x65,
0x6c, 0x61, 0x70, 0x73, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x2c, 0x0a, 0x12, 0x63, 0x72,
@ -1841,15 +1850,20 @@ var file_metrics_proto_rawDesc = []byte{
0x69, 0x63, 0x61, 0x6c, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32,
0x1c, 0x2e, 0x73, 0x6f, 0x6f, 0x6e, 0x67, 0x5f, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x6d, 0x65,
0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x4a, 0x6f, 0x62, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0c, 0x63,
0x72, 0x69, 0x74, 0x69, 0x63, 0x61, 0x6c, 0x50, 0x61, 0x74, 0x68, 0x22, 0x55, 0x0a, 0x07, 0x4a,
0x6f, 0x62, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x21, 0x0a, 0x0c, 0x65, 0x6c, 0x61, 0x70, 0x73, 0x65,
0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x65, 0x6c,
0x61, 0x70, 0x73, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x6a, 0x6f, 0x62,
0x5f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x0e, 0x6a, 0x6f, 0x62, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69,
0x6f, 0x6e, 0x42, 0x28, 0x5a, 0x26, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2f, 0x73, 0x6f,
0x6f, 0x6e, 0x67, 0x2f, 0x75, 0x69, 0x2f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2f, 0x6d,
0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x72, 0x69, 0x74, 0x69, 0x63, 0x61, 0x6c, 0x50, 0x61, 0x74, 0x68, 0x12, 0x48, 0x0a, 0x11, 0x6c,
0x6f, 0x6e, 0x67, 0x5f, 0x72, 0x75, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x5f, 0x6a, 0x6f, 0x62, 0x73,
0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x73, 0x6f, 0x6f, 0x6e, 0x67, 0x5f, 0x62,
0x75, 0x69, 0x6c, 0x64, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x4a, 0x6f, 0x62,
0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0f, 0x6c, 0x6f, 0x6e, 0x67, 0x52, 0x75, 0x6e, 0x6e, 0x69, 0x6e,
0x67, 0x4a, 0x6f, 0x62, 0x73, 0x22, 0x55, 0x0a, 0x07, 0x4a, 0x6f, 0x62, 0x49, 0x6e, 0x66, 0x6f,
0x12, 0x21, 0x0a, 0x0c, 0x65, 0x6c, 0x61, 0x70, 0x73, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65,
0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x65, 0x6c, 0x61, 0x70, 0x73, 0x65, 0x64, 0x54,
0x69, 0x6d, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x6a, 0x6f, 0x62, 0x5f, 0x64, 0x65, 0x73, 0x63, 0x72,
0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x6a, 0x6f,
0x62, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x28, 0x5a, 0x26,
0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2f, 0x73, 0x6f, 0x6f, 0x6e, 0x67, 0x2f, 0x75, 0x69,
0x2f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73,
0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
}
var (
@ -1909,11 +1923,12 @@ var file_metrics_proto_depIdxs = []int32{
14, // 20: soong_build_metrics.SoongBuildMetrics.mixed_builds_info:type_name -> soong_build_metrics.MixedBuildsInfo
3, // 21: soong_build_metrics.ExpConfigFetcher.status:type_name -> soong_build_metrics.ExpConfigFetcher.ConfigStatus
16, // 22: soong_build_metrics.CriticalPathInfo.critical_path:type_name -> soong_build_metrics.JobInfo
23, // [23:23] is the sub-list for method output_type
23, // [23:23] is the sub-list for method input_type
23, // [23:23] is the sub-list for extension type_name
23, // [23:23] is the sub-list for extension extendee
0, // [0:23] is the sub-list for field type_name
16, // 23: soong_build_metrics.CriticalPathInfo.long_running_jobs:type_name -> soong_build_metrics.JobInfo
24, // [24:24] is the sub-list for method output_type
24, // [24:24] is the sub-list for method input_type
24, // [24:24] is the sub-list for extension type_name
24, // [24:24] is the sub-list for extension extendee
0, // [0:24] is the sub-list for field type_name
}
func init() { file_metrics_proto_init() }

View file

@ -318,16 +318,18 @@ message MixedBuildsInfo{
repeated string mixed_build_disabled_modules = 2;
}
message CriticalPathInfo{
message CriticalPathInfo {
// Real time which the build system spent
optional uint64 elapsed_time = 1;
// The sum of execution time of the longest path from leave to the root
optional uint64 critical_path_time = 2;
// Detailed job information in a critical path.
repeated JobInfo critical_path = 4;
// Detailed job information for long running jobs (>30 seconds). These may or may not also be on a critical path.
repeated JobInfo long_running_jobs = 5;
}
message JobInfo{
message JobInfo {
// Real time which a job spent
optional uint64 elapsed_time = 1;
// Description of a job

View file

@ -127,16 +127,31 @@ func (cp *CriticalPath) criticalPath() (path []*node, elapsedTime time.Duration,
return
}
func (cp *CriticalPath) longRunningJobs() (nodes []*node) {
threshold := time.Second * 30
for _, node := range cp.nodes {
if node != nil && node.duration > threshold {
nodes = append(nodes, node)
}
}
return
}
func addJobInfos(jobInfos *[]*soong_metrics_proto.JobInfo, sources []*node) {
for _, job := range sources {
jobInfo := soong_metrics_proto.JobInfo{}
jobInfo.ElapsedTime = proto.Uint64(uint64(job.duration.Microseconds()))
jobInfo.JobDescription = &job.action.Description
*jobInfos = append(*jobInfos, &jobInfo)
}
}
func (cp *CriticalPath) WriteToMetrics(met *metrics.Metrics) {
criticalPathInfo := soong_metrics_proto.CriticalPathInfo{}
path, elapsedTime, criticalTime := cp.criticalPath()
criticalPathInfo.ElapsedTime = proto.Uint64(uint64(elapsedTime.Microseconds()))
criticalPathInfo.CriticalPathTime = proto.Uint64(uint64(criticalTime.Microseconds()))
for _, job := range path {
jobInfo := soong_metrics_proto.JobInfo{}
jobInfo.ElapsedTime = proto.Uint64(uint64(job.duration.Microseconds()))
jobInfo.JobDescription = &job.action.Description
criticalPathInfo.CriticalPath = append(criticalPathInfo.CriticalPath, &jobInfo)
}
addJobInfos(&criticalPathInfo.LongRunningJobs, cp.longRunningJobs())
addJobInfos(&criticalPathInfo.CriticalPath, path)
met.SetCriticalPathInfo(criticalPathInfo)
}