diff options
author | Edwin Vane <edwin.vane@intel.com> | 2013-05-30 17:48:11 +0000 |
---|---|---|
committer | Edwin Vane <edwin.vane@intel.com> | 2013-05-30 17:48:11 +0000 |
commit | b76a13eb4ee46fabb7eb55fb13d5687d25db800f (patch) | |
tree | e2c98f8b18a66acacdcd7c9127874891eb99290b /clang-tools-extra/cpp11-migrate/Core | |
parent | 8fe6d11b84ddbde08aeeae528e208e82a3ecc3c5 (diff) | |
download | bcm5719-llvm-b76a13eb4ee46fabb7eb55fb13d5687d25db800f.tar.gz bcm5719-llvm-b76a13eb4ee46fabb7eb55fb13d5687d25db800f.zip |
cpp11-migrate: Transforms collect timing data.
Using updated form of newFrontendActionFactory(), Transforms now automatically
measure, if requested, how long it takes to apply a MatchFinder to a source
file. Other per-transform overhead, e.g. applying replacements, is not
currently measured. This behaviour is disabled for now and soon will be
connected to a new command line arg.
llvm-svn: 182942
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/Core')
4 files changed, 66 insertions, 8 deletions
diff --git a/clang-tools-extra/cpp11-migrate/Core/Transform.cpp b/clang-tools-extra/cpp11-migrate/Core/Transform.cpp index d235356075f..c6bb835321d 100644 --- a/clang-tools-extra/cpp11-migrate/Core/Transform.cpp +++ b/clang-tools-extra/cpp11-migrate/Core/Transform.cpp @@ -35,3 +35,19 @@ void collectResults(clang::Rewriter &Rewrite, 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); +} diff --git a/clang-tools-extra/cpp11-migrate/Core/Transform.h b/clang-tools-extra/cpp11-migrate/Core/Transform.h index adc02989536..73a2a00a816 100644 --- a/clang-tools-extra/cpp11-migrate/Core/Transform.h +++ b/clang-tools-extra/cpp11-migrate/Core/Transform.h @@ -17,6 +17,8 @@ #include <string> #include <vector> +#include "clang/Tooling/Tooling.h" +#include "llvm/Support/Timer.h" // For RewriterContainer #include "clang/Rewrite/Core/Rewriter.h" @@ -104,9 +106,23 @@ private: }; /// \brief Abstract base class for all C++11 migration transforms. -class Transform { +/// +/// Per-source performance timing is handled by the callbacks +/// handleBeginSource() and handleEndSource() if timing is enabled. See +/// clang::tooling::newFrontendActionFactory() for how to register +/// a Transform object for callbacks. +class Transform : public clang::tooling::SourceFileCallbacks { public: - Transform(llvm::StringRef Name) : Name(Name) { + /// \brief Constructor + /// \param Name Name of the transform for human-readable purposes (e.g. -help + /// text) + /// \param EnableTiming Enable the timing of the duration between calls to + /// handleBeginSource() and handleEndSource(). When a Transform object is + /// registered for FrontendAction source file callbacks, this behaviour can + /// be used to time the application of a MatchFinder by subclasses. Durations + /// are automatically stored in a TimingVec. + Transform(llvm::StringRef Name, bool EnableTiming) + : Name(Name), EnableTiming(EnableTiming) { Reset(); } @@ -156,7 +172,31 @@ public: DeferredChanges = 0; } + /// \brief Callback for notification of the start of processing of a source + /// file by a FrontendAction. Starts a performance timer if timing was + /// enabled. + virtual bool handleBeginSource(clang::CompilerInstance &CI, + llvm::StringRef Filename) LLVM_OVERRIDE; + + /// \brief Callback for notification of the end of processing of a source + /// file by a FrontendAction. Stops a performance timer if timing was enabled + /// and records the elapsed time. For a given source, handleBeginSource() and + /// handleEndSource() are expected to be called in pairs. + virtual void handleEndSource() LLVM_OVERRIDE; + + /// \brief Performance timing data is stored as a vector of pairs. Pairs are + /// formed of: + /// \li Name of source file. + /// \li Elapsed time. + typedef std::vector<std::pair<std::string, llvm::TimeRecord> > TimingVec; + + /// \brief Return an iterator to the start of collected timing data. + TimingVec::const_iterator timing_begin() const { return Timings.begin(); } + /// \brief Return an iterator to the start of collected timing data. + TimingVec::const_iterator timing_end() const { return Timings.end(); } + protected: + void setAcceptedChanges(unsigned Changes) { AcceptedChanges = Changes; } @@ -169,6 +209,8 @@ protected: private: const std::string Name; + bool EnableTiming; + TimingVec Timings; unsigned AcceptedChanges; unsigned RejectedChanges; unsigned DeferredChanges; diff --git a/clang-tools-extra/cpp11-migrate/Core/Transforms.cpp b/clang-tools-extra/cpp11-migrate/Core/Transforms.cpp index d7eae694870..85c0e2103a7 100644 --- a/clang-tools-extra/cpp11-migrate/Core/Transforms.cpp +++ b/clang-tools-extra/cpp11-migrate/Core/Transforms.cpp @@ -35,11 +35,11 @@ void Transforms::registerTransform(llvm::StringRef OptName, new cl::opt<bool>(OptName.data(), cl::desc(Description.data())), Creator)); } -void Transforms::createSelectedTransforms() { +void Transforms::createSelectedTransforms(bool EnableTiming) { for (OptionVec::iterator I = Options.begin(), E = Options.end(); I != E; ++I) { if (*I->first) { - ChosenTransforms.push_back(I->second()); + ChosenTransforms.push_back(I->second(EnableTiming)); } } } diff --git a/clang-tools-extra/cpp11-migrate/Core/Transforms.h b/clang-tools-extra/cpp11-migrate/Core/Transforms.h index 67e38b025c8..b19b0316d90 100644 --- a/clang-tools-extra/cpp11-migrate/Core/Transforms.h +++ b/clang-tools-extra/cpp11-migrate/Core/Transforms.h @@ -28,10 +28,10 @@ class Option; } // namespace llvm class Transform; -typedef Transform *(*TransformCreator)(); +typedef Transform *(*TransformCreator)(bool); template <typename T> -Transform *ConstructTransform() { - return new T(); +Transform *ConstructTransform(bool EnableTiming) { + return new T(EnableTiming); } /// \brief Class encapsulating the creation of command line bool options @@ -55,7 +55,7 @@ public: /// \brief Instantiate all transforms that were selected on the command line. /// /// Call *after* parsing options. - void createSelectedTransforms(); + void createSelectedTransforms(bool EnableTiming); /// \brief Return an iterator to the start of a container of instantiated /// transforms. |