diff --git a/changelog/dmd.ftime-trace-inline.dd b/changelog/dmd.ftime-trace-inline.dd new file mode 100644 index 000000000000..bc3d15cb9df1 --- /dev/null +++ b/changelog/dmd.ftime-trace-inline.dd @@ -0,0 +1,9 @@ +`-ftime-trace`: add instrumentation for the inliner pass + +The `-ftime-trace` output previously had no coverage for the inliner pass. +When compiling with `-inline`, the time spent scanning and inlining functions +did not appear in the trace at all. + +Two new spans are now emitted: `Inlining` covers the entire inliner pass, and +`Inline: ` covers each function scanned individually. +These are visible in trace viewers like $(LINK2 https://ui.perfetto.dev/, Perfetto). diff --git a/compiler/src/dmd/inline.d b/compiler/src/dmd/inline.d index dc74a2c6ba6b..311da43463a4 100644 --- a/compiler/src/dmd/inline.d +++ b/compiler/src/dmd/inline.d @@ -1823,6 +1823,10 @@ public: fd.inlineScanned = true; fd.semanticRun = pass; + import dmd.timetrace; + timeTraceBeginEvent(TimeTraceEventType.inlineFunction); + scope (exit) timeTraceEndEvent(TimeTraceEventType.inlineFunction, fd); + scope InlineScanVisitor v = new InlineScanVisitor(fd, pass, eSink); do diff --git a/compiler/src/dmd/main.d b/compiler/src/dmd/main.d index dbbde2889b6c..5b37bd3cd68b 100644 --- a/compiler/src/dmd/main.d +++ b/compiler/src/dmd/main.d @@ -665,6 +665,10 @@ private int tryMain(const(char)[][] argv, out Param params) if (global.errors) removeHdrFilesAndFail(params, modules); + { + timeTraceBeginEvent(TimeTraceEventType.inlineGeneral); + scope (exit) timeTraceEndEvent(TimeTraceEventType.inlineGeneral); + // Scan for modules with always inline functions foreach (m; modules) { @@ -686,6 +690,7 @@ private int tryMain(const(char)[][] argv, out Param params) inlineScanAllFunctions(m, global.errorSink); } } + } if (global.warnings) errorOnWarning(); diff --git a/compiler/src/dmd/timetrace.d b/compiler/src/dmd/timetrace.d index 806e78d5bc61..ac52c61e6186 100644 --- a/compiler/src/dmd/timetrace.d +++ b/compiler/src/dmd/timetrace.d @@ -184,6 +184,8 @@ enum TimeTraceEventType sema1Function, sema2, sema3, + inlineGeneral, /// top-level span for the entire inliner pass + inlineFunction, /// per-function span during inlining dfa, ctfe, ctfeCall, @@ -211,6 +213,8 @@ private immutable string[] eventPrefixes = [ "Sema1: Function ", "Sema2: ", "Sema3: ", + "Inlining", + "Inline: ", "DFA: ", "Ctfe: ", "Ctfe: call ", diff --git a/compiler/test/compilable/ftimetrace.d b/compiler/test/compilable/ftimetrace.d index 23b7d6a11c68..0480daf60cee 100644 --- a/compiler/test/compilable/ftimetrace.d +++ b/compiler/test/compilable/ftimetrace.d @@ -16,6 +16,7 @@ DFA: fun, object.fun DFA: id, object.id!int.id DFA: uses, object.uses Import object.object, object.object +Inlining, Parse: Module object, object Parsing, Sema1: Function add, object.add diff --git a/compiler/test/compilable/ftimetrace_inline.d b/compiler/test/compilable/ftimetrace_inline.d new file mode 100644 index 000000000000..d6082794a07a --- /dev/null +++ b/compiler/test/compilable/ftimetrace_inline.d @@ -0,0 +1,37 @@ +/** +REQUIRED_ARGS: -ftime-trace -ftime-trace-file=- -ftime-trace-granularity=0 -inline +TRANSFORM_OUTPUT: sanitize_timetrace +TEST_OUTPUT: +--- +Code generation, +Codegen: function add, object.add +Codegen: function uses, object.uses +Codegen: module object, object +Import object.object, object.object +Inline: add, object.add +Inline: uses, object.uses +Inlining, +Parse: Module object, object +Parsing, +Sema1: Function add, object.add +Sema1: Function uses, object.uses +Sema1: Module object, object +Sema2: add, object.add +Sema2: uses, object.uses +Sema3: add, object.add +Sema3: uses, object.uses +Semantic analysis, +--- +*/ + +module object; // Don't clutter time trace output with object.d + +int add(int x, int y) +{ + return x + y; +} + +void uses() +{ + int a = add(1, 2); +} diff --git a/compiler/test/compilable/ftimetrace_pragma.d b/compiler/test/compilable/ftimetrace_pragma.d new file mode 100644 index 000000000000..6d690e420617 --- /dev/null +++ b/compiler/test/compilable/ftimetrace_pragma.d @@ -0,0 +1,43 @@ +/** +REQUIRED_ARGS: -ftime-trace -ftime-trace-file=- -ftime-trace-granularity=0 +TRANSFORM_OUTPUT: sanitize_timetrace +TEST_OUTPUT: +--- +Code generation, +Codegen: function cube, object.cube +Codegen: function square, object.square +Codegen: function uses, object.uses +Codegen: module object, object +Import object.object, object.object +Inline: cube, object.cube +Inline: uses, object.uses +Inlining, +Parse: Module object, object +Parsing, +Sema1: Function cube, object.cube +Sema1: Function square, object.square +Sema1: Function uses, object.uses +Sema1: Module object, object +Sema2: cube, object.cube +Sema2: square, object.square +Sema2: uses, object.uses +Sema3: cube, object.cube +Sema3: square, object.square +Sema3: uses, object.uses +Semantic analysis, +--- +*/ + +module object; // Don't clutter time trace output with object.d + +pragma(inline, true) +int square(int x) { return x * x; } + +pragma(inline, true) +int cube(int x) { return x * square(x); } + +void uses() +{ + int a = cube(3); + int b = square(4); +}