11#include <vendor/source_location/source_location.hpp>
13#include <dr/detail/format_shim.hpp>
14#include <dr/detail/ranges_shim.hpp>
20 timer() : begin_(std::chrono::high_resolution_clock::now()) {}
23 auto end = std::chrono::high_resolution_clock::now();
24 return std::chrono::duration<double>(end - begin_).count();
28 std::chrono::time_point<std::chrono::high_resolution_clock> begin_;
33 enum filters { base, for_each, transpose, mdspan_view, mpi, last };
35 logger() { rng::fill(enabled_,
true); }
37 void set_file(std::ofstream &fout) { fout_ = &fout; }
39 void filter(
const std::vector<std::string> &names) {
40 if (names.size() == 0) {
45 rng::fill(enabled_,
false);
48 for (
const auto &name : names) {
49 std::size_t
index = filters::last;
50 for (std::size_t i = 0; i < filter_names_.size(); i++) {
51 if (name == filter_names_[i]) {
55 if (
index == filters::last) {
56 std::cerr <<
"Ignoring unrecognized filter: " << name <<
"\n";
58 enabled_[
index] =
true;
65 template <
typename... Args>
67 fmt::format_string<Args...> format, Args &&...args) {
68 if (fout_ && enabled_[filters::base]) {
69 *fout_ << fmt::format(format, std::forward<Args>(args)...) <<
" <"
70 << location.file_name() <<
":" << location.line() <<
">\n";
75 template <
typename... Args>
76 void debug(fmt::format_string<Args...> format, Args &&...args) {
77 debug(filters::base, format, std::forward<Args>(args)...);
80 template <
typename... Args>
81 void debug(filters filter, fmt::format_string<Args...> format,
83 if (fout_ && enabled_[filter]) {
84 *fout_ << fmt::format(format, std::forward<Args>(args)...);
91 template <
typename... Args>
95 template <
typename... Args>
void debug(std::string format, Args &&...args) {}
97 template <
typename... Args>
98 void debug(filters filter, std::string format, Args &&...args) {}
103 std::ofstream *fout_ =
nullptr;
104 std::array<bool, filters::last> enabled_;
105 std::array<std::string, filters::last> filter_names_ = {
106 "base",
"for_each",
"transpose",
"mdspan_view",
"mpi"};
112 dr::drlog.debug(nostd::source_location::current(), __VA_ARGS__)
Definition: logger.hpp:31
Definition: logger.hpp:18
Definition: source_location.hpp:13