Skip to content
Snippets Groups Projects
Commit 4456a5e0 authored by René Fritze's avatar René Fritze Committed by René Milk
Browse files

[py] add bindings for Timings

parent 5737e03f
No related branches found
No related tags found
No related merge requests found
......@@ -12,4 +12,5 @@ add_subdirectory(common)
dune_pybindxi_add_module(_common EXCLUDE_FROM_ALL bindings.cc)
dune_pybindxi_add_module(_empty EXCLUDE_FROM_ALL empty.cc)
dune_pybindxi_add_module(_logging EXCLUDE_FROM_ALL logging.cc)
dune_pybindxi_add_module(_timings EXCLUDE_FROM_ALL timings.cc)
from dune.xt._timings import *
timings = instance()
\ No newline at end of file
// This file is part of the dune-xt-common project:
// https://github.com/dune-community/dune-xt-common
// Copyright 2009-2018 dune-xt-common developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Rene Milk (2018)
#include "config.h"
#include <string>
#include <vector>
#include <dune/pybindxi/pybind11.h>
#include <dune/pybindxi/stl.h>
#include <dune/pybindxi/iostream.h>
#include <python/dune/xt/common/bindings.hh>
#include <dune/xt/common/python.hh>
#include <dune/xt/common/timings.hh>
#include <python/dune/xt/common/exceptions.bindings.hh>
#include <dune/common/parallel/mpihelper.hh>
PYBIND11_MODULE(_timings, m)
{
namespace py = pybind11;
using namespace pybind11::literals;
using namespace Dune::XT::Common;
Dune::XT::Common::bindings::addbind_exceptions(m);
Dune::XT::Common::bindings::add_initialization(m, "dune.xt.common.timings");
py::class_<Timings>(m, "Timings")
.def("start", &Timings::start, "set this to begin a named section")
.def("reset", py::overload_cast<std::string>(&Timings::reset), "set elapsed time back to 0 for section_name")
.def("reset", py::overload_cast<>(&Timings::reset), "set elapsed time back to 0 for section_name")
.def("stop", py::overload_cast<std::string>(&Timings::stop), "stop all timer for given section only")
.def("stop", py::overload_cast<>(&Timings::stop), "stop all running timers")
.def("walltime", &Timings::walltime, "get runtime of section in milliseconds")
//! TODO this actually accepts an ostream
.def("output_simple", [](Timings& self) { self.output_simple(); }, "outputs per-rank csv-file")
.def("output_per_rank", &Timings::output_per_rank, "outputs walltime only")
//! TODO this actually accepts an MPICOMM and an ostream too
.def("output_all_measures",
[](Timings& self) { self.output_all_measures(); },
"outputs per rank and global averages of all measures");
m.def("instance", &timings, py::return_value_policy::reference);
}
......@@ -33,4 +33,12 @@ def test_logging():
lg.create(lg.log_max);
lg.info('log info test')
lg.error('log error test')
lg.debug('log debug test')
\ No newline at end of file
lg.debug('log debug test')
def test_timings():
from dune.xt.common.timings import timings
timings.reset()
timings.start("foo.bar")
timings.stop()
timings.output_simple()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment