The -ftime-trace option in clang writes a trace of the compilation as a json file for each compilation unit that it processed (e.g. for each object file it produces).
This is a simple model and tools like ClangBuildAnalyzer or ninjatracing build on this. However when using an offloading model (OpenMP, HIP, CUDA, SYCL…) this promise of one produced object file → one trace file is broken.
In offloading mode, the clang driver transparently invokes the compiler (clang -cc1) multiple times (typically once for each offload target, i.e. GPU architecture) when compiling a single source file to an object file -ftime-trace currently is implemented in the compiler, the driver only provides the path where the object will be stored, therefore each sub-compilation would get its own trace. (I say would because since ⚙ D150282 [Driver] -ftime-trace: derive trace file names from -o and -dumpdir disabled -ftime-trace is currently disabled for offloading).
Now for the RFC part: ideally using -ftime-trace with offloading would be as easy for users as without offloading, i.e. a single trace should be produced that contains the compilation timings for all targets, but minimally the trace files should contain enough information to map back to object files and targets.
Use an IPC mechanism to share the time trace context between the compilation jobs and the driver.
Merge the traces in the driver.
Don’t merge, just extend the files with information that maps it to object files.
Is complicated, but Perfetto could make it easier as it has its own serialization format already, (⚙ D82994 [RFC] Instrumenting Clang/LLVM with Perfetto attempted to add perfetto, but it was abandoned.