[lld-macho] Initialize separate time trace profiler for mapfile worker
authorJez Ng <jezng@fb.com>
Wed, 12 Jan 2022 01:45:07 +0000 (17:45 -0800)
committerJez Ng <jezng@fb.com>
Wed, 12 Jan 2022 01:45:18 +0000 (17:45 -0800)
After {D115416}, the "Write map file" event no longer shows up
in the time trace. Each time trace profiler instance is thread-local,
but we had neglected to initialize a separate instance for the mapfile
worker thread.

Reviewed By: keith

Differential Revision: https://reviews.llvm.org/D117069

lld/MachO/Writer.cpp
lld/test/MachO/map-file.s

index b0ca5ee..c633dbb 100644 (file)
@@ -1175,7 +1175,13 @@ template <class LP> void Writer::run() {
   sortSegmentsAndSections();
   createLoadCommands<LP>();
   finalizeAddresses();
-  threadPool.async(writeMapFile);
+  threadPool.async([&] {
+    if (LLVM_ENABLE_THREADS && config->timeTraceEnabled)
+      timeTraceProfilerInitialize(config->timeTraceGranularity, "writeMapFile");
+    writeMapFile();
+    if (LLVM_ENABLE_THREADS && config->timeTraceEnabled)
+      timeTraceProfilerFinishThread();
+  });
   finalizeLinkEditSegment();
   writeOutputFile();
 }
index 610ed9b..d51818e 100644 (file)
@@ -3,10 +3,11 @@
 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
 
-# RUN: %lld -map %t/map %t/test.o %t/foo.o -o %t/test-map
+# RUN: %lld -map %t/map %t/test.o %t/foo.o --time-trace -o %t/test-map
 # RUN: llvm-objdump --syms --section-headers %t/test-map > %t/objdump
 # RUN: cat %t/objdump %t/map > %t/out
 # RUN: FileCheck %s < %t/out
+# RUN: FileCheck %s --check-prefix=MAPFILE < %t/test-map.time-trace
 
 #--- foo.s
 .section __TEXT,obj
@@ -49,3 +50,5 @@ _main:
 # CHECK-NEXT: 0x[[#NUMBER]]    [  1]  _number
 # CHECK-NEXT: 0x[[#MAIN]]      [  1]  _main
 # CHECK-NEXT: 0x[[#FOO]]       [  2]  _foo
+
+# MAPFILE: "name":"Write map file"