1 // Copyright John Maddock 2014.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_MATH_TOOLS_ITERATION_LOGGER
7 #define BOOST_MATH_TOOLS_ITERATION_LOGGER
15 #include <boost/current_function.hpp>
17 namespace boost{ namespace math{ namespace detail{
21 std::map<std::pair<std::string, std::string>, unsigned long long> data;
25 for(std::map<std::pair<std::string, std::string>, unsigned long long>::const_iterator i = data.begin(); i != data.end(); ++i)
27 std::cout << "Logging iteration data:\n file: " << i->first.first
28 << "\n function: " << i->first.second
29 << "\n count: " << i->second << std::endl;
31 // Read in existing data:
33 std::map<std::string, unsigned long long> file_data;
34 std::string filename = i->first.first + ".logfile";
35 std::ifstream is(filename.c_str());
47 if(file_data.find(i->first.second) != file_data.end())
48 file_data[i->first.second] += i->second;
50 file_data[i->first.second] = i->second;
52 // Write it out again:
54 std::ofstream os(filename.c_str());
55 for(std::map<std::string, unsigned long long>::const_iterator j = file_data.begin(); j != file_data.end(); ++j)
56 os << j->first << "\n " << j->second << std::endl;
62 inline void log_iterations(const char* file, const char* function, unsigned long long count)
65 std::pair<std::string, std::string> key(file, function);
66 if(l.data.find(key) == l.data.end())
71 #define BOOST_MATH_LOG_COUNT(count) boost::math::detail::log_iterations(__FILE__, BOOST_CURRENT_FUNCTION, count);
76 #endif // BOOST_MATH_TOOLS_ITERATION_LOGGER