diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 864a580fcd2e76b52ee10bfe27061bf07576d3e6..ff9ac66e3949addba89eaeffb5662903f3ccfe18 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,29 @@ +2008-05-05 Benjamin Kosnik <bkoz@redhat.com> + + * testsuite/util/testsuite_visualization.h: Move contents into... + * testsuite/util/testsuite_performance.h: ...here. + * testsuite/util/testsuite_common_types.h: Move + performance-related test infrastructure into + testsuite_performance. + * testsuite/performance/25_algorithms/search_n.cc: Fix includes. + * testsuite/performance/23_containers/find/map.cc: Same. + * testsuite/performance/23_containers/create/map.cc: Same. + * testsuite/performance/23_containers/insert_erase/associative.cc: Same. + * testsuite/performance/23_containers/insert/sequence.cc: Same. + * testsuite/performance/23_containers/insert/associative.cc: Same. + * testsuite/performance/23_containers/create_from_sorted/set.cc: Same. + * testsuite/performance/23_containers/index/map.cc: Same. + * testsuite/performance/23_containers/insert_from_sorted/set.cc: Same. + * testsuite/performance/23_containers/create_sort/list.cc: Same. + * testsuite/performance/23_containers/sort_search/list.cc: Same. + * testsuite/performance/23_containers/producer_consumer/sequence.cc: + Same. + * testsuite/performance/23_containers/producer_consumer/associative.cc: + Same. + + * testsuite/29_atomics/atomic/cons/assign_neg.cc: Adjust line numbers. + * testsuite/29_atomics/atomic/cons/copy_neg.cc: Same. + 2008-05-05 Benjamin Kosnik <bkoz@redhat.com> * 20_util/make_signed/requirements/typedefs-1.cc: Correct requirements. diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/cons/assign_neg.cc b/libstdc++-v3/testsuite/29_atomics/atomic/cons/assign_neg.cc index 435309860a33dc65bab67b469f936f123f3817f6..a22a558f26e90d63508a73cebc88bd748b7c988d 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic/cons/assign_neg.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic/cons/assign_neg.cc @@ -38,7 +38,7 @@ int main() return 0; } -// { dg-error "within this context" "" { target *-*-* } 310 } +// { dg-error "within this context" "" { target *-*-* } 309 } // { dg-error "is private" "" { target *-*-* } 1750 } // { dg-error "is private" "" { target *-*-* } 1782 } // { dg-error "is private" "" { target *-*-* } 1799 } diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/cons/copy_neg.cc b/libstdc++-v3/testsuite/29_atomics/atomic/cons/copy_neg.cc index 011933a8eb8ba6b3d2d0dc6fbb2106a8ea7d7b0f..49125182ebb4a71bc20d69e8ce7e578058e0f5ee 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic/cons/copy_neg.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic/cons/copy_neg.cc @@ -38,7 +38,7 @@ int main() return 0; } -// { dg-error "within this context" "" { target *-*-* } 333 } +// { dg-error "within this context" "" { target *-*-* } 332 } // { dg-error "is private" "" { target *-*-* } 1749 } // { dg-error "is private" "" { target *-*-* } 1781 } // { dg-error "is private" "" { target *-*-* } 1798 } diff --git a/libstdc++-v3/testsuite/performance/23_containers/create/map.cc b/libstdc++-v3/testsuite/performance/23_containers/create/map.cc index 5049e1a1ff5724b9de6fbcff17a2ee40f7b502bb..1ec20613a3a08a072b60eceb25897dfdb4d33367 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/create/map.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/create/map.cc @@ -27,7 +27,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <testsuite_common_types.h> +#include <testsuite_performance.h> template<typename Container, int Iter> void diff --git a/libstdc++-v3/testsuite/performance/23_containers/create_from_sorted/set.cc b/libstdc++-v3/testsuite/performance/23_containers/create_from_sorted/set.cc index 97ea3af117a4b2587301939e6b54412318a52510..c9259c0919cc586f6ab1037a89a3c3520cee8e21 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/create_from_sorted/set.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/create_from_sorted/set.cc @@ -25,7 +25,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <testsuite_common_types.h> +#include <testsuite_performance.h> template<typename Container, int Iter> void diff --git a/libstdc++-v3/testsuite/performance/23_containers/create_sort/list.cc b/libstdc++-v3/testsuite/performance/23_containers/create_sort/list.cc index 7a47f32b2ec2d86179eaec04ced8dec0472ccd6e..063075f3a97600df0b597919ccb4d731f21e1453 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/create_sort/list.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/create_sort/list.cc @@ -25,7 +25,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <testsuite_common_types.h> +#include <testsuite_performance.h> template<typename Container, int Iter> void diff --git a/libstdc++-v3/testsuite/performance/23_containers/find/map.cc b/libstdc++-v3/testsuite/performance/23_containers/find/map.cc index e6c2c79a7fc7ed5c978c45624300632727f7bbe0..6d09d030a762c75c5a22b79c93a58a078e434904 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/find/map.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/find/map.cc @@ -27,7 +27,7 @@ // 2004-03-11 Dhruv Matani <dhruvbird@HotPOP.com> -#include <testsuite_common_types.h> +#include <testsuite_performance.h> template<typename Container, int Iter> void diff --git a/libstdc++-v3/testsuite/performance/23_containers/index/map.cc b/libstdc++-v3/testsuite/performance/23_containers/index/map.cc index 386890d90ea67ae6408f1a243aa87bbc481c16df..e08b7d8d4c57bf3f1898c3934b9e52e74f454af6 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/index/map.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/index/map.cc @@ -25,7 +25,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <testsuite_common_types.h> +#include <testsuite_performance.h> // libstdc++/13823 recast for this testing framework template<typename Container, int Iter> diff --git a/libstdc++-v3/testsuite/performance/23_containers/insert/associative.cc b/libstdc++-v3/testsuite/performance/23_containers/insert/associative.cc index b3f8f71327c5bf327b7d02b3d8afe96009028692..a047f9933ae70382f2625a2832a51acc37710edf 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/insert/associative.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/insert/associative.cc @@ -25,7 +25,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <testsuite_common_types.h> +#include <testsuite_performance.h> template<typename Container, int Iter> void diff --git a/libstdc++-v3/testsuite/performance/23_containers/insert/sequence.cc b/libstdc++-v3/testsuite/performance/23_containers/insert/sequence.cc index 7023332e5e97fc311c46fae97549323552820c05..41faac12eb9345bc01fde90d00d8798f1cabef69 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/insert/sequence.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/insert/sequence.cc @@ -25,7 +25,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <testsuite_common_types.h> +#include <testsuite_performance.h> template<typename Container, int Iter> void diff --git a/libstdc++-v3/testsuite/performance/23_containers/insert_erase/associative.cc b/libstdc++-v3/testsuite/performance/23_containers/insert_erase/associative.cc index ee48ce2a708e2a56e218c45d7fc68045075df112..f3a29d07a02dd8628762f9da575edfffded97f0f 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/insert_erase/associative.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/insert_erase/associative.cc @@ -25,7 +25,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <testsuite_common_types.h> +#include <testsuite_performance.h> template<typename Container, int Iter> void diff --git a/libstdc++-v3/testsuite/performance/23_containers/insert_from_sorted/set.cc b/libstdc++-v3/testsuite/performance/23_containers/insert_from_sorted/set.cc index 72b1921e69758048572525a79a93f9962892d572..201edd9d189e29cd33b6ead26c06d8dcf0aecf77 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/insert_from_sorted/set.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/insert_from_sorted/set.cc @@ -25,7 +25,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <testsuite_common_types.h> +#include <testsuite_performance.h> template<typename Container, int Iter> void diff --git a/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/associative.cc b/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/associative.cc index 841cdf0477ecc4004cd612cb2baae6bda6ebc5b7..d0e1f2c6a8ed29aee62f1dabe4949920172f8d8e 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/associative.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/associative.cc @@ -25,7 +25,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <testsuite_common_types.h> +#include <testsuite_performance.h> typedef int test_type; diff --git a/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/sequence.cc b/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/sequence.cc index 1590c974b474ec441f9aaba503d58182cf4d6ae7..80c200f0df4e51a7707a55b96de14ecdcaad4bfb 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/sequence.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/sequence.cc @@ -25,7 +25,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <testsuite_common_types.h> +#include <testsuite_performance.h> typedef int test_type; diff --git a/libstdc++-v3/testsuite/performance/23_containers/sort_search/list.cc b/libstdc++-v3/testsuite/performance/23_containers/sort_search/list.cc index 14b42b4c0096da6184b79da2b991918f4b846ca2..71f66fde76ab57560a5756b8d57b153c956fcd92 100644 --- a/libstdc++-v3/testsuite/performance/23_containers/sort_search/list.cc +++ b/libstdc++-v3/testsuite/performance/23_containers/sort_search/list.cc @@ -25,7 +25,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#include <testsuite_common_types.h> +#include <testsuite_performance.h> template<typename Container, int Iter> void diff --git a/libstdc++-v3/testsuite/performance/25_algorithms/search_n.cc b/libstdc++-v3/testsuite/performance/25_algorithms/search_n.cc index d316cf8ecb69c3bcf6d679d3eebd94ce6deeec5a..814de7067993aed54d9f455bafed930ebb032882 100644 --- a/libstdc++-v3/testsuite/performance/25_algorithms/search_n.cc +++ b/libstdc++-v3/testsuite/performance/25_algorithms/search_n.cc @@ -53,7 +53,7 @@ main(void) array[i] = (match != 0) ? 1 : 0; if(--match < 0) match = rand() % (match_length - 1); } - test_container<int, forward_iterator_wrapper> fcon(array, array + length); + __gnu_test::test_container<int, forward_iterator_wrapper> fcon(array, array + length); start_counters(time, resource); for(int i = 0; i < 100; i++) search_n(fcon.begin(), fcon.end(), 10, 1); @@ -61,7 +61,7 @@ main(void) report_performance(__FILE__, "forward iterator", time, resource); clear_counters(time, resource); - test_container<int, random_access_iterator_wrapper> rcon(array, array + length); + __gnu_test::test_container<int, random_access_iterator_wrapper> rcon(array, array + length); start_counters(time, resource); for(int i = 0; i < 100; i++) search_n(rcon.begin(), rcon.end(), 10, 1); diff --git a/libstdc++-v3/testsuite/util/testsuite_common_types.h b/libstdc++-v3/testsuite/util/testsuite_common_types.h index bd9e76d4e2e41a9cd6c47870cddcb7f15c0259cd..35bd907d8da46c95537bd53290056724c9b59713 100644 --- a/libstdc++-v3/testsuite/util/testsuite_common_types.h +++ b/libstdc++-v3/testsuite/util/testsuite_common_types.h @@ -31,7 +31,6 @@ #ifndef _TESTSUITE_COMMON_TYPES_H #define _TESTSUITE_COMMON_TYPES_H 1 -#include <testsuite_visualization.h> #include <ext/typelist.h> #include <ext/new_allocator.h> @@ -347,122 +346,4 @@ namespace __gnu_test }; } // namespace __gnu_test - - -// Function template, function objects for the tests. -template<typename TestType> - struct value_type : public std::pair<const TestType, TestType> - { - inline value_type& operator++() - { - ++this->second; - return *this; - } - - inline operator TestType() const { return this->second; } - }; - -template<typename Container, int Iter> - void - do_loop(); - -template<typename Container, int Iter> - void* - do_thread(void* p = NULL) - { - do_loop<Container, Iter>(); - return p; - } - -template<typename Container, int Iter, bool Thread> - void - test_container(const char* filename) - { - using namespace __gnu_test; - time_counter time; - resource_counter resource; - { - start_counters(time, resource); - if (!Thread) - { - // No threads, so run 4x. - do_loop<Container, Iter * 4>(); - } - else - { -#if defined (_GLIBCXX_GCC_GTHR_POSIX_H) && !defined (NOTHREAD) - pthread_t t1, t2, t3, t4; - pthread_create(&t1, 0, &do_thread<Container, Iter>, 0); - pthread_create(&t2, 0, &do_thread<Container, Iter>, 0); - pthread_create(&t3, 0, &do_thread<Container, Iter>, 0); - pthread_create(&t4, 0, &do_thread<Container, Iter>, 0); - - pthread_join(t1, NULL); - pthread_join(t2, NULL); - pthread_join(t3, NULL); - pthread_join(t4, NULL); -#endif - } - stop_counters(time, resource); - - // Detailed text data. - Container obj; - int status; - std::ostringstream comment; - comment << "type: " << abi::__cxa_demangle(typeid(obj).name(), - 0, 0, &status); - report_header(filename, comment.str()); - report_performance("", "", time, resource); - - // Detailed data for visualization. - std::string vizfilename(filename); - vizfilename += ".dat"; - write_viz_data(time, vizfilename.c_str()); - } - } - -template<bool Thread> - struct test_sequence - { - test_sequence(const char* filename) : _M_filename(filename) { } - - template<class Container> - void - operator()(Container) - { - const int i = 20000; - test_container<Container, i, Thread>(_M_filename); - } - - private: - const char* _M_filename; - }; - - -inline std::string::size_type -sequence_find_container(std::string& type) -{ - const std::string::size_type npos = std::string::npos; - std::string::size_type n1 = type.find("vector"); - std::string::size_type n2 = type.find("list"); - std::string::size_type n3 = type.find("deque"); - std::string::size_type n4 = type.find("string"); - - if (n1 != npos || n2 != npos || n3 != npos || n4 != npos) - return std::min(std::min(n1, n2), std::min(n3, n4)); - else - throw std::runtime_error("sequence_find_container not found"); -} - -inline std::string::size_type -associative_find_container(std::string& type) -{ - using std::string; - string::size_type n1 = type.find("map"); - string::size_type n2 = type.find("set"); - if (n1 != string::npos || n2 != string::npos) - return std::min(n1, n2); - else - throw std::runtime_error("associative_find_container not found"); -} #endif diff --git a/libstdc++-v3/testsuite/util/testsuite_performance.h b/libstdc++-v3/testsuite/util/testsuite_performance.h index ad873ed6d23dcc92d61413d6f603e2a406e1287a..246651812d854a6b64c32c5158b9f43c50ac5316 100644 --- a/libstdc++-v3/testsuite/util/testsuite_performance.h +++ b/libstdc++-v3/testsuite/util/testsuite_performance.h @@ -1,7 +1,7 @@ // -*- C++ -*- // Testing performance utilities for the C++ library testsuite. // -// Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc. +// Copyright (C) 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -38,6 +38,11 @@ #include <string> #include <fstream> #include <iomanip> +#include <typeinfo> +#include <stdexcept> +#include <sstream> +#include <cxxabi.h> +#include <testsuite_common_types.h> #ifdef __linux__ #include <malloc.h> @@ -260,5 +265,229 @@ namespace __gnu_test } } // namespace __gnu_test + +// Ah, we wish it wasn't so... +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; + + // Create title. + { + 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; + } + + // Create compressed type name. + Container obj; + int status; + std::string type(abi::__cxa_demangle(typeid(obj).name(), 0, 0, &status)); + + // Extract fully-qualified typename. + // Assumes "set" or "map" are uniquely determinate. + string::iterator beg = type.begin(); + string::iterator end; + string::size_type n = (*find_container)(type); + + // Find start of fully-qualified name. + // Assume map, find end. + 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>"; + + // XXX + 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"); + + // Print out score in appropriate column. + 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; +} + + +// Function template, function objects for the tests. +template<typename TestType> + struct value_type : public std::pair<const TestType, TestType> + { + inline value_type& operator++() + { + ++this->second; + return *this; + } + + inline operator TestType() const { return this->second; } + }; + +template<typename Container, int Iter> + void + do_loop(); + +template<typename Container, int Iter> + void* + do_thread(void* p = NULL) + { + do_loop<Container, Iter>(); + return p; + } + +template<typename Container, int Iter, bool Thread> + void + test_container(const char* filename) + { + using namespace __gnu_test; + time_counter time; + resource_counter resource; + { + start_counters(time, resource); + if (!Thread) + { + // No threads, so run 4x. + do_loop<Container, Iter * 4>(); + } + else + { +#if defined (_GLIBCXX_GCC_GTHR_POSIX_H) && !defined (NOTHREAD) + pthread_t t1, t2, t3, t4; + pthread_create(&t1, 0, &do_thread<Container, Iter>, 0); + pthread_create(&t2, 0, &do_thread<Container, Iter>, 0); + pthread_create(&t3, 0, &do_thread<Container, Iter>, 0); + pthread_create(&t4, 0, &do_thread<Container, Iter>, 0); + + pthread_join(t1, NULL); + pthread_join(t2, NULL); + pthread_join(t3, NULL); + pthread_join(t4, NULL); +#endif + } + stop_counters(time, resource); + + // Detailed text data. + Container obj; + int status; + std::ostringstream comment; + comment << "type: " << abi::__cxa_demangle(typeid(obj).name(), + 0, 0, &status); + report_header(filename, comment.str()); + report_performance("", "", time, resource); + + // Detailed data for visualization. + std::string vizfilename(filename); + vizfilename += ".dat"; + write_viz_data(time, vizfilename.c_str()); + } + } + +template<bool Thread> + struct test_sequence + { + test_sequence(const char* filename) : _M_filename(filename) { } + + template<class Container> + void + operator()(Container) + { + const int i = 20000; + test_container<Container, i, Thread>(_M_filename); + } + + private: + const char* _M_filename; + }; + + +inline std::string::size_type +sequence_find_container(std::string& type) +{ + const std::string::size_type npos = std::string::npos; + std::string::size_type n1 = type.find("vector"); + std::string::size_type n2 = type.find("list"); + std::string::size_type n3 = type.find("deque"); + std::string::size_type n4 = type.find("string"); + + if (n1 != npos || n2 != npos || n3 != npos || n4 != npos) + return std::min(std::min(n1, n2), std::min(n3, n4)); + else + throw std::runtime_error("sequence_find_container not found"); +} + +inline std::string::size_type +associative_find_container(std::string& type) +{ + using std::string; + string::size_type n1 = type.find("map"); + string::size_type n2 = type.find("set"); + if (n1 != string::npos || n2 != string::npos) + return std::min(n1, n2); + else + throw std::runtime_error("associative_find_container not found"); +} + #endif // _GLIBCXX_PERFORMANCE_H diff --git a/libstdc++-v3/testsuite/util/testsuite_visualization.h b/libstdc++-v3/testsuite/util/testsuite_visualization.h deleted file mode 100644 index 0e2757666a41a1c8da5d1b13f7845778cf9efba6..0000000000000000000000000000000000000000 --- a/libstdc++-v3/testsuite/util/testsuite_visualization.h +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (C) 2005 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -#include <typeinfo> -#include <stdexcept> -#include <sstream> -#include <fstream> -#include <cxxabi.h> -#include <testsuite_performance.h> - -// Ah, we wish it wasn't so... -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; - - // Create title. - { - 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; - } - - // Create compressed type name. - Container obj; - int status; - std::string type(abi::__cxa_demangle(typeid(obj).name(), 0, 0, &status)); - - // Extract fully-qualified typename. - // Assumes "set" or "map" are uniquely determinate. - string::iterator beg = type.begin(); - string::iterator end; - string::size_type n = (*find_container)(type); - - // Find start of fully-qualified name. - // Assume map, find end. - 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>"; - - // XXX - 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"); - - // Print out score in appropriate column. - 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 -// cons -write_viz_container<container_type, Iter, Thread>(&sequence_find_container, - filename); -#endif - -#if 0 -// dtor -write_viz_endl(filename) -#endif