[llvm] r207385 - Teach the pass manager's execution dump to print the current time before

Chandler Carruth chandlerc at gmail.com
Sun Apr 27 16:59:25 PDT 2014


Author: chandlerc
Date: Sun Apr 27 18:59:25 2014
New Revision: 207385

URL: http://llvm.org/viewvc/llvm-project?rev=207385&view=rev
Log:
Teach the pass manager's execution dump to print the current time before
each line. This is particularly nice for tracking which run of
a particular pass over a particular function was slow.

This also required making the TimeValue string much more useful. First,
there is a standard format for writing out a date and time. Let's use
that rather than strings that would have to be parsed. Second, actually
output the nanosecond resolution that timevalue claims to have.

This is proving useful working on PR19499, so I figured it would be
generally useful to commit.

Modified:
    llvm/trunk/lib/IR/LegacyPassManager.cpp
    llvm/trunk/lib/Support/Unix/TimeValue.inc

Modified: llvm/trunk/lib/IR/LegacyPassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LegacyPassManager.cpp?rev=207385&r1=207384&r2=207385&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LegacyPassManager.cpp (original)
+++ llvm/trunk/lib/IR/LegacyPassManager.cpp Sun Apr 27 18:59:25 2014
@@ -22,6 +22,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Mutex.h"
+#include "llvm/Support/TimeValue.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
@@ -1158,7 +1159,8 @@ void PMDataManager::dumpPassInfo(Pass *P
                                  StringRef Msg) {
   if (PassDebugging < Executions)
     return;
-  dbgs() << (void*)this << std::string(getDepth()*2+1, ' ');
+  dbgs() << "[" << sys::TimeValue::now().str() << "] " << (void *)this
+         << std::string(getDepth() * 2 + 1, ' ');
   switch (S1) {
   case EXECUTION_MSG:
     dbgs() << "Executing Pass '" << P->getPassName();

Modified: llvm/trunk/lib/Support/Unix/TimeValue.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/TimeValue.inc?rev=207385&r1=207384&r2=207385&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/TimeValue.inc (original)
+++ llvm/trunk/lib/Support/Unix/TimeValue.inc Sun Apr 27 18:59:25 2014
@@ -26,9 +26,11 @@ std::string TimeValue::str() const {
   struct tm Storage;
   struct tm *LT = ::localtime_r(&OurTime, &Storage);
   assert(LT);
-  char Buffer[25];
-  strftime(Buffer, 25, "%b %e %H:%M %Y", LT);
-  return std::string(Buffer);
+  char Buffer1[sizeof("YYYY-MM-DD HH:MM:SS")];
+  strftime(Buffer1, sizeof(Buffer1), "%Y-%m-%d %H:%M:%S", LT);
+  char Buffer2[sizeof("YYYY-MM-DD HH:MM:SS.MMMUUUNNN")];
+  snprintf(Buffer2, sizeof(Buffer2), "%s.%.9u", Buffer1, this->nanoseconds());
+  return std::string(Buffer2);
 }
 
 TimeValue TimeValue::now() {





More information about the llvm-commits mailing list