[PATCH] D92146: [Timer] [TableGen] Add a function to TimerGroup to suppress report sorting

Paul C. Anagnostopoulos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 25 18:09:29 PST 2020


Paul-C-Anagnostopoulos created this revision.
Paul-C-Anagnostopoulos added a reviewer: lattner.
Herald added subscribers: llvm-commits, dexonsmith, mgrang, hiraditya.
Herald added a project: LLVM.
Paul-C-Anagnostopoulos requested review of this revision.

This little patch adds the SortByWallClock() function to the TimerGroup class. You can use this function to suppress the usual sorting of the timer reports in wall clock order. I find that order confusing, since the timers move around in the report depending on their percentage of the total wall clock time. Without the sort, the timers appear in the order they were created, which is good for timing sequential phases.

I added one more timer to DAGISelEmitter so I could do a thorough test. The unsorted report looks like:

-------------------------------------------------------------------------
-------------------------------------------------------------------------

  TableGen Phase Timing

-------------------------------------------------------------------------
-------------------------------------------------------------------------

  Total Execution Time: 128.5448 seconds (128.6254 wall clock)
  
   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
  15.3505 ( 12.0%)   0.0156 ( 14.3%)  15.3661 ( 12.0%)  15.3869 ( 12.0%)  Parse, build records
  37.8926 ( 29.5%)   0.0468 ( 42.9%)  37.9394 ( 29.5%)  37.9292 ( 29.5%)  Parse patterns
   2.2464 (  1.7%)   0.0000 (  0.0%)   2.2464 (  1.7%)   2.2571 (  1.8%)  Sort patterns
  68.9056 ( 53.6%)   0.0312 ( 28.6%)  68.9368 ( 53.6%)  68.9859 ( 53.6%)  Convert to matchers
   1.0764 (  0.8%)   0.0000 (  0.0%)   1.0764 (  0.8%)   1.0841 (  0.8%)  Optimize matchers
   2.9640 (  2.3%)   0.0156 ( 14.3%)   2.9796 (  2.3%)   2.9772 (  2.3%)  Emit matcher table
   0.0000 (  0.0%)   0.0000 (  0.0%)   0.0000 (  0.0%)   0.0050 (  0.0%)  Write output
  128.4356 (100.0%)   0.1092 (100.0%)  128.5448 (100.0%)  128.6254 (100.0%)  Total


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92146

Files:
  llvm/include/llvm/Support/Timer.h
  llvm/include/llvm/TableGen/Record.h
  llvm/lib/Support/Timer.cpp
  llvm/utils/TableGen/DAGISelEmitter.cpp


Index: llvm/utils/TableGen/DAGISelEmitter.cpp
===================================================================
--- llvm/utils/TableGen/DAGISelEmitter.cpp
+++ llvm/utils/TableGen/DAGISelEmitter.cpp
@@ -189,6 +189,7 @@
 namespace llvm {
 
 void EmitDAGISel(RecordKeeper &RK, raw_ostream &OS) {
+  RK.startTimer("Parse patterns");
   DAGISelEmitter(RK).run(OS);
 }
 
Index: llvm/lib/Support/Timer.cpp
===================================================================
--- llvm/lib/Support/Timer.cpp
+++ llvm/lib/Support/Timer.cpp
@@ -302,7 +302,8 @@
 
 void TimerGroup::PrintQueuedTimers(raw_ostream &OS) {
   // Sort the timers in descending order by amount of time taken.
-  llvm::sort(TimersToPrint);
+  if (SortByWallTime)
+    llvm::sort(TimersToPrint);
 
   TimeRecord Total;
   for (const PrintRecord &Record : TimersToPrint)
Index: llvm/include/llvm/TableGen/Record.h
===================================================================
--- llvm/include/llvm/TableGen/Record.h
+++ llvm/include/llvm/TableGen/Record.h
@@ -1821,6 +1821,7 @@
   /// Start phase timing; called if the --time-phases option is specified.
   void startPhaseTiming() {
     TimingGroup = new TimerGroup("TableGen", "TableGen Phase Timing");
+    TimingGroup->sortByWallTime(false);
   }
 
   /// Start timing a phase. Automatically stops any previous phase timer.
Index: llvm/include/llvm/Support/Timer.h
===================================================================
--- llvm/include/llvm/Support/Timer.h
+++ llvm/include/llvm/Support/Timer.h
@@ -187,6 +187,7 @@
   std::string Description;
   Timer *FirstTimer = nullptr; ///< First timer in the group.
   std::vector<PrintRecord> TimersToPrint;
+  bool SortByWallTime = true;  ///< Sort by wall time if true; otherwise no sort.
 
   TimerGroup **Prev; ///< Pointer to Next field of previous timergroup in list.
   TimerGroup *Next;  ///< Pointer to next timergroup in list.
@@ -206,6 +207,10 @@
     Description.assign(NewDescription.begin(), NewDescription.end());
   }
 
+  /// If true, sort report by wall time. If false, keep report in the
+  /// order timers were started.
+  void sortByWallTime(bool Sort) { SortByWallTime = Sort; }
+
   /// Print any started timers in this group, optionally resetting timers after
   /// printing them.
   void print(raw_ostream &OS, bool ResetAfterPrint = false);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92146.307737.patch
Type: text/x-patch
Size: 2347 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201126/6a929438/attachment-0001.bin>


More information about the llvm-commits mailing list