Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
9#ifndef LOG_H
10#define LOG_H
11
12#include <cstdint>
13#include <string>
14#include <string_view>
15#include <utility>
16#include <vector>
17
18#if defined(__GNUC__) || defined(__clang__)
19#define MALLARD_PRINTF(fmt, args) __attribute__((format(printf, fmt, args)))
20#else
21#define MALLARD_PRINTF(fmt, args)
22#endif
23
24namespace logging {
25
27using Items = std::vector<std::pair<std::string, std::string>>;
28
30constexpr int WIDTH = 92;
32constexpr int KEY_WIDTH = 18;
33
34enum class Style { BOLD, DIM, RED, YELLOW, GREEN, CYAN };
35
39std::string format(const char * fmt, ...) MALLARD_PRINTF(1, 2);
40
44std::string style(std::string_view text, Style s);
45
50bool color_stdout();
51bool color_stderr();
52
56void line(std::string_view text = "");
57
61void section(std::string_view title, std::string_view right = "");
62
66void item(std::string_view key, std::string_view value);
67void items(const Items & list);
68
73void begin_phase(std::string_view name);
74void end_phase(double seconds);
75
80void event(uint64_t step, double t, std::string_view kind, std::string_view text);
81
85void warning(std::string_view message);
86
90void error(std::string_view message);
91
93std::string count(uint64_t n);
95std::string duration(double seconds);
97std::string si(double value);
99std::string real(double value);
100
101} // namespace logging
102
103#endif // LOG_H
KOKKOS_INLINE_FUNCTION rtype dot(const rtype *a, const rtype *b)
Compute the dot product of two arrays.
Definition common_math.h:32
#define MALLARD_PRINTF(fmt, args)
Definition log.h:21
Definition log.cpp:20
std::string real(double v)
Compact real: "%.6g".
Definition log.cpp:200
void event(uint64_t step, double t, std::string_view kind, std::string_view text)
One-line event during the run (e.g. a file written), led by the step and time so it lines up with the...
Definition log.cpp:145
std::string count(uint64_t n)
1234567 -> "1,234,567".
Definition log.cpp:167
std::vector< std::pair< std::string, std::string > > Items
Key-value lines of a setup section, in display order.
Definition log.h:27
std::string format(const char *fmt,...)
printf-style formatting into a std::string.
Definition log.cpp:74
void error(std::string_view message)
Error on stderr from the calling rank, prefixed with the rank in parallel runs.
Definition log.cpp:160
bool color_stdout()
Whether to color stdout (stderr): a terminal, NO_COLOR unset and not under an MPI launcher,...
Definition log.cpp:87
void line(std::string_view text)
Prints a line on stdout from rank 0.
Definition log.cpp:101
void items(const Items &list)
Definition log.cpp:124
void begin_phase(std::string_view name)
Starts a line naming a setup phase; end_phase() completes it with the elapsed time....
Definition log.cpp:128
void end_phase(double seconds)
Definition log.cpp:137
constexpr int WIDTH
Width of section rules and the target maximum line width.
Definition log.h:30
Style
Definition log.h:34
bool color_stderr()
Definition log.cpp:92
void warning(std::string_view message)
Warning on stderr from rank 0, for conditions every rank sees alike.
Definition log.cpp:153
void section(std::string_view title, std::string_view right)
Section heading, e.g. "== Mesh ===...=== 0.12 s".
Definition log.cpp:107
constexpr int KEY_WIDTH
Column at which the values of key-value lines start.
Definition log.h:32
std::string si(double v)
Value with an SI suffix and 3 significant digits: "16.3M", "1.20k".
Definition log.cpp:189
std::string duration(double s)
Wall-clock duration: "850 us", "12.3 ms", "4.56 s", "12m 03s", "2h 05m".
Definition log.cpp:178
std::string style(std::string_view text, Style s)
Wraps text in an ANSI style when stdout gets color, else returns it unchanged.
Definition log.cpp:97
void item(std::string_view key, std::string_view value)
Aligned " key value" line under a section.
Definition log.cpp:117