[PATCH] [ELF] Implement --stats

Davide Italiano davide at freebsd.org
Sun Feb 15 16:46:50 PST 2015


Hi shankar.easwaran, ruiu, Bigcheese, atanasyan,

I used this quite a bit for some internal benchmarking, and seems to be working (at least for the time side). GetMallocUsage() appears to be broken on FreeBSD-11 + tcmalloc(), and I'll investigate on the reason, but I would like to get another pair of eye on this patch in the meanwhile.
I can write an unit test, if needed.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D7657

Files:
  include/lld/ReaderWriter/ELFLinkingContext.h
  lib/Driver/GnuLdDriver.cpp
  lib/Driver/GnuLdOptions.td
  lib/ReaderWriter/ELF/ELFLinkingContext.cpp

Index: include/lld/ReaderWriter/ELFLinkingContext.h
===================================================================
--- include/lld/ReaderWriter/ELFLinkingContext.h
+++ include/lld/ReaderWriter/ELFLinkingContext.h
@@ -291,6 +291,10 @@
   bool stripSymbols() const { return _stripSymbols; }
   void setStripSymbols(bool strip) { _stripSymbols = strip; }
 
+  /// \brief Collect statistics.
+  bool collectStats() const { return _collectStats; }
+  void setCollectStats(bool s) { _collectStats = s; }
+
   // We can parse several linker scripts via command line whose ASTs are stored
   // in the current linking context via addLinkerScript().
   void addLinkerScript(std::unique_ptr<script::Parser> script) {
@@ -329,6 +333,7 @@
   bool _stripSymbols;
   bool _alignSegments;
   bool _nostdlib;
+  bool _collectStats;
   llvm::Optional<uint64_t> _maxPageSize;
 
   OutputMagic _outputMagic;
Index: lib/Driver/GnuLdDriver.cpp
===================================================================
--- lib/Driver/GnuLdDriver.cpp
+++ lib/Driver/GnuLdDriver.cpp
@@ -32,6 +32,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstring>
 #include <tuple>
@@ -171,7 +172,15 @@
     return false;
   if (!options)
     return true;
-  return link(*options, diag);
+  bool linked = link(*options, diag);
+
+  // Handle --stats.
+  if (options->collectStats()) {
+    llvm::TimeRecord t = llvm::TimeRecord::getCurrentTime(true);
+    diag << "total time in link " << t.getProcessTime() << "\n";
+    diag << "data size " << t.getMemUsed() << "\n";
+  }
+  return linked;
 }
 
 static llvm::Optional<llvm::Triple::ArchType>
@@ -445,6 +454,11 @@
     ctx->setAllowRemainingUndefines(true);
   }
 
+  // Handle --stats.
+  if (parsedArgs->hasArg(OPT_stats)) {
+    ctx->setCollectStats(true);
+  }
+
   // Figure out if the output type is nmagic/omagic
   if (auto *arg = parsedArgs->getLastArg(
         OPT_nmagic, OPT_omagic, OPT_no_omagic)) {
Index: lib/Driver/GnuLdOptions.td
===================================================================
--- lib/Driver/GnuLdOptions.td
+++ lib/Driver/GnuLdOptions.td
@@ -277,6 +277,8 @@
 def t : Flag<["-"], "t">,
      HelpText<"Print the names of the input files as ld processes them">,
      Group<grp_tracingopts>;
+def stats : Flag<["--"], "stats">,
+     HelpText<"Print time and memory usage stats">, Group<grp_tracingopts>;
 
 //===----------------------------------------------------------------------===//
 /// Extensions
Index: lib/ReaderWriter/ELF/ELFLinkingContext.cpp
===================================================================
--- lib/ReaderWriter/ELF/ELFLinkingContext.cpp
+++ lib/ReaderWriter/ELF/ELFLinkingContext.cpp
@@ -61,7 +61,7 @@
       _mergeCommonStrings(false), _useShlibUndefines(true),
       _dynamicLinkerArg(false), _noAllowDynamicLibraries(false),
       _mergeRODataToTextSegment(true), _demangle(true),
-      _stripSymbols(false), _alignSegments(true),
+      _stripSymbols(false), _collectStats(false), _alignSegments(true),
       _outputMagic(OutputMagic::DEFAULT), _initFunction("_init"),
       _finiFunction("_fini"), _sysrootPath("") {}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7657.19993.patch
Type: text/x-patch
Size: 3269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150216/2bfc46ec/attachment.bin>


More information about the llvm-commits mailing list