Skip to content

Commit

Permalink
Move to chrono timings
Browse files Browse the repository at this point in the history
  • Loading branch information
schnellerhase committed Oct 22, 2024
1 parent a1378ef commit 739846f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 60 deletions.
1 change: 0 additions & 1 deletion cpp/dolfinx/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/log.cpp
${CMAKE_CURRENT_SOURCE_DIR}/MPI.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Table.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Timer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TimeLogger.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TimeLogManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timing.cpp
Expand Down
44 changes: 0 additions & 44 deletions cpp/dolfinx/common/Timer.cpp

This file was deleted.

29 changes: 18 additions & 11 deletions cpp/dolfinx/common/Timer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2008 Anders Logg, 2015 Jan Blechta
// Copyright (C) 2008 Anders Logg, 2015 Jan Blechta, 2024 Paul T. Kühner
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
Expand All @@ -7,7 +7,7 @@
#pragma once

#include <array>
#include <boost/timer/timer.hpp>
#include <chrono>
#include <optional>
#include <string>

Expand All @@ -28,33 +28,40 @@ namespace dolfinx::common
///
/// list_timings();

template <typename chrono_timer = std::chrono::high_resolution_clock>
class Timer
{
public:
/// Create timer
///
/// If a task name is provided this enables logging to logger, otherwise (i.e.
/// no task provided) nothing gets logged.
Timer(std::optional<std::string> task = std::nullopt);
Timer(std::optional<std::string> task = std::nullopt) : _task(task) {}

/// Destructor
~Timer();
~Timer() = default;

/// Zero and start timer
void start();
void start() { _start_time = chrono_timer::now(); }

/// Stop timer, return wall time elapsed and store timing data into
/// logger
double stop();

/// Return wall, user and system time in seconds
std::array<double, 3> elapsed() const;
template <typename unit = std::chrono::nanoseconds>
double stop()
{
auto end_time = chrono_timer::now();
auto elapsed = unit(end_time - _start_time).count();
// TODO: reactivate
// if (_task.has_value())
// TimeLogManager::logger().register_timing(_task.value(), wall, user,
// system);
return elapsed;
}

private:
// Name of task
std::optional<std::string> _task;

// Implementation of timer
boost::timer::cpu_timer _timer;
chrono_timer::time_point _start_time;
};
} // namespace dolfinx::common
7 changes: 3 additions & 4 deletions python/dolfinx/wrappers/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ void common(nb::module_& m)
},
nb::arg("global"));
// dolfinx::common::Timer
nb::class_<dolfinx::common::Timer>(m, "Timer", "Timer class")
nb::class_<dolfinx::common::Timer<>>(m, "Timer", "Timer class")
.def(nb::init<std::optional<std::string>>(), nb::arg("task").none())
.def("start", &dolfinx::common::Timer::start, "Start timer")
.def("stop", &dolfinx::common::Timer::stop, "Stop timer")
.def("elapsed", &dolfinx::common::Timer::elapsed);
.def("start", &dolfinx::common::Timer<>::start, "Start timer")
.def("stop", &dolfinx::common::Timer<>::stop, "Stop timer");

// dolfinx::common::Timer enum
nb::enum_<dolfinx::TimingType>(m, "TimingType")
Expand Down

0 comments on commit 739846f

Please sign in to comment.