[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 18 00:57:32 PDT 2024
================
@@ -60,39 +74,65 @@ bool compileFromString(StringRef Code, StringRef Standard, StringRef FileName) {
return Compiler.ExecuteAction(Action);
}
+std::string GetMetadata(json::Object *Event) {
+ std::string Metadata = "";
+ if (json::Object *Args = Event->getObject("args")) {
+ if (StringRef Detail = Args->getString("detail").value_or("");
+ !Detail.empty())
+ Metadata += Detail.str();
+ if (StringRef File = Args->getString("filename").value_or("");
+ !File.empty())
+ Metadata += ", " + File.str();
+ }
+ return Metadata;
+}
+
// Returns pretty-printed trace graph.
std::string buildTraceGraph(StringRef Json) {
struct EventRecord {
int64_t TimestampBegin;
int64_t TimestampEnd;
- StringRef Name;
- StringRef Detail;
+ std::string Name;
+ std::string Metadata;
};
std::vector<EventRecord> Events;
// Parse `EventRecord`s from JSON dump.
Expected<json::Value> Root = json::parse(Json);
if (!Root)
return "";
+ std::stack<json::Object *> SourceEvents;
for (json::Value &TraceEventValue :
*Root->getAsObject()->getArray("traceEvents")) {
json::Object *TraceEventObj = TraceEventValue.getAsObject();
int64_t TimestampBegin = TraceEventObj->getInteger("ts").value_or(0);
int64_t TimestampEnd =
TimestampBegin + TraceEventObj->getInteger("dur").value_or(0);
- StringRef Name = TraceEventObj->getString("name").value_or("");
- StringRef Detail = "";
- if (json::Object *Args = TraceEventObj->getObject("args"))
- Detail = Args->getString("detail").value_or("");
+ std::string Name = TraceEventObj->getString("name").value_or("").str();
+ std::string Metadata = GetMetadata(TraceEventObj);
+
+ if (Name == "Source") {
----------------
ilya-biryukov wrote:
But why do we do this in the unit-tests, and not production code, and why do we need to do this in this change?
I am still vague on the motivation for this diff.
https://github.com/llvm/llvm-project/pull/98320
More information about the cfe-commits
mailing list