4 #include <boost/regex.hpp> 5 #include <sys/resource.h> 6 #include <boost/lexical_cast.hpp> 17 const double LogTiming::cpu_reference_speed = 2992.497;
32 : number_divergent(-1), number_iteration(-1)
34 const int host_name_max = 1000;
35 char hostnamebuf[host_name_max];
36 int status = gethostname(hostnamebuf, host_name_max);
38 throw Exception(
"Call to gethostname failed");
39 hostname = std::string(hostnamebuf);
46 std::ifstream proc(
"/proc/cpuinfo");
48 proc.exceptions(std::ifstream::badbit | std::ifstream::failbit |
49 std::ifstream::eofbit);
52 while(!boost::regex_match(ln, m,
53 boost::regex(
"model name\\s*:\\s*(.*)")))
56 while(!boost::regex_match(ln, m, boost::regex(
"cpu MHz\\s*:\\s*(.*)")))
58 speed_mhz = boost::lexical_cast<
double>(m[1]);
60 }
catch(std::ifstream::failure e) {
68 cpu_factor = speed_mhz / cpu_reference_speed;
79 double wtime = wall_clock.elapsed();
80 struct rusage r_usage;
81 int status = getrusage(RUSAGE_SELF, &r_usage);
83 throw Exception(
"Call to getrusage failed");
84 double utime = r_usage.ru_utime.tv_sec + r_usage.ru_utime.tv_usec * 1e-6;
85 double stime = r_usage.ru_stime.tv_sec + r_usage.ru_stime.tv_usec * 1e-6;
87 std::ostringstream log;
88 log <<
"\n---------------------------------------------------------\n" 89 << Prefix <<
" Timing\n";
90 log <<
"Host: " << hostname <<
"\n";
92 log <<
"CPU Model: " << cpu_model <<
"\n" 93 <<
"Speed: " << speed_mhz <<
" MHz\n" 94 <<
"CPU Factor: " << cpu_factor <<
"\n";
96 log <<
"Couldn't get CPU model and speed. Assuming CPU Factor of 1\n" 97 <<
"CPU Factor: " << cpu_factor <<
"\n";
99 log <<
"Total Wall clock time: " << wtime <<
" seconds\n" 100 <<
"Total User time: " << utime <<
" seconds\n" 101 <<
"Total System time: " << stime <<
" seconds\n";
105 std::ifstream proc(
"/proc/self/status");
106 proc.exceptions(std::ifstream::badbit | std::ifstream::failbit |
107 std::ifstream::eofbit);
110 while(!boost::regex_match(ln, m,
111 boost::regex(
"VmPeak:\\s*(\\d+)\\s*kB")))
113 double t = boost::lexical_cast<
double>(m[1]);
114 log <<
"Virtual memory maximum: " << (t / 1024) <<
" MB\n";
115 while(!boost::regex_match(ln, m,
116 boost::regex(
"VmSize:\\s*(\\d+)\\s*kB")))
118 t = boost::lexical_cast<
double>(m[1]);
119 log <<
"Virtual memory current: " << (t / 1024) <<
" MB\n";
120 while(!boost::regex_match(ln, m,
121 boost::regex(
"VmHWM:\\s*(\\d+)\\s*kB")))
123 t = boost::lexical_cast<
double>(m[1]);
124 log <<
"Resident memory maximum: " << (t / 1024) <<
" MB\n";
125 while(!boost::regex_match(ln, m,
126 boost::regex(
"VmRSS:\\s*(\\d+)\\s*kB")))
128 t = boost::lexical_cast<
double>(m[1]);
129 log <<
"Resident memory current: " << (t / 1024) <<
" MB\n";
130 }
catch(std::ifstream::failure e) {
131 log <<
"Memory usage information isn't available on this platform\n" 132 <<
"(Available on Linux only)\n";
134 if(number_iteration > 0)
135 log <<
"Number successful steps: " << number_iteration <<
"\n" 136 <<
"Number divergent steps: " << number_divergent <<
"\n" 137 <<
"Total iteration: " << number_iteration + number_divergent
139 <<
"Normalized wall clock time per iteration: " 140 << wtime / (number_iteration + number_divergent) * cpu_factor
142 <<
"Normalized user time per iteration: " 143 << utime / (number_iteration + number_divergent) * cpu_factor
145 <<
"Normalized system time per iteration: " 146 << stime / (number_iteration + number_divergent) * cpu_factor
148 log <<
"---------------------------------------------------------\n";
virtual void notify_update(const ConnorSolver &Solver)
Called when the Observed object is updated.
This is the base of the exception hierarchy for Full Physics code.
int number_iteration() const
Number of iterations for the last problem solved.
const Unit m("m", 1.0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
Contains classes to abstract away details in various Spurr Radiative Transfer software.
virtual void write_to_log(const std::string &Prefix="") const
Write data to disk.
int number_divergent() const
Number of divergent steps for the last problem solved.