testsuite_visualization.h [plain text]
#include <typeinfo>
#include <stdexcept>
#include <sstream>
#include <fstream>
#include <cxxabi.h>
#include <testsuite_performance.h>
bool first_container = false;
extern const char* filename;
typedef std::string::size_type (*callback_type) (std::string&);
template<typename Container, int Iter, bool Thread>
void
write_viz_container(callback_type find_container, const char* filename)
{
typedef std::string string;
{
const char ws(' ');
std::ostringstream title;
std::string titlename(filename);
std::string::size_type n = titlename.find('.');
if (n != string::npos)
titlename = std::string(titlename.begin(), titlename.begin() + n);
title << titlename;
title << ws;
title << Iter;
title << ws;
#if 0
title << "thread<";
std::boolalpha(title);
title << Thread;
title << '>';
#endif
titlename += ".title";
std::ofstream titlefile(titlename.c_str());
if (!titlefile.good())
throw std::runtime_error("write_viz_data cannot open titlename");
titlefile << title.str() << std::endl;
}
Container obj;
int status;
std::string type(abi::__cxa_demangle(typeid(obj).name(), 0, 0, &status));
string::iterator beg = type.begin();
string::iterator end;
string::size_type n = (*find_container)(type);
string::size_type nend = type.find('<', n);
if (nend != string::npos)
end = type.begin() + nend;
string compressed_type;
compressed_type += '"';
compressed_type += string(beg, end);
compressed_type += '<';
#if 0
typename Container::key_type v;
compressed_type += typeid(v).name();
#else
compressed_type += "int";
#endif
compressed_type += ", A>";
if (Thread == true)
compressed_type += " thread";
compressed_type += '"';
std::ofstream file(filename, std::ios_base::app);
if (!file.good())
throw std::runtime_error("write_viz_data cannot open filename");
file << compressed_type;
first_container = false;
}
void
write_viz_data(__gnu_test::time_counter& time, const char* filename)
{
std::ofstream file(filename, std::ios_base::app);
if (!file.good())
throw std::runtime_error("write_viz_data cannot open filename");
const char tab('\t');
int score = time.real_time();
file << tab << score;
}
void
write_viz_endl(const char* filename)
{
std::ofstream file(filename, std::ios_base::app);
if (!file.good())
throw std::runtime_error("write_viz_endl cannot open filename");
file << std::endl;
}
#if 0
write_viz_container<container_type, Iter, Thread>(&sequence_find_container,
filename);
#endif
#if 0
write_viz_endl(filename)
#endif