Skip to content

Commit bb82c7e

Browse files
committed
Add run_time_ms accessors and more comments
1 parent a861164 commit bb82c7e

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/build.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ struct SeenBefore {
452452
}
453453
};
454454

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
456456
// For phony edges, 0 cost.
457457
// For edges with a build history, use the last build time.
458458
// For edges without history, use the 75th percentile time for edges with history.
@@ -462,6 +462,7 @@ int64_t AssignEdgeRuntime(BuildLog* build_log,
462462
bool missing_durations = false;
463463
std::vector<int64_t> durations;
464464
int64_t total_time = 0;
465+
const int64_t kUnknownRunTime = -1;
465466

466467
for (std::map<Edge*, Plan::Want>::const_iterator it = want.begin(),
467468
end = want.end();
@@ -474,11 +475,11 @@ int64_t AssignEdgeRuntime(BuildLog* build_log,
474475
build_log->LookupByOutput(edge->outputs_[0]->path());
475476
if (!entry) {
476477
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
478479
continue;
479480
}
480481
const int64_t duration = entry->end_time - entry->start_time;
481-
edge->run_time_ms_ = duration;
482+
edge->set_run_time_ms(duration);
482483
total_time += duration;
483484
durations.push_back(duration);
484485
}
@@ -504,10 +505,10 @@ int64_t AssignEdgeRuntime(BuildLog* build_log,
504505
end = want.end();
505506
it != end; ++it) {
506507
Edge* edge = it->first;
507-
if (edge->run_time_ms_ >= 0) {
508+
if (edge->run_time_ms() != kUnknownRunTime) {
508509
continue;
509510
}
510-
edge->run_time_ms_ = p75_time;
511+
edge->set_run_time_ms(p75_time);
511512
total_time += p75_time;
512513
}
513514
return total_time;
@@ -542,16 +543,15 @@ void Plan::ComputeCriticalTime(BuildLog* build_log) {
542543
SeenBefore<Edge> seen_edge(
543544
&active_edges); // Test for uniqueness in work_queue
544545

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;
552552
in->set_critical_time(
553553
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()));
555555
if (!seen_edge(in)) {
556556
work_queue.push(in);
557557
}
@@ -571,7 +571,7 @@ void Plan::ComputeCriticalTime(BuildLog* build_log) {
571571
continue;
572572
}
573573
// 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();
575575
if (proposed_time > in->critical_time()) {
576576
in->set_critical_time(proposed_time);
577577
if (!seen_edge(in)) {

src/graph.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ struct Edge {
206206
critical_time_ = critical_time;
207207
}
208208

209+
// Run time in ms for this edge's command.
210+
// Taken from the build log if present, or estimated otherwise.
211+
// Default initialized to 0.
212+
int64_t run_time_ms() const { return run_time_ms_; }
213+
void set_run_time_ms(int64_t run_time_ms) {
214+
run_time_ms_ = run_time_ms;
215+
}
216+
209217
const Rule* rule_;
210218
Pool* pool_;
211219
std::vector<Node*> inputs_;

0 commit comments

Comments
 (0)