monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
logger_utils.cpp
Go to the documentation of this file.
1 #include "../../../include/monolish_blas.hpp"
2 #include "../../internal/monolish_internal.hpp"
3 
4 namespace monolish {
5 
6 // solver
7 void Logger::solver_in(const std::string func_name) {
8  if (LogLevel >= 1) {
9  if (filename.empty()) {
10  pStream = &std::cout;
11  }
12 
13  // init
14  calls.push_back(func_name);
15  times.push_back(std::chrono::system_clock::now());
16 
17  // start
18  *pStream << "- {" << std::flush;
19 
20  // func
21  *pStream << "type : solver, " << std::flush;
22  *pStream << "name : " << std::flush;
23  for (int i = 0; i < (int)calls.size(); i++)
24  *pStream << calls[i] << "/" << std::flush;
25  *pStream << ", " << std::flush;
26 
27  // stat
28  *pStream << "stat : IN" << std::flush;
29 
30  // end
31  *pStream << "}" << std::endl;
32  }
33 }
34 
36  if (LogLevel >= 1) {
37  if (filename.empty()) {
38  pStream = &std::cout;
39  }
40 
41  // start
42  *pStream << "- {" << std::flush;
43 
44  // func
45  *pStream << "type : solver, " << std::flush;
46  *pStream << "name : " << std::flush;
47  for (int i = 0; i < (int)calls.size(); i++)
48  *pStream << calls[i] << "/" << std::flush;
49  *pStream << ", " << std::flush;
50 
51  // time
52  auto end = std::chrono::system_clock::now();
53  double sec = std::chrono::duration_cast<std::chrono::nanoseconds>(
54  end - times[(int)times.size() - 1])
55  .count() /
56  1.0e+9;
57  *pStream << "stat : OUT, " << std::flush;
58  *pStream << "time : " << sec << std::flush;
59 
60  // end
61  *pStream << "}" << std::endl;
62 
63  calls.pop_back();
64  times.pop_back();
65  }
66 }
67 
68 // func
69 void Logger::func_in(const std::string func_name) {
70  if (LogLevel >= 2) {
71  if (filename.empty()) {
72  pStream = &std::cout;
73  }
74 
75  calls.push_back(func_name);
76  times.push_back(std::chrono::system_clock::now());
77  }
78 }
79 
81  if (LogLevel >= 2) {
82  if (filename.empty()) {
83  pStream = &std::cout;
84  }
85 
86  // start
87  *pStream << "- {" << std::flush;
88 
89  // func
90  *pStream << "type : func, " << std::flush;
91  *pStream << "name : " << std::flush;
92  for (int i = 0; i < (int)calls.size(); i++)
93  *pStream << calls[i] << "/" << std::flush;
94  *pStream << ", " << std::flush;
95 
96  // time
97  auto end = std::chrono::system_clock::now();
98  double sec = std::chrono::duration_cast<std::chrono::nanoseconds>(
99  end - times[(int)times.size() - 1])
100  .count() /
101  1.0e+9;
102  *pStream << "time : " << sec << std::flush;
103 
104  // end
105  *pStream << "}" << std::endl;
106 
107  calls.pop_back();
108  times.pop_back();
109  }
110 }
111 
112 // util
113 void Logger::util_in(const std::string func_name) {
114  if (LogLevel >= 3) {
115  if (filename.empty()) {
116  pStream = &std::cout;
117  }
118  calls.push_back(func_name);
119  times.push_back(std::chrono::system_clock::now());
120  }
121 }
122 
124  if (LogLevel >= 3) {
125  if (filename.empty()) {
126  pStream = &std::cout;
127  }
128 
129  // start
130  *pStream << "- {" << std::flush;
131 
132  // func
133  *pStream << "type : util, " << std::flush;
134  *pStream << "name : " << std::flush;
135  for (int i = 0; i < (int)calls.size(); i++)
136  *pStream << calls[i] << "/" << std::flush;
137  *pStream << ", " << std::flush;
138 
139  // time
140  auto end = std::chrono::system_clock::now();
141  double sec = std::chrono::duration_cast<std::chrono::nanoseconds>(
142  end - times[(int)times.size() - 1])
143  .count() /
144  1.0e+9;
145  *pStream << "time : " << sec << std::flush;
146 
147  // end
148  *pStream << "}" << std::endl;
149 
150  calls.pop_back();
151  times.pop_back();
152  }
153 }
154 
156 void util::set_log_level(const size_t Level) {
157  Logger &logger = Logger::get_instance();
158  logger.set_log_level(Level);
159 }
160 
161 void util::set_log_filename(const std::string filename) {
162  Logger &logger = Logger::get_instance();
163  logger.set_log_filename(filename);
164 }
165 
166 } // namespace monolish
monolish::Logger::pStream
std::ostream * pStream
Definition: monolish_logger.hpp:32
monolish::Logger::set_log_level
void set_log_level(size_t L)
Specifying the log level.
Definition: monolish_logger.hpp:58
monolish::Logger::calls
std::vector< std::string > calls
Definition: monolish_logger.hpp:27
monolish::Logger
logger class (singleton, for developper class)
Definition: monolish_logger.hpp:19
monolish::Logger::func_out
void func_out()
Definition: logger_utils.cpp:80
monolish::Logger::solver_in
void solver_in(const std::string func_name)
Definition: logger_utils.cpp:7
monolish::Logger::util_out
void util_out()
Definition: logger_utils.cpp:123
monolish::Logger::set_log_filename
void set_log_filename(const std::string file)
Specifying the log finename.
Definition: monolish_logger.hpp:70
monolish::Logger::filename
std::string filename
Definition: monolish_logger.hpp:31
monolish::Logger::util_in
void util_in(const std::string func_name)
Definition: logger_utils.cpp:113
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::Logger::solver_out
void solver_out()
Definition: logger_utils.cpp:35
monolish::util::set_log_filename
void set_log_filename(const std::string filename)
Specifying the log finename.
Definition: logger_utils.cpp:161
monolish::util::set_log_level
void set_log_level(const size_t Level)
Logger utils ///////////////////////////////.
Definition: logger_utils.cpp:156
monolish::Logger::LogLevel
size_t LogLevel
Definition: monolish_logger.hpp:35
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42
monolish::Logger::times
std::vector< std::chrono::system_clock::time_point > times
Definition: monolish_logger.hpp:30
monolish::Logger::func_in
void func_in(const std::string func_name)
Definition: logger_utils.cpp:69