2008-05-29 Andy Hutchinson <hutchinsonandy@aim.com>
[official-gcc.git] / libstdc++-v3 / testsuite / util / testsuite_visualization.h
blob0e2757666a41a1c8da5d1b13f7845778cf9efba6
1 // Copyright (C) 2005 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 // USA.
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction. Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License. This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
28 #include <typeinfo>
29 #include <stdexcept>
30 #include <sstream>
31 #include <fstream>
32 #include <cxxabi.h>
33 #include <testsuite_performance.h>
35 // Ah, we wish it wasn't so...
36 bool first_container = false;
37 extern const char* filename;
39 typedef std::string::size_type (*callback_type) (std::string&);
41 template<typename Container, int Iter, bool Thread>
42 void
43 write_viz_container(callback_type find_container, const char* filename)
45 typedef std::string string;
47 // Create title.
49 const char ws(' ');
50 std::ostringstream title;
52 std::string titlename(filename);
53 std::string::size_type n = titlename.find('.');
54 if (n != string::npos)
55 titlename = std::string(titlename.begin(), titlename.begin() + n);
57 title << titlename;
58 title << ws;
59 title << Iter;
60 title << ws;
61 #if 0
62 title << "thread<";
63 std::boolalpha(title);
64 title << Thread;
65 title << '>';
66 #endif
68 titlename += ".title";
69 std::ofstream titlefile(titlename.c_str());
70 if (!titlefile.good())
71 throw std::runtime_error("write_viz_data cannot open titlename");
72 titlefile << title.str() << std::endl;
75 // Create compressed type name.
76 Container obj;
77 int status;
78 std::string type(abi::__cxa_demangle(typeid(obj).name(), 0, 0, &status));
80 // Extract fully-qualified typename.
81 // Assumes "set" or "map" are uniquely determinate.
82 string::iterator beg = type.begin();
83 string::iterator end;
84 string::size_type n = (*find_container)(type);
86 // Find start of fully-qualified name.
87 // Assume map, find end.
88 string::size_type nend = type.find('<', n);
89 if (nend != string::npos)
90 end = type.begin() + nend;
92 string compressed_type;
93 compressed_type += '"';
94 compressed_type += string(beg, end);
95 compressed_type += '<';
96 #if 0
97 typename Container::key_type v;
98 compressed_type += typeid(v).name();
99 #else
100 compressed_type += "int";
101 #endif
102 compressed_type += ", A>";
104 // XXX
105 if (Thread == true)
106 compressed_type += " thread";
107 compressed_type += '"';
109 std::ofstream file(filename, std::ios_base::app);
110 if (!file.good())
111 throw std::runtime_error("write_viz_data cannot open filename");
113 file << compressed_type;
114 first_container = false;
118 void
119 write_viz_data(__gnu_test::time_counter& time, const char* filename)
121 std::ofstream file(filename, std::ios_base::app);
122 if (!file.good())
123 throw std::runtime_error("write_viz_data cannot open filename");
125 // Print out score in appropriate column.
126 const char tab('\t');
127 int score = time.real_time();
128 file << tab << score;
131 void
132 write_viz_endl(const char* filename)
134 std::ofstream file(filename, std::ios_base::app);
135 if (!file.good())
136 throw std::runtime_error("write_viz_endl cannot open filename");
137 file << std::endl;
141 #if 0
142 // cons
143 write_viz_container<container_type, Iter, Thread>(&sequence_find_container,
144 filename);
145 #endif
147 #if 0
148 // dtor
149 write_viz_endl(filename)
150 #endif