Loading...
Searching...
No Matches
Logger.h
// Copyright (C) 2003-2016 Anders Logg, 2015 Jan Blechta
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// Thanks to Jim Tilander for many helpful hints.
//
// Modified by Ola Skavhaug 2007, 2009
#ifndef __LOGGER_H
#define __LOGGER_H
#include <map>
#include <memory>
#include <ostream>
#include <string>
#include <set>
#include <thread>
#include <tuple>
#include <dolfin/common/timing.h>
#include <dolfin/common/MPI.h>
#include "Table.h"
#include "LogLevel.h"
namespace dolfin
{
class Logger
{
public:
Logger();
~Logger();
void log(std::string msg, int log_level=INFO) const;
void log_underline(std::string msg, int log_level=INFO) const;
void warning(std::string msg) const;
void error(std::string msg) const;
void dolfin_error(std::string location,
std::string task,
std::string reason,
int mpi_rank=-1) const;
void deprecation(std::string feature,
std::string version_deprecated,
std::string message) const;
void begin(std::string msg, int log_level=INFO);
void end();
void progress (std::string title, double p) const;
void set_output_stream(std::ostream& stream);
std::ostream& get_output_stream() { return *logstream; }
void set_log_active(bool active);
inline bool is_active() { return _active; }
void set_log_level(int log_level);
inline int get_log_level() const { return _log_level; }
void set_indentation_level(std::size_t indentation_level);
void register_timing(std::string task,
std::tuple<double, double, double> elapsed);
Table timings(TimingClear clear, std::set<TimingType> type);
void list_timings(TimingClear clear, std::set<TimingType> type);
void dump_timings_to_xml(std::string filename, TimingClear clear);
std::tuple<std::size_t, double, double, double>
timing(std::string task, TimingClear clear);
void monitor_memory_usage();
MPI_Comm mpi_comm()
{ return _mpi_comm; }
void _report_memory_usage(size_t num_mb);
void __debug(std::string msg) const;
void __dolfin_assert(std::string file, unsigned long line,
std::string function, std::string check) const;
private:
// Write message
void write(int log_level, std::string msg) const;
// True iff logging is active
bool _active;
// Current log level
int _log_level;
// Current indentation level
int _indentation_level;
// Optional stream for logging
std::ostream* logstream;
// List of timings for tasks, map from string to
// (num_timings, total_wall_time, total_user_time, total_system_time)
std::map<std::string, std::tuple<std::size_t, double, double, double>>
_timings;
// Thread used for monitoring memory usage
std::unique_ptr<std::thread> _thread_monitor_memory_usage;
// Maximum memory usage so far
long int _maximum_memory_usage;
// Map for stringifying TimingType
static std::map<TimingType, std::string> _TimingType_descr;
// FIXME: This should be a dolfin::MPI::Comm, the MPI-awareness of
// the logging needs to be fixed.
// MPI Communicator
MPI_Comm _mpi_comm;
};
}
#endif
dolfin::Logger::monitor_memory_usage
void monitor_memory_usage()
Definition Logger.cpp:393
dolfin::Logger::list_timings
void list_timings(TimingClear clear, std::set< TimingType > type)
Definition Logger.cpp:297
dolfin::Logger::log
void log(std::string msg, int log_level=INFO) const
Print message.
Definition Logger.cpp:109
dolfin::Logger::dolfin_error
void dolfin_error(std::string location, std::string task, std::string reason, int mpi_rank=-1) const
Definition Logger.cpp:142
dolfin::Logger::dump_timings_to_xml
void dump_timings_to_xml(std::string filename, TimingClear clear)
Definition Logger.cpp:317
dolfin::Logger::get_output_stream
std::ostream & get_output_stream()
Get output stream.
Definition Logger.h:90
dolfin::Logger::set_log_level
void set_log_level(int log_level)
Set log level.
Definition Logger.cpp:256
dolfin::Logger::set_log_active
void set_log_active(bool active)
Turn logging on or off.
Definition Logger.cpp:251
dolfin::Logger::log_underline
void log_underline(std::string msg, int log_level=INFO) const
Print underlined message.
Definition Logger.cpp:114
dolfin::Logger::timing
std::tuple< std::size_t, double, double, double > timing(std::string task, TimingClear clear)
Definition Logger.cpp:371
dolfin::Logger::set_indentation_level
void set_indentation_level(std::size_t indentation_level)
Set indentation level.
Definition Logger.cpp:261
dolfin::Logger::_report_memory_usage
void _report_memory_usage(size_t num_mb)
Helper function for reporting memory usage.
Definition Logger.cpp:414
dolfin::Logger::begin
void begin(std::string msg, int log_level=INFO)
Begin task (increase indentation level).
Definition Logger.cpp:212
dolfin::Logger::is_active
bool is_active()
Return true iff logging is active.
Definition Logger.h:96
dolfin::Logger::get_log_level
int get_log_level() const
Get log level.
Definition Logger.h:102
dolfin::Logger::__dolfin_assert
void __dolfin_assert(std::string file, unsigned long line, std::string function, std::string check) const
Helper function for dolfin_dolfin_assert macro.
Definition Logger.cpp:429
dolfin::Logger::progress
void progress(std::string title, double p) const
Draw progress bar.
Definition Logger.cpp:224
dolfin::Logger::deprecation
void deprecation(std::string feature, std::string version_deprecated, std::string message) const
Issue deprecation warning for removed feature.
Definition Logger.cpp:188
dolfin::Logger::mpi_comm
MPI_Comm mpi_comm()
Return MPI Communicator of Logger.
Definition Logger.h:138
dolfin::Logger::warning
void warning(std::string msg) const
Print warning.
Definition Logger.cpp:130
dolfin::Logger::Logger
Logger()
Constructor.
Definition Logger.cpp:95
dolfin::Logger::error
void error(std::string msg) const
Print error message and throw exception.
Definition Logger.cpp:136
dolfin::Logger::~Logger
~Logger()
Destructor.
Definition Logger.cpp:102
dolfin::Logger::set_output_stream
void set_output_stream(std::ostream &stream)
Set output stream.
Definition Logger.cpp:246
dolfin::Logger::end
void end()
End task (decrease indentation level).
Definition Logger.cpp:219
dolfin::Logger::__debug
void __debug(std::string msg) const
Helper function for dolfin_debug macro.
Definition Logger.cpp:423
dolfin::Logger::timings
Table timings(TimingClear clear, std::set< TimingType > type)
Definition Logger.cpp:340
dolfin::Logger::register_timing
void register_timing(std::string task, std::tuple< double, double, double > elapsed)
Register timing (for later summary).
Definition Logger.cpp:266
dolfin::Table
Definition Table.h:50
dolfin
Definition adapt.h:30
dolfin::TimingClear
TimingClear
Definition timing.h:33