-ftime-trace or -ftime-trace=<path> enable the TimeProfiler.
When Clang does compile and link actions in one command and -ftime-trace is used, the created time-trace json files currently goes to a temporary directory, e.g.
$ clang++ -ftime-trace -o main.out /demo/main.cpp $ ls . main.out $ ls /tmp/ main-[random-string].json
Obviously the time-trace files cannot be easily found, so that the json file location is undesired.
This patch change the default storing behavior of -ftime-trace.
That is, if the compiling job contains the linking action, the executable file' s directory may be seem as the main work directory.
Thus the time trace files would be stored in the same directory of linking result.
By this approach, the user can easily get the time-trace files in the main work directory. The improved demo results:
$ clang++ -ftime-trace -o main.out /demo/main.cpp $ ls . main.out main-[random-string].json
In addition, the main codes of time-trace files' path inference have been refactored.
- The <path> of -ftime-trace=<path> is infered in clang driver
- After that, -ftime-trace=<path> can be added into clang's options
By this approach, the dirty work of path processing and judging can be implemented in driver layer, so that the clang may focus on its main work.
This include isn't necessary. There are asserts already in the file so this is transitively included.