Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove TimeLogManager and make TimeLogger singleton #3494

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 0 additions & 2 deletions cpp/dolfinx/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ set(HEADERS_common
${CMAKE_CURRENT_SOURCE_DIR}/Table.h
${CMAKE_CURRENT_SOURCE_DIR}/Timer.h
${CMAKE_CURRENT_SOURCE_DIR}/TimeLogger.h
${CMAKE_CURRENT_SOURCE_DIR}/TimeLogManager.h
${CMAKE_CURRENT_SOURCE_DIR}/timing.h
${CMAKE_CURRENT_SOURCE_DIR}/utils.h
PARENT_SCOPE
Expand All @@ -26,6 +25,5 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/MPI.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Table.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TimeLogger.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TimeLogManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timing.cpp
)
18 changes: 0 additions & 18 deletions cpp/dolfinx/common/TimeLogManager.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions cpp/dolfinx/common/TimeLogManager.h

This file was deleted.

7 changes: 7 additions & 0 deletions cpp/dolfinx/common/TimeLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
using namespace dolfinx;
using namespace dolfinx::common;

//-----------------------------------------------------------------------------
TimeLogger& TimeLogger::instance()
{
static TimeLogger _instance{};
return _instance;
}

//-----------------------------------------------------------------------------
void TimeLogger::register_timing(
std::string task, std::chrono::duration<double, std::ratio<1>> time)
Expand Down
29 changes: 17 additions & 12 deletions cpp/dolfinx/common/TimeLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@

namespace dolfinx::common
{
/// Timer logging
/// @brief Time logger maintaining data collected by Timer, if registered.
///
/// @note This is a monotstate, i.e. the data members are static and thus
/// timings are aggregated into a single map.
class TimeLogger
{
public:
/// Constructor
TimeLogger() = default;

// This class is used as a singleton and thus should not allow copies.
TimeLogger(const TimeLogger&) = delete;

// This class is used as a singleton and thus should not allow copies.
TimeLogger& operator=(const TimeLogger&) = delete;

/// Destructor
~TimeLogger() = default;
static TimeLogger& instance();

/// Register timing (for later summary)
void register_timing(std::string task,
Expand Down Expand Up @@ -58,6 +51,18 @@ class TimeLogger
timings() const;

private:
/// Constructor
TimeLogger() = default;

// This class is used as a singleton and thus should not allow copies.
TimeLogger(const TimeLogger&) = delete;

// This class is used as a singleton and thus should not allow copies.
TimeLogger& operator=(const TimeLogger&) = delete;

/// Destructor
~TimeLogger() = default;

// List of timings for tasks, map from string to (num_timings,
// total_wall_time)
std::map<std::string,
Expand Down
7 changes: 4 additions & 3 deletions cpp/dolfinx/common/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

#pragma once

#include "TimeLogManager.h"
#include <chrono>
#include <optional>
#include <stdexcept>
#include <string>

#include "TimeLogger.h"

namespace dolfinx::common
{
/// @brief Timer for measuring and logging elapsed time durations.
Expand Down Expand Up @@ -56,7 +57,7 @@ class Timer
if (_start_time.has_value() and _task.has_value())
{
_acc += T::now() - *_start_time;
TimeLogManager::logger().register_timing(*_task, _acc);
TimeLogger::instance().register_timing(*_task, _acc);
}
}

Expand Down Expand Up @@ -121,7 +122,7 @@ class Timer

if (_task.has_value())
{
TimeLogManager::logger().register_timing(*_task, _acc);
TimeLogger::instance().register_timing(*_task, _acc);
_task = std::nullopt;
}
}
Expand Down
9 changes: 4 additions & 5 deletions cpp/dolfinx/common/timing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,30 @@

#include "timing.h"
#include "Table.h"
#include "TimeLogManager.h"
#include "TimeLogger.h"
#include "Timer.h"

//-----------------------------------------------------------------------
dolfinx::Table dolfinx::timing_table()
{
return dolfinx::common::TimeLogManager::logger().timing_table();
return dolfinx::common::TimeLogger::instance().timing_table();
}
//-----------------------------------------------------------------------------
void dolfinx::list_timings(MPI_Comm comm, Table::Reduction reduction)
{
dolfinx::common::TimeLogManager::logger().list_timings(comm, reduction);
dolfinx::common::TimeLogger::instance().list_timings(comm, reduction);
}
//-----------------------------------------------------------------------------
std::pair<int, std::chrono::duration<double, std::ratio<1>>>
dolfinx::timing(std::string task)
{
return dolfinx::common::TimeLogManager::logger().timing(task);
return dolfinx::common::TimeLogger::instance().timing(task);
}
//-----------------------------------------------------------------------------
std::map<std::string,
std::pair<int, std::chrono::duration<double, std::ratio<1>>>>
dolfinx::timings()
{
return dolfinx::common::TimeLogManager::logger().timings();
return dolfinx::common::TimeLogger::instance().timings();
}
//-----------------------------------------------------------------------------
Loading