/usr/include/dolfin/log/Logger.h is in libdolfin-dev 2016.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | // 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:
/// Constructor
Logger();
/// Destructor
~Logger();
/// Print message
void log(std::string msg, int log_level=INFO) const;
/// Print underlined message
void log_underline(std::string msg, int log_level=INFO) const;
/// Print warning
void warning(std::string msg) const;
/// Print error message and throw exception
void error(std::string msg) const;
/// Print error message, prefer this to the above generic error message
void dolfin_error(std::string location,
std::string task,
std::string reason,
int mpi_rank=-1) const;
/// Issue deprecation warning for removed feature
void deprecation(std::string feature,
std::string version_deprecated,
std::string message) const;
/// Begin task (increase indentation level)
void begin(std::string msg, int log_level=INFO);
/// End task (decrease indentation level)
void end();
/// Draw progress bar
void progress (std::string title, double p) const;
/// Set output stream
void set_output_stream(std::ostream& stream);
/// Get output stream
std::ostream& get_output_stream() { return *logstream; }
/// Turn logging on or off
void set_log_active(bool active);
/// Return true iff logging is active
inline bool is_active() { return _active; }
/// Set log level
void set_log_level(int log_level);
/// Get log level
inline int get_log_level() const { return _log_level; }
/// Register timing (for later summary)
void register_timing(std::string task,
std::tuple<double, double, double> elapsed);
/// Return a summary of timings and tasks in a Table, optionally clearing
/// stored timings
Table timings(TimingClear clear, std::set<TimingType> type);
/// List a summary of timings and tasks, optionally clearing stored timings.
/// ``MPI_AVG`` reduction is printed. Collective on ``Logger::mpi_comm()``.
void list_timings(TimingClear clear, std::set<TimingType> type);
/// Dump a summary of timings and tasks to XML file, optionally clearing
/// stored timings. ``MPI_MAX``, ``MPI_MIN`` and ``MPI_AVG`` reductions are
/// stored. Collective on ``Logger::mpi_comm()``.
void dump_timings_to_xml(std::string filename, TimingClear clear);
/// Return timing (count, total wall time, total user time,
/// total system time) for given task, optionally clearing
/// all timings for the task
std::tuple<std::size_t, double, double, double>
timing(std::string task, TimingClear clear);
/// Monitor memory usage. Call this function at the start of a
/// program to continuously monitor the memory usage of the
/// process.
void monitor_memory_usage();
/// Return MPI Communicator of Logger
MPI_Comm mpi_comm()
{ return _mpi_comm; }
/// Helper function for reporting memory usage
void _report_memory_usage(size_t num_mb);
/// Helper function for dolfin_debug macro
void __debug(std::string msg) const;
/// Helper function for dolfin_dolfin_assert macro
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;
// MPI Communicator
MPI_Comm _mpi_comm;
};
}
#endif
|