diff options
author | Edwin Vane <edwin.vane@intel.com> | 2013-06-04 22:37:02 +0000 |
---|---|---|
committer | Edwin Vane <edwin.vane@intel.com> | 2013-06-04 22:37:02 +0000 |
commit | db7a52a6e71d7a8f521225f673ecd62e65a1b474 (patch) | |
tree | b249c759d4638dfc420f0ac0483abc105126f81f /clang-tools-extra/cpp11-migrate/Core/Transform.cpp | |
parent | 2a70c69d315a821cee5821c315d85e788b7a4c6d (diff) | |
download | bcm5719-llvm-db7a52a6e71d7a8f521225f673ecd62e65a1b474.tar.gz bcm5719-llvm-db7a52a6e71d7a8f521225f673ecd62e65a1b474.zip |
cpp11-migrate: collect performance timers per source file
Performance timers captured in each transform for all files they process are now collected and arranged per source file in preparation for writing to disk.
This revision is the last piece of the initial implementation of performance timer capturing.
llvm-svn: 183274
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/Core/Transform.cpp')
-rw-r--r-- | clang-tools-extra/cpp11-migrate/Core/Transform.cpp | 110 |
1 files changed, 57 insertions, 53 deletions
diff --git a/clang-tools-extra/cpp11-migrate/Core/Transform.cpp b/clang-tools-extra/cpp11-migrate/Core/Transform.cpp index c6bb835321d..f615867f89d 100644 --- a/clang-tools-extra/cpp11-migrate/Core/Transform.cpp +++ b/clang-tools-extra/cpp11-migrate/Core/Transform.cpp @@ -1,53 +1,57 @@ -#include "Core/Transform.h" -#include "clang/Basic/FileManager.h" -#include "clang/Basic/SourceManager.h" -#include "clang/Rewrite/Core/Rewriter.h" -#include "llvm/Support/raw_ostream.h" - -using namespace clang; - -void collectResults(clang::Rewriter &Rewrite, - const FileContentsByPath &InputStates, - FileContentsByPath &Results) { - // Copy the contents of InputStates to be modified. - Results = InputStates; - - for (Rewriter::buffer_iterator I = Rewrite.buffer_begin(), - E = Rewrite.buffer_end(); - I != E; ++I) { - const FileEntry *Entry = Rewrite.getSourceMgr().getFileEntryForID(I->first); - assert(Entry != 0 && "Expected a FileEntry"); - assert(Entry->getName() != 0 && - "Unexpected NULL return from FileEntry::getName()"); - - std::string ResultBuf; - - // Get a copy of the rewritten buffer from the Rewriter. - llvm::raw_string_ostream StringStream(ResultBuf); - I->second.write(StringStream); - - // Cause results to be written to ResultBuf. - StringStream.str(); - - // FIXME: Use move semantics to avoid copies of the buffer contents if - // benchmarking shows the copies are expensive, especially for large source - // files. - Results[Entry->getName()] = ResultBuf; - } -} - -bool Transform::handleBeginSource(CompilerInstance &CI, StringRef Filename) { - if (!EnableTiming) - return true; - - Timings.push_back(std::make_pair(Filename.str(), llvm::TimeRecord())); - Timings.back().second -= llvm::TimeRecord::getCurrentTime(true); - return true; -} - -void Transform::handleEndSource() { - if (!EnableTiming) - return; - - Timings.back().second += llvm::TimeRecord::getCurrentTime(false); -} +#include "Core/Transform.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void collectResults(clang::Rewriter &Rewrite,
+ const FileContentsByPath &InputStates,
+ FileContentsByPath &Results) {
+ // Copy the contents of InputStates to be modified.
+ Results = InputStates;
+
+ for (Rewriter::buffer_iterator I = Rewrite.buffer_begin(),
+ E = Rewrite.buffer_end();
+ I != E; ++I) {
+ const FileEntry *Entry = Rewrite.getSourceMgr().getFileEntryForID(I->first);
+ assert(Entry != 0 && "Expected a FileEntry");
+ assert(Entry->getName() != 0 &&
+ "Unexpected NULL return from FileEntry::getName()");
+
+ std::string ResultBuf;
+
+ // Get a copy of the rewritten buffer from the Rewriter.
+ llvm::raw_string_ostream StringStream(ResultBuf);
+ I->second.write(StringStream);
+
+ // Cause results to be written to ResultBuf.
+ StringStream.str();
+
+ // FIXME: Use move semantics to avoid copies of the buffer contents if
+ // benchmarking shows the copies are expensive, especially for large source
+ // files.
+ Results[Entry->getName()] = ResultBuf;
+ }
+}
+
+bool Transform::handleBeginSource(CompilerInstance &CI, StringRef Filename) {
+ if (!EnableTiming)
+ return true;
+
+ Timings.push_back(std::make_pair(Filename.str(), llvm::TimeRecord()));
+ Timings.back().second -= llvm::TimeRecord::getCurrentTime(true);
+ return true;
+}
+
+void Transform::handleEndSource() {
+ if (!EnableTiming)
+ return;
+
+ Timings.back().second += llvm::TimeRecord::getCurrentTime(false);
+}
+
+void Transform::addTiming(llvm::StringRef Label, llvm::TimeRecord Duration) {
+ Timings.push_back(std::make_pair(Label.str(), Duration));
+}
|