Loading...
Searching...
No Matches
TimeLogger.h
// Copyright (C) 2003-2016 Anders Logg, 2015 Jan Blechta
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#pragma once
#include "Table.h"
#include "timing.h"
#include <chrono>
#include <map>
#include <mpi.h>
#include <string>
#include <utility>
namespace dolfinx::common
{
class TimeLogger
{
public:
static TimeLogger& instance();
void register_timing(const std::string& task,
std::chrono::duration<double, std::ratio<1>> wall);
Table timing_table() const;
void list_timings(MPI_Comm comm, Table::Reduction reduction) const;
std::pair<int, std::chrono::duration<double, std::ratio<1>>>
timing(const std::string& task) const;
std::map<std::string,
std::pair<int, std::chrono::duration<double, std::ratio<1>>>>
timings() const;
private:
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;
~TimeLogger() = default;
// List of timings for tasks, map from string to (num_timings,
// total_wall_time)
std::map<std::string,
std::pair<int, std::chrono::duration<double, std::ratio<1>>>>
_timings;
};
} // namespace dolfinx::common
dolfinx::Table
This class provides storage and pretty-printing for tables.
Definition Table.h:29
dolfinx::Table::Reduction
Reduction
Definition Table.h:34
dolfinx::common::TimeLogger::register_timing
void register_timing(const std::string &task, std::chrono::duration< double, std::ratio< 1 > > wall)
Register timing (for later summary).
Definition TimeLogger.cpp:23
dolfinx::common::TimeLogger::timing
std::pair< int, std::chrono::duration< double, std::ratio< 1 > > > timing(const std::string &task) const
Return timing.
Definition TimeLogger.cpp:70
dolfinx::common::TimeLogger::timings
std::map< std::string, std::pair< int, std::chrono::duration< double, std::ratio< 1 > > > > timings() const
Logged elapsed times.
Definition TimeLogger.cpp:85
dolfinx::common::TimeLogger::list_timings
void list_timings(MPI_Comm comm, Table::Reduction reduction) const
Definition TimeLogger.cpp:41
dolfinx::common::TimeLogger::timing_table
Table timing_table() const
Return a summary of timings and tasks in a Table.
Definition TimeLogger.cpp:53
dolfinx::common::TimeLogger::instance
static TimeLogger & instance()
Singleton access.
Definition TimeLogger.cpp:16
dolfinx::common
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8