From b8302545fc28b46b5258a06c63e70ded4e345998 Mon Sep 17 00:00:00 2001 From: Rene Milk <rene.milk@uni-muenster.de> Date: Tue, 26 Jan 2016 10:30:15 +0100 Subject: [PATCH] rename Profiler -> Timings --- config.h.cmake | 4 +-- dune/xt/CMakeLists.txt | 2 +- dune/xt/common/test/profiler.cc | 20 ++++++------ dune/xt/common/{profiler.cc => timings.cc} | 38 +++++++++++----------- dune/xt/common/{profiler.hh => timings.hh} | 34 +++++++++---------- 5 files changed, 49 insertions(+), 49 deletions(-) rename dune/xt/common/{profiler.cc => timings.cc} (90%) rename dune/xt/common/{profiler.hh => timings.hh} (89%) diff --git a/config.h.cmake b/config.h.cmake index 2e9c8eed9..9467ab155 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -51,8 +51,8 @@ #endif /* needed in dune/xt/common/profiler.hh */ -#ifndef DUNE_XT_COMMON_DO_PROFILE -# define DUNE_XT_COMMON_DO_PROFILE 0 +#ifndef DUNE_XT_COMMON_DO_TIMING +# define DUNE_XT_COMMON_DO_TIMING 0 #endif /*** Silence implicitly False evaluation of undefined macro warnings ****/ diff --git a/dune/xt/CMakeLists.txt b/dune/xt/CMakeLists.txt index 5ca7c1b3c..629b228ca 100644 --- a/dune/xt/CMakeLists.txt +++ b/dune/xt/CMakeLists.txt @@ -13,7 +13,7 @@ set(lib_dune_xt_common_sources common/filesystem.cc common/logging.cc common/timedlogging.cc common/logstreams.cc - common/profiler.cc + common/timings.cc common/configuration.cc common/signals.cc common/math.cc diff --git a/dune/xt/common/test/profiler.cc b/dune/xt/common/test/profiler.cc index 9e9a0dfcd..d1debe1a7 100644 --- a/dune/xt/common/test/profiler.cc +++ b/dune/xt/common/test/profiler.cc @@ -9,7 +9,7 @@ #include <dune/xt/common/test/main.hxx> -#include <dune/xt/common/profiler.hh> +#include <dune/xt/common/timings.hh> #include <dune/xt/common/math.hh> #include <dune/xt/common/ranges.hh> @@ -30,10 +30,10 @@ static double confidence_margin() TEST(ProfilerTest, Timing) { for (auto i : value_range(1, 4)) { - DXTC_PROFILER.start_timing("ProfilerTest.Timing"); + DXTC_TIMINGS.start_timing("ProfilerTest.Timing"); busywait(wait_ms); - DXTC_PROFILER.stop_timing("ProfilerTest.Timing"); - EXPECT_GE(DXTC_PROFILER.get_timing("ProfilerTest.Timing"), i * wait_ms * confidence_margin()); + DXTC_TIMINGS.stop_timing("ProfilerTest.Timing"); + EXPECT_GE(DXTC_TIMINGS.get_timing("ProfilerTest.Timing"), i * wait_ms * confidence_margin()); } } @@ -43,13 +43,13 @@ TEST(ProfilerTest, ScopedTiming) for (auto DUNE_UNUSED(i) : dvalue_range) { scoped_busywait("ProfilerTest.ScopedTiming", wait_ms); } - EXPECT_GE(DXTC_PROFILER.get_timing("ProfilerTest.ScopedTiming"), long(dvalue_range.size() * wait_ms)); + EXPECT_GE(DXTC_TIMINGS.get_timing("ProfilerTest.ScopedTiming"), long(dvalue_range.size() * wait_ms)); } TEST(ProfilerTest, OutputConstness) { - DXTC_PROFILER.reset(1); - const auto& prof = DXTC_PROFILER; + DXTC_TIMINGS.reset(1); + const auto& prof = DXTC_TIMINGS; prof.output_averaged(0, 0); prof.output_timings("timings"); prof.output_timings(dev_null); @@ -57,13 +57,13 @@ TEST(ProfilerTest, OutputConstness) TEST(ProfilerTest, ExpectedFailures) { - EXPECT_THROW(DXTC_PROFILER.reset(0), Dune::RangeError); - EXPECT_THROW(DXTC_PROFILER.stop_timing("This_section_was_never_started"), Dune::RangeError); + EXPECT_THROW(DXTC_TIMINGS.reset(0), Dune::RangeError); + EXPECT_THROW(DXTC_TIMINGS.stop_timing("This_section_was_never_started"), Dune::RangeError); } TEST(ProfilerTest, NestedTiming) { - auto& prof = DXTC_PROFILER; + auto& prof = DXTC_TIMINGS; prof.reset(1); prof.start_timing("NestedTiming.Outer"); busywait(100); diff --git a/dune/xt/common/profiler.cc b/dune/xt/common/timings.cc similarity index 90% rename from dune/xt/common/profiler.cc rename to dune/xt/common/timings.cc index 8f6d6d071..bd580adc5 100644 --- a/dune/xt/common/profiler.cc +++ b/dune/xt/common/timings.cc @@ -9,7 +9,7 @@ // Tobias Leibner (2014) #include "config.h" -#include "profiler.hh" +#include "timings.hh" #include <dune/common/version.hh> @@ -76,7 +76,7 @@ TimingData::DeltaType TimingData::delta() const return {{cast(elapsed.wall * scale), cast(elapsed.user * scale), cast(elapsed.system * scale)}}; } -void Profiler::reset_timing(const std::string section_name) +void Timings::reset_timing(const std::string section_name) { try { stop_timing(section_name); @@ -87,7 +87,7 @@ void Profiler::reset_timing(const std::string section_name) current_data[section_name] = {{0, 0, 0}}; } -void Profiler::start_timing(const std::string section_name) +void Timings::start_timing(const std::string section_name) { std::lock_guard<std::mutex> lock(mutex_); if (current_run_number_ >= datamaps_.size()) { @@ -108,7 +108,7 @@ void Profiler::start_timing(const std::string section_name) DXTC_LIKWID_BEGIN_SECTION(section_name) } // StartTiming -long Profiler::stop_timing(const std::string section_name) +long Timings::stop_timing(const std::string section_name) { DXTC_LIKWID_END_SECTION(section_name) assert(current_run_number_ < datamaps_.size()); @@ -129,18 +129,18 @@ long Profiler::stop_timing(const std::string section_name) return delta[0]; } // StopTiming -long Profiler::get_timing(const std::string section_name) const +long Timings::get_timing(const std::string section_name) const { return get_delta(section_name)[0]; } -TimingData::DeltaType Profiler::get_delta(const std::string section_name) const +TimingData::DeltaType Timings::get_delta(const std::string section_name) const { assert(current_run_number_ < datamaps_.size()); return get_timing_idx(section_name, current_run_number_); } -TimingData::DeltaType Profiler::get_timing_idx(const std::string section_name, const size_t run_number) const +TimingData::DeltaType Timings::get_timing_idx(const std::string section_name, const size_t run_number) const { assert(run_number < datamaps_.size()); const Datamap& data = datamaps_[run_number]; @@ -155,7 +155,7 @@ TimingData::DeltaType Profiler::get_timing_idx(const std::string section_name, c return section->second; } -void Profiler::stop_all() +void Timings::stop_all() { for (auto&& section : known_timers_map_) { try { @@ -165,7 +165,7 @@ void Profiler::stop_all() } } // GetTiming -void Profiler::reset(const size_t numRuns) +void Timings::reset(const size_t numRuns) { if (!(numRuns > 0)) DUNE_THROW(Dune::RangeError, "preparing the profiler for 0 runs is moronic"); @@ -174,12 +174,12 @@ void Profiler::reset(const size_t numRuns) current_run_number_ = 0; } // Reset -void Profiler::add_count(const size_t num) +void Timings::add_count(const size_t num) { counters_[num] += 1; } -void Profiler::next_run() +void Timings::next_run() { // set all known timers to "stopped" for (auto& timer_it : known_timers_map_) @@ -187,7 +187,7 @@ void Profiler::next_run() current_run_number_++; } -void Profiler::output_averaged(const int refineLevel, const long numDofs, const double scale_factor) const +void Timings::output_averaged(const int refineLevel, const long numDofs, const double scale_factor) const { const auto& comm = Dune::MPIHelper::getCollectiveCommunication(); const int numProce = comm.size(); @@ -234,13 +234,13 @@ void Profiler::output_averaged(const int refineLevel, const long numDofs, const csv.close(); } // OutputAveraged -void Profiler::set_outputdir(const std::string dir) +void Timings::set_outputdir(const std::string dir) { output_dir_ = dir; test_create_directory(output_dir_); } -void Profiler::output_timings(const std::string csv) const +void Timings::output_timings(const std::string csv) const { const auto& comm = Dune::MPIHelper::getCollectiveCommunication(); boost::filesystem::path dir(output_dir_); @@ -256,7 +256,7 @@ void Profiler::output_timings(const std::string csv) const } } -void Profiler::output_timings_all(std::ostream& out) const +void Timings::output_timings_all(std::ostream& out) const { if (datamaps_.size() < 1) return; @@ -300,7 +300,7 @@ void Profiler::output_timings_all(std::ostream& out) const out << stash.str(); } -void Profiler::output_timings(std::ostream& out) const +void Timings::output_timings(std::ostream& out) const { if (datamaps_.size() < 1) return; @@ -319,7 +319,7 @@ void Profiler::output_timings(std::ostream& out) const } } -Profiler::Profiler() +Timings::Timings() : csv_sep_(",") { DXTC_LIKWID_INIT; @@ -327,7 +327,7 @@ Profiler::Profiler() set_outputdir("./profiling"); } -Profiler::~Profiler() +Timings::~Timings() { DXTC_LIKWID_CLOSE; } @@ -340,7 +340,7 @@ OutputScopedTiming::OutputScopedTiming(const std::string& section_name, std::ost OutputScopedTiming::~OutputScopedTiming() { - const auto duration = profiler().stop_timing(section_name_); + const auto duration = timings().stop_timing(section_name_); out_ << "Executing " << section_name_ << " took " << duration / 1000.f << "s\n"; } diff --git a/dune/xt/common/profiler.hh b/dune/xt/common/timings.hh similarity index 89% rename from dune/xt/common/profiler.hh rename to dune/xt/common/timings.hh index ac6d71b6e..aeaecde9a 100644 --- a/dune/xt/common/profiler.hh +++ b/dune/xt/common/timings.hh @@ -34,10 +34,10 @@ namespace Dune { namespace XT { namespace Common { -class Profiler; +class Timings; //! XT::Profiler global instance -Profiler& profiler(); +Timings& timings(); //! wraps name, start- and end time for one timing section struct TimingData @@ -64,19 +64,19 @@ public: //! a utility class to time a limited scope of code class ScopedTiming; -/** \brief simple inline profiling class +/** \brief simple inline timing class * - User can set as many (even nested) named sections whose total (=system+user) time will be computed across all *program * instances.\n * - Provides csv-conform output of process-averaged runtimes. **/ -class Profiler +class Timings { - friend Profiler& profiler(); + friend Timings& timings(); private: - Profiler(); - ~Profiler(); + Timings(); + ~Timings(); typedef std::map<std::string, std::pair<bool, PerThreadValue<TimingData>>> KnownTimersMap; //! section name -> seconds @@ -140,17 +140,17 @@ private: const std::string csv_sep_; std::mutex mutex_; - static Profiler& instance() + static Timings& instance() { - static Profiler pf; + static Timings pf; return pf; } }; //! global profiler object -inline Profiler& profiler() +inline Timings& timings() { - return Profiler::instance(); + return Timings::instance(); } class ScopedTiming : public boost::noncopyable @@ -162,12 +162,12 @@ public: inline ScopedTiming(const std::string& section_name) : section_name_(section_name) { - profiler().start_timing(section_name_); + timings().start_timing(section_name_); } inline ~ScopedTiming() { - profiler().stop_timing(section_name_); + timings().stop_timing(section_name_); } }; @@ -185,12 +185,12 @@ protected: } // namespace XT } // namespace Dune -#define DXTC_PROFILER profiler() +#define DXTC_TIMINGS timings() -#if DUNE_XT_COMMON_DO_PROFILE -#define DUNE_XT_COMMON_PROFILE_SCOPE(section_name) ScopedTiming DXTC_UNUSED(timer)(section_name) +#if DUNE_XT_COMMON_DO_TIMING +#define DUNE_XT_COMMON_TIMING_SCOPE(section_name) ScopedTiming DXTC_UNUSED(timer)(section_name) #else -#define DUNE_XT_COMMON_PROFILE_SCOPE(section_name) +#define DUNE_XT_COMMON_TIMING_SCOPE(section_name) #endif #endif // DUNE_XT_COMMON_PROFILER_HH -- GitLab