@@ -452,7 +452,7 @@ struct SeenBefore {
452
452
}
453
453
};
454
454
455
- // Assign run_time_ms_ for all wanted edges, and returns total time for all edges
455
+ // Assign run_time_ms for all wanted edges, and returns total time for all edges
456
456
// For phony edges, 0 cost.
457
457
// For edges with a build history, use the last build time.
458
458
// For edges without history, use the 75th percentile time for edges with history.
@@ -462,6 +462,7 @@ int64_t AssignEdgeRuntime(BuildLog* build_log,
462
462
bool missing_durations = false ;
463
463
std::vector<int64_t > durations;
464
464
int64_t total_time = 0 ;
465
+ const int64_t kUnknownRunTime = -1 ;
465
466
466
467
for (std::map<Edge*, Plan::Want>::const_iterator it = want.begin (),
467
468
end = want.end ();
@@ -474,11 +475,11 @@ int64_t AssignEdgeRuntime(BuildLog* build_log,
474
475
build_log->LookupByOutput (edge->outputs_ [0 ]->path ());
475
476
if (!entry) {
476
477
missing_durations = true ;
477
- edge->run_time_ms_ = - 1 ; // -1 to mark as needing filled in
478
+ edge->set_run_time_ms ( kUnknownRunTime ) ; // mark as needing filled in
478
479
continue ;
479
480
}
480
481
const int64_t duration = entry->end_time - entry->start_time ;
481
- edge->run_time_ms_ = duration;
482
+ edge->set_run_time_ms ( duration) ;
482
483
total_time += duration;
483
484
durations.push_back (duration);
484
485
}
@@ -504,10 +505,10 @@ int64_t AssignEdgeRuntime(BuildLog* build_log,
504
505
end = want.end ();
505
506
it != end; ++it) {
506
507
Edge* edge = it->first ;
507
- if (edge->run_time_ms_ >= 0 ) {
508
+ if (edge->run_time_ms () != kUnknownRunTime ) {
508
509
continue ;
509
510
}
510
- edge->run_time_ms_ = p75_time;
511
+ edge->set_run_time_ms ( p75_time) ;
511
512
total_time += p75_time;
512
513
}
513
514
return total_time;
@@ -542,16 +543,15 @@ void Plan::ComputeCriticalTime(BuildLog* build_log) {
542
543
SeenBefore<Edge> seen_edge (
543
544
&active_edges); // Test for uniqueness in work_queue
544
545
545
- for (std::vector<const Node*>::reverse_iterator it = targets_.rbegin (),
546
- end = targets_.rend ();
547
- it != end; ++it) {
548
- if (Edge* in = (*it)->in_edge ()) {
549
- // Use initial critical time: total_time * N. This means higher
550
- // priority targets always get a higher critical time value
551
- int64_t priority_weight = (it - targets_.rbegin ()) * total_time;
546
+ for (size_t i = 0 ; i < targets_.size (); ++i) {
547
+ const Node* target = targets_[i];
548
+ if (Edge* in = target->in_edge ()) {
549
+ // Add a bias to ensure that targets that appear first in |targets_| have a larger critical time than
550
+ // those that follow them. E.g. for 3 targets: [2*total_time, total_time, 0].
551
+ int64_t priority_weight = (targets_.size () - i - 1 ) * total_time;
552
552
in->set_critical_time (
553
553
priority_weight +
554
- std::max<int64_t >(in->run_time_ms_ , in->critical_time ()));
554
+ std::max<int64_t >(in->run_time_ms () , in->critical_time ()));
555
555
if (!seen_edge (in)) {
556
556
work_queue.push (in);
557
557
}
@@ -571,7 +571,7 @@ void Plan::ComputeCriticalTime(BuildLog* build_log) {
571
571
continue ;
572
572
}
573
573
// Only process edge if this node offers a higher critical time
574
- const int64_t proposed_time = e->critical_time () + in->run_time_ms_ ;
574
+ const int64_t proposed_time = e->critical_time () + in->run_time_ms () ;
575
575
if (proposed_time > in->critical_time ()) {
576
576
in->set_critical_time (proposed_time);
577
577
if (!seen_edge (in)) {
0 commit comments