diff options
author | Dan Albert <danalbert@google.com> | 2023-06-15 19:43:55 +0000 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2023-06-15 22:04:18 +0000 |
commit | 45d6a94d6de54494150299ff0e7137196f3f0b47 (patch) | |
tree | b07393ef133d54784d133b9cb81308fd682c7c0e | |
parent | 9fdf0a6156cd9d3d5824bd8f422d395abdd6f2fc (diff) | |
download | ninja-45d6a94d6de54494150299ff0e7137196f3f0b47.tar.gz |
Add tags field to build.
The tags field is a string with an implementation defined format. This
allows build systems to include arbitrary metadata in the proto for
better metrics.
Bug: http://b/259130368
Test: used to trace dist cp time
Change-Id: I9f6fcae0d8e4f7152ea82d3038807f622ca92801
-rw-r--r-- | frontend/frontend.pb | bin | 1369 -> 1389 bytes | |||
-rw-r--r-- | src/frontend.pb.h | 14 | ||||
-rw-r--r-- | src/frontend.proto | 3 | ||||
-rw-r--r-- | src/graph.h | 1 | ||||
-rw-r--r-- | src/manifest_parser.cc | 9 | ||||
-rw-r--r-- | src/status.cc | 1 |
6 files changed, 28 insertions, 0 deletions
diff --git a/frontend/frontend.pb b/frontend/frontend.pb Binary files differindex f35d673..8795ecd 100644 --- a/frontend/frontend.pb +++ b/frontend/frontend.pb diff --git a/src/frontend.pb.h b/src/frontend.pb.h index 5b3ac26..d5474a1 100644 --- a/src/frontend.pb.h +++ b/src/frontend.pb.h @@ -289,6 +289,8 @@ struct Status { bool has_voluntary_context_switches_; uint64_t involuntary_context_switches_; bool has_involuntary_context_switches_; + std::string tags_; + bool has_tags_; EdgeFinished() { has_id_ = false; @@ -316,6 +318,7 @@ struct Status { voluntary_context_switches_ = static_cast< uint64_t >(0); has_involuntary_context_switches_ = false; involuntary_context_switches_ = static_cast< uint64_t >(0); + has_tags_ = false; } EdgeFinished(const EdgeFinished&); @@ -335,6 +338,7 @@ struct Status { WriteVarint64(output__, 11, io_output_kb_); WriteVarint64(output__, 12, voluntary_context_switches_); WriteVarint64(output__, 13, involuntary_context_switches_); + WriteString(output__, 14, tags_); } size_t ByteSizeLong() const { @@ -352,6 +356,7 @@ struct Status { size += VarintSize64(io_output_kb_) + 1; size += VarintSize64(voluntary_context_switches_) + 1; size += VarintSize64(involuntary_context_switches_) + 1; + size += StringSize(tags_) + 1; return size; } @@ -369,6 +374,7 @@ struct Status { io_output_kb_ = static_cast< uint64_t >(0); voluntary_context_switches_ = static_cast< uint64_t >(0); involuntary_context_switches_ = static_cast< uint64_t >(0); + tags_.clear(); } uint32_t* mutable_id() { @@ -475,6 +481,14 @@ struct Status { has_involuntary_context_switches_ = true; involuntary_context_switches_ = value; } + std::string* mutable_tags() { + has_tags_ = true; + return &tags_; + } + void set_tags(const std::string& value) { + has_tags_ = true; + tags_ = value; + } }; struct Message { diff --git a/src/frontend.proto b/src/frontend.proto index 8f03522..45b428a 100644 --- a/src/frontend.proto +++ b/src/frontend.proto @@ -78,6 +78,9 @@ message Status { optional uint64 voluntary_context_switches = 12; // Involuntary context switches optional uint64 involuntary_context_switches = 13; + // Arbitrary tags for build system profiling (module names and types, rule + // names, etc). Format of the string is implementation defined. + optional string tags = 14; } message Message { diff --git a/src/graph.h b/src/graph.h index 85e9326..04bbf84 100644 --- a/src/graph.h +++ b/src/graph.h @@ -470,6 +470,7 @@ public: bool deps_missing_ = false; bool phony_from_depfile_ = false; DepScanInfo dep_scan_info_; + std::string tags_; DeclIndex dfs_location() const { return pos_.dfs_location(); } const Rule& rule() const { return *rule_; } diff --git a/src/manifest_parser.cc b/src/manifest_parser.cc index 45342eb..f84d523 100644 --- a/src/manifest_parser.cc +++ b/src/manifest_parser.cc @@ -414,6 +414,7 @@ static inline bool AddPathToEdge(State* state, const Edge& edge, static const HashedStrView kPool { "pool" }; static const HashedStrView kDeps { "deps" }; static const HashedStrView kDyndep { "dyndep" }; +static const HashedStrView kTags { "tags" }; struct ManifestLoader { private: @@ -468,6 +469,14 @@ bool ManifestLoader::AddEdgeToGraph(Edge* edge, const LoadedFile& file, } } + std::string tags; + if (!edge->EvaluateVariable(&tags, kTags, edge->pos_.scope(), err, EdgeEval::kParseTime)) { + return false; + } + if (!tags.empty()) { + edge->tags_ = tags; + } + edge->outputs_.reserve(edge->explicit_outs_ + edge->implicit_outs_); edge->inputs_.reserve(edge->explicit_deps_ + edge->implicit_deps_ + edge->order_only_deps_); diff --git a/src/status.cc b/src/status.cc index 1049312..445771b 100644 --- a/src/status.cc +++ b/src/status.cc @@ -377,6 +377,7 @@ void StatusSerializer::BuildEdgeFinished(Edge* edge, int64_t end_time_millis, edge_finished->set_io_output_kb(result->rusage.ru_oublock / 2); edge_finished->set_voluntary_context_switches(result->rusage.ru_nvcsw); edge_finished->set_involuntary_context_switches(result->rusage.ru_nivcsw); + edge_finished->set_tags(edge->tags_); Send(); } |