Skip to content

Commit

Permalink
Adapt Timer
Browse files Browse the repository at this point in the history
  • Loading branch information
schnellerhase committed Jul 31, 2024
1 parent 5d15d26 commit acc314a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
18 changes: 9 additions & 9 deletions cpp/dolfinx/common/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "Timer.h"
#include <optional>
#include <stdexcept>

#include "TimeLogManager.h"
#include "TimeLogger.h"
#include <stdexcept>
#include "Timer.h"

using namespace dolfinx;
using namespace dolfinx::common;

//-----------------------------------------------------------------------------
Timer::Timer() : Timer::Timer("")
Timer::Timer(std::optional<std::string> task) : _task("")
{
// Do nothing
}
//-----------------------------------------------------------------------------
Timer::Timer(const std::string& task) : _task(task)
{
// Do nothing
if (task)
{
_task = std::move(task.value());
}
}
//-----------------------------------------------------------------------------
Timer::~Timer()
Expand Down
9 changes: 4 additions & 5 deletions cpp/dolfinx/common/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

namespace dolfinx::common
Expand All @@ -30,11 +31,9 @@ namespace dolfinx::common
class Timer
{
public:
/// Create timer without logging
Timer();

/// Create timer with logging
Timer(const std::string& task);
/// Create timer
/// if a task name is provided this enables logging, otherwise without logging
Timer(std::optional<std::string> task = std::nullopt);

/// Destructor
~Timer();
Expand Down
5 changes: 1 addition & 4 deletions python/dolfinx/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ class Timer:
_cpp_object: _cpp.common.Timer

def __init__(self, name: typing.Optional[str] = None):
if name is None:
self._cpp_object = _cpp.common.Timer()
else:
self._cpp_object = _cpp.common.Timer(name)
self._cpp_object = _cpp.common.Timer(name)

def __enter__(self):
self._cpp_object.start()
Expand Down
3 changes: 1 addition & 2 deletions python/dolfinx/wrappers/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ void common(nb::module_& m)
nb::arg("global"));
// dolfinx::common::Timer
nb::class_<dolfinx::common::Timer>(m, "Timer", "Timer class")
.def(nb::init<>())
.def(nb::init<std::string>(), nb::arg("task"))
.def(nb::init<std::string>(), nb::arg("task") = nb::none())
.def("start", &dolfinx::common::Timer::start, "Start timer")
.def("stop", &dolfinx::common::Timer::stop, "Stop timer")
.def("resume", &dolfinx::common::Timer::resume)
Expand Down

0 comments on commit acc314a

Please sign in to comment.