-ftime-trace could break flame-graph assumptions on Windows, with an inner scope overrunning outer scopes. This was due to the way that times were truncated. Changing this so time points for the flame-graph are truncated, instead of durations, preserves the relative order of event starts and ends.
I have tried to retain the extra precision for the totals, which count thousands or millions of events.
Added assert to check this property holds in future.
You can use the range-based version of llvm:sort here.