[PATCH] D117069: [lld-macho] Initialize separate time trace profiler for mapfile worker

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 11 17:10:48 PST 2022


int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added a project: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

After D115416: [lld-macho] Make writing map file asynchronous <https://reviews.llvm.org/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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117069

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


Index: lld/test/MachO/map-file.s
===================================================================
--- lld/test/MachO/map-file.s
+++ lld/test/MachO/map-file.s
@@ -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 @@
 # CHECK-NEXT: 0x[[#NUMBER]]    [  1]  _number
 # CHECK-NEXT: 0x[[#MAIN]]      [  1]  _main
 # CHECK-NEXT: 0x[[#FOO]]       [  2]  _foo
+
+# MAPFILE: "name":"Write map file"
Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -1175,7 +1175,13 @@
   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();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117069.399133.patch
Type: text/x-patch
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220112/c1db3197/attachment.bin>


More information about the llvm-commits mailing list