OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /openrisc/trunk/gnu-stable/gcc-4.5.1/libstdc++-v3/include/profile
    from Rev 816 to Rev 826
    Reverse comparison

Rev 816 → Rev 826

/base.h
0,0 → 1,68
// -*- C++ -*-
 
// Copyright (C) 2009 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, 59 Temple Place - Suite 330, Boston,
// MA 02111-1307, 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.
 
/** @file profile/base.h
* @brief Sequential helper functions.
* This file is a GNU profile extension to the Standard C++ Library.
*/
 
// Written by Lixia Liu
 
#ifndef _GLIBCXX_PROFILE_BASE_H
#define _GLIBCXX_PROFILE_BASE_H 1
 
#include <cstdio>
#include <functional>
#include <bits/c++config.h>
#include <profile/impl/profiler.h>
 
// Profiling mode namespaces.
 
/**
* @namespace std::__profile
* @brief GNU profile code, replaces standard behavior with profile behavior.
*/
namespace std
{
namespace __profile { }
}
 
/**
* @namespace __gnu_profile
* @brief GNU profile code for public use.
*/
namespace __gnu_profile
{
// Import all the profile versions of components in namespace std.
using namespace std::__profile;
}
 
 
#endif /* _GLIBCXX_PROFILE_BASE_H */
base.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler_list_to_slist.h =================================================================== --- impl/profiler_list_to_slist.h (nonexistent) +++ impl/profiler_list_to_slist.h (revision 826) @@ -0,0 +1,182 @@ +// -*- C++ -*- +// +// Copyright (C) 2009 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler_list_to_slist.h + * @brief Diagnostics for list to slist. + */ + +// Written by Changhee Jung. + +#ifndef _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H +#define _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H 1 + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#else +#include +#include +#include +#endif +#include "profile/impl/profiler.h" +#include "profile/impl/profiler_node.h" +#include "profile/impl/profiler_trace.h" + +namespace __gnu_profile +{ + +class __list2slist_info: public __object_info_base +{ + public: + __list2slist_info() : _M_rewind(false), _M_operations(0) {} + __list2slist_info(__stack_t __stack) + : _M_rewind(false), _M_operations(0),__object_info_base(__stack) {} + virtual ~__list2slist_info() {} + __list2slist_info(const __list2slist_info& __o) : __object_info_base(__o) + { _M_rewind = __o._M_rewind; _M_operations = __o._M_operations; } + // XXX: the magnitude should be multiplied with a constant factor F, + // where F is 1 when the malloc size class of list nodes is different + // from the malloc size class of slist nodes. When they fall into the same + // class, the only slist benefit is from having to set fewer links, so + // the factor F should be much smaller, closer to 0 than to 1. + // This could be implemented by passing the size classes in the config file. + // For now, we always assume F to be 1. + float __magnitude() const + { if (!_M_rewind) return _M_operations; else return 0; } + void __merge(const __list2slist_info& __o) {}; + void __write(FILE* __f) const; + const char* __advice() const + { return strdup("change std::list to std::forward_list"); } + void __opr_rewind() { _M_rewind = true; _M_valid = false;} + void __record_operation() { _M_operations++; } + bool __has_rewind() { return _M_rewind; } + +private: + bool _M_rewind; + size_t _M_operations; +}; + +class __list2slist_stack_info: public __list2slist_info { + public: + __list2slist_stack_info(const __list2slist_info& __o) + : __list2slist_info(__o) {} +}; + +class __trace_list_to_slist + : public __trace_base<__list2slist_info, __list2slist_stack_info> +{ + public: + ~__trace_list_to_slist() {} + __trace_list_to_slist() + : __trace_base<__list2slist_info, __list2slist_stack_info>() + { __id = "list-to-slist"; } + void __opr_rewind(const void* __obj); + void __record_operation(const void* __obj); + void __insert(const __object_t __obj, __stack_t __stack) + { __add_object(__obj, __list2slist_info(__stack)); } + void __destruct(const void* __obj); +}; + +inline void __list2slist_info::__write(FILE* __f) const +{ + fprintf(__f, "%s\n", _M_rewind ? "invalid" : "valid"); +} + +inline void __trace_list_to_slist::__destruct(const void* __obj) +{ + if (!__is_on()) + return; + + __list2slist_info* __res = __get_object_info(__obj); + if (!__res) + return; + + __retire_object(__obj); +} + +inline void __trace_list_to_slist_init() +{ + _GLIBCXX_PROFILE_DATA(_S_list_to_slist) = new __trace_list_to_slist(); +} + +inline void __trace_list_to_slist_report(FILE* __f, + __warning_vector_t& __warnings) +{ + if (_GLIBCXX_PROFILE_DATA(_S_list_to_slist)) { + _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__collect_warnings(__warnings); + _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__write(__f); + } +} + +inline void __trace_list_to_slist::__opr_rewind(const void* __obj) +{ + __list2slist_info* __res = __get_object_info(__obj); + if (__res) + __res->__opr_rewind(); +} + +inline void __trace_list_to_slist::__record_operation(const void* __obj) +{ + __list2slist_info* __res = __get_object_info(__obj); + if (__res) + __res->__record_operation(); +} + +inline void __trace_list_to_slist_rewind(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__opr_rewind(__obj); +} + +inline void __trace_list_to_slist_operation(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__record_operation(__obj); +} + +inline void __trace_list_to_slist_construct(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__insert(__obj, __get_stack()); +} + +inline void __trace_list_to_slist_destruct(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__destruct(__obj); +} + +} // namespace __gnu_profile +#endif /* _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H */
impl/profiler_list_to_slist.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler_container_size.h =================================================================== --- impl/profiler_container_size.h (nonexistent) +++ impl/profiler_container_size.h (revision 826) @@ -0,0 +1,242 @@ +// -*- C++ -*- +// +// Copyright (C) 2009, 2010 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler_trace.h + * @brief Diagnostics for container sizes. + */ + +// Written by Lixia Liu and Silvius Rus. + +#ifndef _GLIBCXX_PROFILE_PROFILER_CONTAINER_SIZE_H +#define _GLIBCXX_PROFILE_PROFILER_CONTAINER_SIZE_H 1 + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#else +#include +#include +#include +#endif + +#include + +#include "profile/impl/profiler.h" +#include "profile/impl/profiler_node.h" +#include "profile/impl/profiler_trace.h" + +namespace __gnu_profile +{ + +/** @brief A container size instrumentation line in the object table. */ +class __container_size_info: public __object_info_base +{ + public: + __container_size_info(); + __container_size_info(const __container_size_info& __o); + __container_size_info(__stack_t __stack, size_t __num); + virtual ~__container_size_info() {} + + void __write(FILE* f) const; + float __magnitude() const { return static_cast(_M_cost); } + const char* __advice() const; + + void __merge(const __container_size_info& __o); + // Call if a container is destructed or cleaned. + void __destruct(size_t __num, size_t __inum); + // Estimate the cost of resize/rehash. + float __resize_cost(size_t __from, size_t __to) { return __from; } + // Call if container is resized. + void __resize(size_t __from, size_t __to); + + private: + size_t _M_init; + size_t _M_max; // range of # buckets + size_t _M_min; + size_t _M_total; + size_t _M_item_min; // range of # items + size_t _M_item_max; + size_t _M_item_total; + size_t _M_count; + size_t _M_resize; + size_t _M_cost; +}; + +inline const char* __container_size_info::__advice() const +{ + std::stringstream __message; + if (_M_init < _M_item_max) + __message << "change initial container size from " << _M_init + << " to " << _M_item_max; + + return strdup(__message.str().c_str()); +} + +inline void __container_size_info::__destruct(size_t __num, size_t __inum) +{ + _M_max = std::max(_M_max, __num); + _M_item_max = std::max(_M_item_max, __inum); + if (_M_min == 0) { + _M_min = __num; + _M_item_min = __inum; + } else { + _M_min = std::min(_M_min, __num); + _M_item_min = std::min(_M_item_min, __inum); + } + _M_total += __num; + _M_item_total += __inum; + _M_count += 1; +} + +inline void __container_size_info::__resize(size_t __from, size_t __to) +{ + _M_cost += this->__resize_cost(__from, __to); + _M_resize += 1; + _M_max = std::max(_M_max, __to); +} + +inline __container_size_info::__container_size_info(__stack_t __stack, + size_t __num) + : __object_info_base(__stack), _M_init(0), _M_max(0), _M_item_max(0), + _M_min(0), _M_item_min(0), _M_total(0), _M_item_total(0), _M_cost(0), + _M_count(0), _M_resize(0) +{ + _M_init = _M_max = __num; + _M_item_min = _M_item_max = _M_item_total = _M_total = 0; + _M_min = 0; + _M_count = 0; + _M_resize = 0; +} + +inline void __container_size_info::__merge(const __container_size_info& __o) +{ + _M_init = std::max(_M_init, __o._M_init); + _M_max = std::max(_M_max, __o._M_max); + _M_item_max = std::max(_M_item_max, __o._M_item_max); + _M_min = std::min(_M_min, __o._M_min); + _M_item_min = std::min(_M_item_min, __o._M_item_min); + _M_total += __o._M_total; + _M_item_total += __o._M_item_total; + _M_count += __o._M_count; + _M_cost += __o._M_cost; + _M_resize += __o._M_resize; +} + +inline __container_size_info::__container_size_info() + : _M_init(0), _M_max(0), _M_item_max(0), _M_min(0), _M_item_min(0), + _M_total(0), _M_item_total(0), _M_cost(0), _M_count(0), _M_resize(0) +{ +} + +inline __container_size_info::__container_size_info( + const __container_size_info& __o) + : __object_info_base(__o) +{ + _M_init = __o._M_init; + _M_max = __o._M_max; + _M_item_max = __o._M_item_max; + _M_min = __o._M_min; + _M_item_min = __o._M_item_min; + _M_total = __o._M_total; + _M_item_total = __o._M_item_total; + _M_cost = __o._M_cost; + _M_count = __o._M_count; + _M_resize = __o._M_resize; +} + +/** @brief A container size instrumentation line in the stack table. */ +class __container_size_stack_info: public __container_size_info +{ + public: + __container_size_stack_info(const __container_size_info& __o) + : __container_size_info(__o) {} +}; + +/** @brief Container size instrumentation trace producer. */ +class __trace_container_size + : public __trace_base<__container_size_info, __container_size_stack_info> +{ + public: + ~__trace_container_size() {} + __trace_container_size() + : __trace_base<__container_size_info, __container_size_stack_info>() {}; + + // Insert a new node at construct with object, callstack and initial size. + void __insert(const __object_t __obj, __stack_t __stack, size_t __num); + // Call at destruction/clean to set container final size. + void __destruct(const void* __obj, size_t __num, size_t __inum); + void __construct(const void* __obj, size_t __inum); + // Call at resize to set resize/cost information. + void __resize(const void* __obj, int __from, int __to); +}; + +inline void __trace_container_size::__insert(const __object_t __obj, + __stack_t __stack, size_t __num) +{ + __add_object(__obj, __container_size_info(__stack, __num)); +} + +inline void __container_size_info::__write(FILE* __f) const +{ + fprintf(__f, "%Zu %Zu %Zu %Zu %Zu %Zu %Zu %Zu %Zu %Zu\n", + _M_init, _M_count, _M_cost, _M_resize, _M_min, _M_max, _M_total, + _M_item_min, _M_item_max, _M_item_total); +} + +inline void __trace_container_size::__destruct(const void* __obj, + size_t __num, size_t __inum) +{ + if (!__is_on()) return; + + __object_t __obj_handle = static_cast<__object_t>(__obj); + + __container_size_info* __object_info = __get_object_info(__obj_handle); + if (!__object_info) + return; + + __object_info->__destruct(__num, __inum); + __retire_object(__obj_handle); +} + +inline void __trace_container_size::__resize(const void* __obj, int __from, + int __to) +{ + if (!__is_on()) return; + + __container_size_info* __object_info = __get_object_info(__obj); + if (!__object_info) + return; + + __object_info->__resize(__from, __to); +} + +} // namespace __gnu_profile +#endif /* _GLIBCXX_PROFILE_PROFILER_CONTAINER_SIZE_H */
impl/profiler_container_size.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler_vector_size.h =================================================================== --- impl/profiler_vector_size.h (nonexistent) +++ impl/profiler_vector_size.h (revision 826) @@ -0,0 +1,104 @@ +// -*- C++ -*- +// +// Copyright (C) 2009 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler_vector_size.h + * @brief Collection of vector size traces. + */ + +// Written by Lixia Liu and Silvius Rus. + +#ifndef _GLIBCXX_PROFILE_PROFILER_VECTOR_SIZE_H +#define _GLIBCXX_PROFILE_PROFILER_VECTOR_SIZE_H 1 + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#else +#include +#include +#include +#endif +#include "profile/impl/profiler.h" +#include "profile/impl/profiler_node.h" +#include "profile/impl/profiler_trace.h" +#include "profile/impl/profiler_state.h" +#include "profile/impl/profiler_container_size.h" + +namespace __gnu_profile +{ + +/** @brief Hashtable size instrumentation trace producer. */ +class __trace_vector_size : public __trace_container_size +{ + public: + __trace_vector_size() : __trace_container_size() { __id = "vector-size"; } +}; + +inline void __trace_vector_size_init() +{ + _GLIBCXX_PROFILE_DATA(_S_vector_size) = new __trace_vector_size(); +} + +inline void __trace_vector_size_report(FILE* __f, + __warning_vector_t& __warnings) +{ + if (_GLIBCXX_PROFILE_DATA(_S_vector_size)) { + _GLIBCXX_PROFILE_DATA(_S_vector_size)->__collect_warnings(__warnings); + _GLIBCXX_PROFILE_DATA(_S_vector_size)->__write(__f); + } +} + +inline void __trace_vector_size_construct(const void* __obj, size_t __num) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_vector_size)->__insert(__obj, __get_stack(), __num); +} + +inline void __trace_vector_size_destruct(const void* __obj, size_t __num, + size_t __inum) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_vector_size)->__destruct(__obj, __num, __inum); +} + +inline void __trace_vector_size_resize(const void* __obj, size_t __from, + size_t __to) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_vector_size)->__resize(__obj, __from, __to); +} + +} // namespace __gnu_profile + +#endif /* _GLIBCXX_PROFILE_PROFILER_VECTOR_SIZE_H */
impl/profiler_vector_size.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler_hash_func.h =================================================================== --- impl/profiler_hash_func.h (nonexistent) +++ impl/profiler_hash_func.h (revision 826) @@ -0,0 +1,185 @@ +// -*- C++ -*- +// +// Copyright (C) 2009, 2010 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler_trace.h + * @brief Data structures to represent profiling traces. + */ + +// Written by Lixia Liu and Silvius Rus. + +#ifndef _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H +#define _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H 1 + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#else +#include +#include +#include +#endif +#include "profile/impl/profiler.h" +#include "profile/impl/profiler_node.h" +#include "profile/impl/profiler_trace.h" + +namespace __gnu_profile +{ + +/** @brief A hash performance instrumentation line in the object table. */ +class __hashfunc_info: public __object_info_base +{ + public: + __hashfunc_info() + :_M_longest_chain(0), _M_accesses(0), _M_hops(0) {} + __hashfunc_info(const __hashfunc_info& o); + __hashfunc_info(__stack_t __stack) + : __object_info_base(__stack), + _M_longest_chain(0), _M_accesses(0), _M_hops(0){} + virtual ~__hashfunc_info() {} + + void __merge(const __hashfunc_info& __o); + void __destruct(size_t __chain, size_t __accesses, size_t __hops); + void __write(FILE* __f) const; + float __magnitude() const { return static_cast(_M_hops); } + const char* __advice() const { return strdup("change hash function"); } + +private: + size_t _M_longest_chain; + size_t _M_accesses; + size_t _M_hops; +}; + +inline __hashfunc_info::__hashfunc_info(const __hashfunc_info& __o) + : __object_info_base(__o) +{ + _M_longest_chain = __o._M_longest_chain; + _M_accesses = __o._M_accesses; + _M_hops = __o._M_hops; +} + +inline void __hashfunc_info::__merge(const __hashfunc_info& __o) +{ + _M_longest_chain = std::max(_M_longest_chain, __o._M_longest_chain); + _M_accesses += __o._M_accesses; + _M_hops += __o._M_hops; +} + +inline void __hashfunc_info::__destruct(size_t __chain, size_t __accesses, + size_t __hops) +{ + _M_longest_chain = std::max(_M_longest_chain, __chain); + _M_accesses += __accesses; + _M_hops += __hops; +} + +/** @brief A hash performance instrumentation line in the stack table. */ +class __hashfunc_stack_info: public __hashfunc_info { + public: + __hashfunc_stack_info(const __hashfunc_info& __o) : __hashfunc_info(__o) {} +}; + +/** @brief Hash performance instrumentation producer. */ +class __trace_hash_func + : public __trace_base<__hashfunc_info, __hashfunc_stack_info> +{ + public: + __trace_hash_func(); + ~__trace_hash_func() {} + + // Insert a new node at construct with object, callstack and initial size. + void __insert(__object_t __obj, __stack_t __stack); + // Call at destruction/clean to set container final size. + void __destruct(const void* __obj, size_t __chain, + size_t __accesses, size_t __hops); +}; + +inline __trace_hash_func::__trace_hash_func() + : __trace_base<__hashfunc_info, __hashfunc_stack_info>() +{ + __id = "hash-distr"; +} + +inline void __trace_hash_func::__insert(__object_t __obj, __stack_t __stack) +{ + __add_object(__obj, __hashfunc_info(__stack)); +} + +inline void __hashfunc_info::__write(FILE* __f) const +{ + fprintf(__f, "%Zu %Zu %Zu\n", _M_hops, _M_accesses, _M_longest_chain); +} + +inline void __trace_hash_func::__destruct(const void* __obj, size_t __chain, + size_t __accesses, size_t __hops) +{ + if (!__is_on()) return; + + // First find the item from the live objects and update the informations. + __hashfunc_info* __objs = __get_object_info(__obj); + if (!__objs) + return; + + __objs->__destruct(__chain, __accesses, __hops); + __retire_object(__obj); +} + +inline void __trace_hash_func_init() +{ + _GLIBCXX_PROFILE_DATA(_S_hash_func) = new __trace_hash_func(); +} + +inline void __trace_hash_func_report(FILE* __f, + __warning_vector_t& __warnings) +{ + if (_GLIBCXX_PROFILE_DATA(_S_hash_func)) { + _GLIBCXX_PROFILE_DATA(_S_hash_func)->__collect_warnings(__warnings); + _GLIBCXX_PROFILE_DATA(_S_hash_func)->__write(__f); + } +} + +inline void __trace_hash_func_construct(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_hash_func)->__insert(__obj, __get_stack()); +} + +inline void __trace_hash_func_destruct(const void* __obj, size_t __chain, + size_t __accesses, size_t __hops) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_hash_func)->__destruct(__obj, __chain, __accesses, + __hops); +} + +} // namespace __gnu_profile +#endif /* _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H */
impl/profiler_hash_func.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler_trace.h =================================================================== --- impl/profiler_trace.h (nonexistent) +++ impl/profiler_trace.h (revision 826) @@ -0,0 +1,628 @@ +// -*- C++ -*- +// +// Copyright (C) 2009, 2010 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler_trace.h + * @brief Data structures to represent profiling traces. + */ + +// Written by Lixia Liu and Silvius Rus. + +#ifndef _GLIBCXX_PROFILE_PROFILER_TRACE_H +#define _GLIBCXX_PROFILE_PROFILER_TRACE_H 1 + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#include +#define _GLIBCXX_IMPL_UNORDERED_MAP std::_GLIBCXX_STD_PR::unordered_map +#include +#else +#include +#include +#include +#include +#include +#define _GLIBCXX_IMPL_UNORDERED_MAP std::tr1::unordered_map +#endif + +#include +#include +#include +#include +#include // for std::make_heap, std::sort_heap + +#include "profile/impl/profiler_state.h" +#include "profile/impl/profiler_node.h" + +namespace __gnu_profile +{ +/** @brief Internal environment. Values can be set one of two ways: + 1. In config file "var = value". The default config file path is + libstdcxx-profile.conf. + 2. By setting process environment variables. For instance, in a Bash + shell you can set the unit cost of iterating through a map like this: + export __map_iterate_cost_factor=5.0. + If a value is set both in the input file and through an environment + variable, the environment value takes precedence. */ +typedef _GLIBCXX_IMPL_UNORDERED_MAP __env_t; +_GLIBCXX_PROFILE_DEFINE_UNINIT_DATA(__env_t, __env); + +/** @brief Master lock. */ +_GLIBCXX_PROFILE_DEFINE_UNINIT_DATA(__gnu_cxx::__mutex, __global_lock); + +/** @brief Representation of a warning. */ +struct __warning_data +{ + float __magnitude; + __stack_t __context; + const char* __warning_id; + const char* __warning_message; + + __warning_data() + : __magnitude(0.0), __context(NULL), __warning_id(NULL), + __warning_message(NULL) { } + + __warning_data(float __m, __stack_t __c, const char* __id, + const char* __msg) + : __magnitude(__m), __context(__c), __warning_id(__id), + __warning_message(__msg) { } + + bool + operator>(const struct __warning_data& __other) const + { return __magnitude > __other.__magnitude; } +}; + +typedef std::_GLIBCXX_STD_PR::vector<__warning_data> __warning_vector_t; + +// Defined in profiler_.h. +class __trace_hash_func; +class __trace_hashtable_size; +class __trace_map2umap; +class __trace_vector_size; +class __trace_vector_to_list; +class __trace_list_to_slist; +class __trace_list_to_vector; +void __trace_vector_size_init(); +void __trace_hashtable_size_init(); +void __trace_hash_func_init(); +void __trace_vector_to_list_init(); +void __trace_list_to_slist_init(); +void __trace_list_to_vector_init(); +void __trace_map_to_unordered_map_init(); +void __trace_vector_size_report(FILE*, __warning_vector_t&); +void __trace_hashtable_size_report(FILE*, __warning_vector_t&); +void __trace_hash_func_report(FILE*, __warning_vector_t&); +void __trace_vector_to_list_report(FILE*, __warning_vector_t&); +void __trace_list_to_slist_report(FILE*, __warning_vector_t&); +void __trace_list_to_vector_report(FILE*, __warning_vector_t&); +void __trace_map_to_unordered_map_report(FILE*, __warning_vector_t&); + +struct __cost_factor +{ + const char* __env_var; + float __value; +}; + +typedef std::_GLIBCXX_STD_PR::vector<__cost_factor*> __cost_factor_vector; + +_GLIBCXX_PROFILE_DEFINE_DATA(__trace_hash_func*, _S_hash_func, NULL); +_GLIBCXX_PROFILE_DEFINE_DATA(__trace_hashtable_size*, _S_hashtable_size, NULL); +_GLIBCXX_PROFILE_DEFINE_DATA(__trace_map2umap*, _S_map2umap, NULL); +_GLIBCXX_PROFILE_DEFINE_DATA(__trace_vector_size*, _S_vector_size, NULL); +_GLIBCXX_PROFILE_DEFINE_DATA(__trace_vector_to_list*, _S_vector_to_list, NULL); +_GLIBCXX_PROFILE_DEFINE_DATA(__trace_list_to_slist*, _S_list_to_slist, NULL); +_GLIBCXX_PROFILE_DEFINE_DATA(__trace_list_to_vector*, _S_list_to_vector, NULL); + +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __vector_shift_cost_factor, + {"__vector_shift_cost_factor", 1.0}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __vector_iterate_cost_factor, + {"__vector_iterate_cost_factor", 1.0}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __vector_resize_cost_factor, + {"__vector_resize_cost_factor", 1.0}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __list_shift_cost_factor, + {"__list_shift_cost_factor", 0.0}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __list_iterate_cost_factor, + {"__list_iterate_cost_factor", 10.0}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __list_resize_cost_factor, + {"__list_resize_cost_factor", 0.0}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __map_insert_cost_factor, + {"__map_insert_cost_factor", 1.5}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __map_erase_cost_factor, + {"__map_erase_cost_factor", 1.5}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __map_find_cost_factor, + {"__map_find_cost_factor", 1}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __map_iterate_cost_factor, + {"__map_iterate_cost_factor", 2.3}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __umap_insert_cost_factor, + {"__umap_insert_cost_factor", 12.0}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __umap_erase_cost_factor, + {"__umap_erase_cost_factor", 12.0}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __umap_find_cost_factor, + {"__umap_find_cost_factor", 10.0}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor, __umap_iterate_cost_factor, + {"__umap_iterate_cost_factor", 1.7}); +_GLIBCXX_PROFILE_DEFINE_DATA(__cost_factor_vector*, __cost_factors, NULL); + +_GLIBCXX_PROFILE_DEFINE_DATA(const char*, _S_trace_file_name, + _GLIBCXX_PROFILE_TRACE_PATH_ROOT); +_GLIBCXX_PROFILE_DEFINE_DATA(size_t, _S_max_warn_count, + _GLIBCXX_PROFILE_MAX_WARN_COUNT); +_GLIBCXX_PROFILE_DEFINE_DATA(size_t, _S_max_stack_depth, + _GLIBCXX_PROFILE_MAX_STACK_DEPTH); +_GLIBCXX_PROFILE_DEFINE_DATA(size_t, _S_max_mem, + _GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC); + +inline size_t __stack_max_depth() +{ + return _GLIBCXX_PROFILE_DATA(_S_max_stack_depth); +} + +inline size_t __max_mem() +{ + return _GLIBCXX_PROFILE_DATA(_S_max_mem); +} + +/** @brief Base class for all trace producers. */ +template +class __trace_base +{ + public: + __trace_base(); + virtual ~__trace_base() {} + + void __add_object(__object_t object, __object_info __info); + __object_info* __get_object_info(__object_t __object); + void __retire_object(__object_t __object); + void __write(FILE* f); + void __collect_warnings(__warning_vector_t& __warnings); + + private: + __gnu_cxx::__mutex __object_table_lock; + __gnu_cxx::__mutex __stack_table_lock; + typedef _GLIBCXX_IMPL_UNORDERED_MAP<__object_t, + __object_info> __object_table_t; + typedef _GLIBCXX_IMPL_UNORDERED_MAP<__stack_t, __stack_info, __stack_hash, + __stack_hash> __stack_table_t; + __object_table_t __object_table; + __stack_table_t __stack_table; + size_t __stack_table_byte_size; + + protected: + const char* __id; +}; + +template +void __trace_base<__object_info, __stack_info>::__collect_warnings( + __warning_vector_t& __warnings) +{ + typename __stack_table_t::iterator __i = __stack_table.begin(); + for ( ; __i != __stack_table.end(); ++__i ) + { + __warnings.push_back(__warning_data((*__i).second.__magnitude(), + (*__i).first, + __id, + (*__i).second.__advice())); + } +} + +template +__trace_base<__object_info, __stack_info>::__trace_base() +{ + // Do not pick the initial size too large, as we don't know which diagnostics + // are more active. + __object_table.rehash(10000); + __stack_table.rehash(10000); + __stack_table_byte_size = 0; + __id = NULL; +} + +template +void __trace_base<__object_info, __stack_info>::__add_object( + __object_t __object, __object_info __info) +{ + if (__max_mem() == 0 + || __object_table.size() * sizeof(__object_info) <= __max_mem()) { + this->__object_table_lock.lock(); + __object_table.insert( + typename __object_table_t::value_type(__object, __info)); + this->__object_table_lock.unlock(); + } +} + +template +__object_info* __trace_base<__object_info, __stack_info>::__get_object_info( + __object_t __object) +{ + // XXX: Revisit this to see if we can decrease mutex spans. + // Without this mutex, the object table could be rehashed during an + // insertion on another thread, which could result in a segfault. + this->__object_table_lock.lock(); + typename __object_table_t::iterator __object_it = + __object_table.find(__object); + if (__object_it == __object_table.end()){ + this->__object_table_lock.unlock(); + return NULL; + } else { + this->__object_table_lock.unlock(); + return &__object_it->second; + } +} + +template +void __trace_base<__object_info, __stack_info>::__retire_object( + __object_t __object) +{ + this->__object_table_lock.lock(); + this->__stack_table_lock.lock(); + typename __object_table_t::iterator __object_it = + __object_table.find(__object); + if (__object_it != __object_table.end()){ + const __object_info& __info = __object_it->second; + const __stack_t& __stack = __info.__stack(); + typename __stack_table_t::iterator __stack_it = + __stack_table.find(__stack); + if (__stack_it == __stack_table.end()) { + // First occurence of this call context. + if (__max_mem() == 0 || __stack_table_byte_size < __max_mem()) { + __stack_table_byte_size += + (sizeof(__instruction_address_t) * __size(__stack) + + sizeof(__stack) + sizeof(__stack_info)); + __stack_table.insert(make_pair(__stack, __stack_info(__info))); + } + } else { + // Merge object info into info summary for this call context. + __stack_it->second.__merge(__info); + delete __stack; + } + __object_table.erase(__object); + } + this->__object_table_lock.unlock(); + this->__stack_table_lock.unlock(); +} + +template +void __trace_base<__object_info, __stack_info>::__write(FILE* __f) +{ + typename __stack_table_t::iterator __it; + + for (__it = __stack_table.begin(); __it != __stack_table.end(); __it++) { + if (__it->second.__is_valid()) { + fprintf(__f, __id); + fprintf(__f, "|"); + __gnu_profile::__write(__f, __it->first); + fprintf(__f, "|"); + __it->second.__write(__f); + } + } +} + +inline size_t __env_to_size_t(const char* __env_var, size_t __default_value) +{ + char* __env_value = getenv(__env_var); + if (__env_value) { + long int __converted_value = strtol(__env_value, NULL, 10); + if (errno || __converted_value < 0) { + fprintf(stderr, "Bad value for environment variable '%s'.\n", __env_var); + abort(); + } else { + return static_cast(__converted_value); + } + } else { + return __default_value; + } +} + +inline void __set_max_stack_trace_depth() +{ + _GLIBCXX_PROFILE_DATA(_S_max_stack_depth) = __env_to_size_t( + _GLIBCXX_PROFILE_MAX_STACK_DEPTH_ENV_VAR, + _GLIBCXX_PROFILE_DATA(_S_max_stack_depth)); +} + +inline void __set_max_mem() +{ + _GLIBCXX_PROFILE_DATA(_S_max_mem) = __env_to_size_t( + _GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC_ENV_VAR, + _GLIBCXX_PROFILE_DATA(_S_max_mem)); +} + +inline int __log_magnitude(float __f) +{ + const float __log_base = 10.0; + int __result = 0; + int __sign = 1; + if (__f < 0) { + __f = -__f; + __sign = -1; + } + while (__f > __log_base) { + ++__result; + __f /= 10.0; + } + return __sign * __result; +} + +inline FILE* __open_output_file(const char* __extension) +{ + // The path is made of _S_trace_file_name + "." + extension. + size_t __root_len = strlen(_GLIBCXX_PROFILE_DATA(_S_trace_file_name)); + size_t __ext_len = strlen(__extension); + char* __file_name = new char[__root_len + 1 + __ext_len + 1]; + memcpy(__file_name, _GLIBCXX_PROFILE_DATA(_S_trace_file_name), __root_len); + *(__file_name + __root_len) = '.'; + memcpy(__file_name + __root_len + 1, __extension, __ext_len + 1); + FILE* __out_file = fopen(__file_name, "w"); + if (__out_file) { + return __out_file; + } else { + fprintf(stderr, "Could not open trace file '%s'.\n", __file_name); + abort(); + } +} + +/** @brief Final report method, registered with @b atexit. + * + * This can also be called directly by user code, including signal handlers. + * It is protected against deadlocks by the reentrance guard in profiler.h. + * However, when called from a signal handler that triggers while within + * __gnu_profile (under the guarded zone), no output will be produced. + */ +inline void __report(void) +{ + _GLIBCXX_PROFILE_DATA(__global_lock).lock(); + + __warning_vector_t __warnings; + + FILE* __raw_file = __open_output_file("raw"); + __trace_vector_size_report(__raw_file, __warnings); + __trace_hashtable_size_report(__raw_file, __warnings); + __trace_hash_func_report(__raw_file, __warnings); + __trace_vector_to_list_report(__raw_file, __warnings); + __trace_list_to_slist_report(__raw_file, __warnings); + __trace_list_to_vector_report(__raw_file, __warnings); + __trace_map_to_unordered_map_report(__raw_file, __warnings); + fclose(__raw_file); + + // Sort data by magnitude. + // XXX: instead of sorting, should collect only top N for better performance. + size_t __cutoff = std::min(_GLIBCXX_PROFILE_DATA(_S_max_warn_count), + __warnings.size()); + + std::make_heap(__warnings.begin(), __warnings.end(), + std::greater<__warning_vector_t::value_type>()); + std::sort_heap(__warnings.begin(), __warnings.end(), + std::greater<__warning_vector_t::value_type>()); + __warnings.resize(__cutoff); + + FILE* __warn_file = __open_output_file("txt"); + + for (__warning_vector_t::iterator __it = __warnings.begin(); + __it != __warnings.end(); ++__it) + { + fprintf(__warn_file, __it->__warning_id); + fprintf(__warn_file, ": improvement = %d", + __log_magnitude(__it->__magnitude)); + fprintf(__warn_file, ": call stack = "); + __gnu_profile::__write(__warn_file, __it->__context); + fprintf(__warn_file, ": advice = %s\n", __it->__warning_message); + free(const_cast(reinterpret_cast + (__it->__warning_message))); + } + + fclose(__warn_file); + + _GLIBCXX_PROFILE_DATA(__global_lock).unlock(); +} + +inline void __set_trace_path() +{ + char* __env_trace_file_name = getenv(_GLIBCXX_PROFILE_TRACE_ENV_VAR); + + if (__env_trace_file_name) { + _GLIBCXX_PROFILE_DATA(_S_trace_file_name) = __env_trace_file_name; + } + + // Make sure early that we can create the trace file. + fclose(__open_output_file("txt")); +} + +inline void __set_max_warn_count() +{ + char* __env_max_warn_count_str = getenv( + _GLIBCXX_PROFILE_MAX_WARN_COUNT_ENV_VAR); + + if (__env_max_warn_count_str) { + _GLIBCXX_PROFILE_DATA(_S_max_warn_count) = static_cast( + atoi(__env_max_warn_count_str)); + } +} + +inline void __read_cost_factors() +{ + std::string __conf_file_name(_GLIBCXX_PROFILE_DATA(_S_trace_file_name)); + __conf_file_name += ".conf"; + + std::ifstream __conf_file(__conf_file_name.c_str()); + + if (__conf_file.is_open()) + { + std::string __line; + + while (getline(__conf_file, __line)) + { + std::string::size_type __i = __line.find_first_not_of(" \t\n\v"); + + if (__line.length() <= 0 || __line[__i] == '#') { + // Skip empty lines or comments. + continue; + } + + // Trim. + if (__line.begin() != __line.end()) + { + // A simple remove operation. + std::string::iterator __first = __line.begin(); + std::string::iterator __result = __first; + ++__first; + for(; __first != __line.end(); ++__first) + if(!(*__first == ' ')) + { + *__result = *__first; + ++__result; + } + __line.erase(__result, __line.end()); + } + std::string::size_type __pos = __line.find("="); + std::string __factor_name = __line.substr(0, __pos); + std::string::size_type __end = __line.find_first_of(";\n"); + std::string __factor_value = __line.substr(__pos + 1, __end - __pos); + + _GLIBCXX_PROFILE_DATA(__env)[__factor_name] = __factor_value; + } + } +} + +inline void __write_cost_factors() +{ + FILE* __file = __open_output_file("conf.out"); + + for (__decltype(_GLIBCXX_PROFILE_DATA(__cost_factors)->begin()) __it + = _GLIBCXX_PROFILE_DATA(__cost_factors)->begin(); + __it != _GLIBCXX_PROFILE_DATA(__cost_factors)->end(); ++__it) + fprintf(__file, "%s = %f\n", (*__it)->__env_var, (*__it)->__value); + + fclose(__file); +} + +inline void __set_cost_factors() +{ + _GLIBCXX_PROFILE_DATA(__cost_factors) = new __cost_factor_vector; + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__vector_shift_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__vector_iterate_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__vector_resize_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__list_shift_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__list_iterate_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__list_resize_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__map_insert_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__map_erase_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__map_find_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__map_iterate_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__umap_insert_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__umap_erase_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__umap_find_cost_factor)); + _GLIBCXX_PROFILE_DATA(__cost_factors)->push_back( + &_GLIBCXX_PROFILE_DATA(__umap_iterate_cost_factor)); + + for (__decltype(_GLIBCXX_PROFILE_DATA(__cost_factors)->begin()) __it + = _GLIBCXX_PROFILE_DATA(__cost_factors)->begin(); + __it != _GLIBCXX_PROFILE_DATA(__cost_factors)->end(); ++__it) + { + const char* __env_cost_factor = getenv((*__it)->__env_var); + if (!__env_cost_factor) + { + __env_t::iterator __found = _GLIBCXX_PROFILE_DATA(__env).find( + (*__it)->__env_var); + if (__found != _GLIBCXX_PROFILE_DATA(__env).end()) + __env_cost_factor = (*__found).second.c_str(); + } + if (__env_cost_factor) + (*__it)->__value = atof(__env_cost_factor); + } +} + +inline void __profcxx_init_unconditional() +{ + _GLIBCXX_PROFILE_DATA(__global_lock).lock(); + + if (__is_invalid()) { + + __set_max_warn_count(); + + if (_GLIBCXX_PROFILE_DATA(_S_max_warn_count) == 0) { + + __turn_off(); + + } else { + + __set_max_stack_trace_depth(); + __set_max_mem(); + __set_trace_path(); + __read_cost_factors(); + __set_cost_factors(); + __write_cost_factors(); + + __trace_vector_size_init(); + __trace_hashtable_size_init(); + __trace_hash_func_init(); + __trace_vector_to_list_init(); + __trace_list_to_slist_init(); + __trace_list_to_vector_init(); + __trace_map_to_unordered_map_init(); + + atexit(__report); + + __turn_on(); + + } + } + + _GLIBCXX_PROFILE_DATA(__global_lock).unlock(); +} + +/** @brief This function must be called by each instrumentation point. + * + * The common path is inlined fully. + */ +inline bool __profcxx_init(void) +{ + if (__is_invalid()) { + __profcxx_init_unconditional(); + } + + return __is_on(); +} + +} // namespace __gnu_profile + +#endif /* _GLIBCXX_PROFILE_PROFILER_TRACE_H */
impl/profiler_trace.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler_list_to_vector.h =================================================================== --- impl/profiler_list_to_vector.h (nonexistent) +++ impl/profiler_list_to_vector.h (revision 826) @@ -0,0 +1,313 @@ +// -*- C++ -*- +// +// Copyright (C) 2009, 2010 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler_list_to_vector.h + * @brief diagnostics for list to vector. + */ + +// Written by Changhee Jung. + +#ifndef _GLIBCXX_PROFILE_PROFILER_LIST_TO_VECTOR_H +#define _GLIBCXX_PROFILE_PROFILER_LIST_TO_VECTOR_H 1 + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#else +#include +#include +#include +#endif +#include +#include +#include "profile/impl/profiler.h" +#include "profile/impl/profiler_node.h" +#include "profile/impl/profiler_trace.h" + +namespace __gnu_profile +{ + +/** @brief A list-to-vector instrumentation line in the object table. */ +class __list2vector_info: public __object_info_base +{ + public: + __list2vector_info() + :_M_shift_count(0), _M_iterate(0), _M_resize(0), _M_list_cost(0), + _M_vector_cost(0), _M_valid(true), _M_max_size(0) {} + __list2vector_info(__stack_t __stack) + : __object_info_base(__stack), _M_shift_count(0), _M_iterate(0), + _M_resize(0), _M_list_cost(0), _M_vector_cost(0), _M_valid(true), + _M_max_size(0) {} + virtual ~__list2vector_info() {} + __list2vector_info(const __list2vector_info& __o); + void __merge(const __list2vector_info& __o); + void __write(FILE* __f) const; + float __magnitude() const { return _M_list_cost - _M_vector_cost; } + const char* __advice() const; + size_t __shift_count() { return _M_shift_count; } + size_t __iterate() { return _M_iterate; } + float __list_cost() { return _M_list_cost; } + size_t __resize() { return _M_resize; } + void __set_list_cost(float __lc) { _M_list_cost = __lc; } + void __set_vector_cost(float __vc) { _M_vector_cost = __vc; } + bool __is_valid() { return _M_valid; } + void __set_invalid() { _M_valid = false; } + + void __opr_insert(size_t __shift, size_t __size); + void __opr_iterate(size_t __num) { _M_iterate += __num;} + + void __resize(size_t __from, size_t __to); + +private: + size_t _M_shift_count; + size_t _M_iterate; + size_t _M_resize; + float _M_list_cost; + float _M_vector_cost; + bool _M_valid; + size_t _M_max_size; +}; + +inline __list2vector_info::__list2vector_info(const __list2vector_info& __o) + : __object_info_base(__o) +{ + _M_shift_count = __o._M_shift_count; + _M_iterate = __o._M_iterate; + _M_vector_cost = __o._M_vector_cost; + _M_list_cost = __o._M_list_cost; + _M_valid = __o._M_valid; + _M_resize = __o._M_resize; + _M_max_size = __o._M_max_size; +} + +inline const char* __list2vector_info::__advice() const { + std::stringstream __sstream; + __sstream + << "change std::list to std::vector and its initial size from 0 to " + << _M_max_size; + return strdup(__sstream.str().c_str()); +} + +inline void __list2vector_info::__merge(const __list2vector_info& __o) +{ + _M_shift_count += __o._M_shift_count; + _M_iterate += __o._M_iterate; + _M_vector_cost += __o._M_vector_cost; + _M_list_cost += __o._M_list_cost; + _M_valid &= __o._M_valid; + _M_resize += __o._M_resize; + _M_max_size = std::max( _M_max_size, __o._M_max_size); +} + +inline void __list2vector_info::__opr_insert(size_t __shift, size_t __size) +{ + _M_shift_count += __shift; + _M_max_size = std::max(_M_max_size, __size); +} + +inline void __list2vector_info::__resize(size_t __from, size_t __to) +{ + _M_resize += __from; +} + +class __list2vector_stack_info: public __list2vector_info { + public: + __list2vector_stack_info(const __list2vector_info& __o) + : __list2vector_info(__o) {} +}; + +class __trace_list_to_vector + : public __trace_base<__list2vector_info, __list2vector_stack_info> +{ + public: + __trace_list_to_vector(); + ~__trace_list_to_vector() {} + + // Insert a new node at construct with object, callstack and initial size. + void __insert(__object_t __obj, __stack_t __stack); + // Call at destruction/clean to set container final size. + void __destruct(const void* __obj); + + // Find the node in the live map. + __list2vector_info* __find(const void* __obj); + + // Collect cost of operations. + void __opr_insert(const void* __obj, size_t __shift, size_t __size); + void __opr_iterate(const void* __obj, size_t __num); + void __invalid_operator(const void* __obj); + void __resize(const void* __obj, size_t __from, size_t __to); + float __vector_cost(size_t __shift, size_t __iterate); + float __list_cost(size_t __shift, size_t __iterate); +}; + +inline __trace_list_to_vector::__trace_list_to_vector() + : __trace_base<__list2vector_info, __list2vector_stack_info>() +{ + __id = "list-to-vector"; +} + +inline void __trace_list_to_vector::__insert(__object_t __obj, + __stack_t __stack) +{ + __add_object(__obj, __list2vector_info(__stack)); +} + +inline void __list2vector_info::__write(FILE* __f) const +{ + fprintf(__f, "%Zu %Zu %Zu %.0f %.0f\n", + _M_shift_count, _M_resize, _M_iterate, _M_vector_cost, _M_list_cost); +} + +inline float __trace_list_to_vector::__vector_cost(size_t __shift, + size_t __iterate) +{ + // The resulting vector will use a 'reserve' method. + return __shift * _GLIBCXX_PROFILE_DATA(__vector_shift_cost_factor).__value + + __iterate * _GLIBCXX_PROFILE_DATA(__vector_iterate_cost_factor).__value; +} + +inline float __trace_list_to_vector::__list_cost(size_t __shift, + size_t __iterate) +{ + return __shift * _GLIBCXX_PROFILE_DATA(__list_shift_cost_factor).__value + + __iterate * _GLIBCXX_PROFILE_DATA(__list_iterate_cost_factor).__value; +} + +inline void __trace_list_to_vector::__destruct(const void* __obj) +{ + if (!__is_on()) + return; + + __list2vector_info* __res = __get_object_info(__obj); + if (!__res) + return; + + float __vc = __vector_cost(__res->__shift_count(), __res->__iterate()); + float __lc = __list_cost(__res->__shift_count(), __res->__iterate()); + __res->__set_vector_cost(__vc); + __res->__set_list_cost(__lc); + __retire_object(__obj); +} + +inline void __trace_list_to_vector::__opr_insert(const void* __obj, + size_t __shift, size_t __size) +{ + __list2vector_info* __res = __get_object_info(__obj); + if (__res) + __res->__opr_insert(__shift, __size); +} + +inline void __trace_list_to_vector::__opr_iterate(const void* __obj, + size_t __num) +{ + __list2vector_info* __res = __get_object_info(__obj); + if (__res) { + __res->__opr_iterate(__num); + } +} + +inline void __trace_list_to_vector::__invalid_operator(const void* __obj) +{ + __list2vector_info* __res = __get_object_info(__obj); + if (__res) + __res->__set_invalid(); +} + +inline void __trace_list_to_vector::__resize(const void* __obj, size_t __from, + size_t __to) +{ + __list2vector_info* __res = __get_object_info(__obj); + if (__res) + __res->__resize(__from, __to); +} + +inline void __trace_list_to_vector_init() +{ + _GLIBCXX_PROFILE_DATA(_S_list_to_vector) = new __trace_list_to_vector(); +} + +inline void __trace_list_to_vector_report(FILE* __f, + __warning_vector_t& __warnings) +{ + if (_GLIBCXX_PROFILE_DATA(_S_list_to_vector)) { + _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__collect_warnings(__warnings); + _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__write(__f); + } +} + +inline void __trace_list_to_vector_construct(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__insert(__obj, __get_stack()); +} + +inline void __trace_list_to_vector_destruct(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__destruct(__obj); +} + +inline void __trace_list_to_vector_insert(const void* __obj, + size_t __shift, size_t __size) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__opr_insert(__obj, __shift, + __size); +} + + +inline void __trace_list_to_vector_iterate(const void* __obj, size_t __num = 1) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__opr_iterate(__obj, __num); +} + +inline void __trace_list_to_vector_invalid_operator(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__invalid_operator(__obj); +} + +inline void __trace_list_to_vector_resize(const void* __obj, + size_t __from, size_t __to) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__resize(__obj, __from, __to); +} + +} // namespace __gnu_profile +#endif /* _GLIBCXX_PROFILE_PROFILER_LIST_TO_VECTOR_H__ */
impl/profiler_list_to_vector.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler_vector_to_list.h =================================================================== --- impl/profiler_vector_to_list.h (nonexistent) +++ impl/profiler_vector_to_list.h (revision 826) @@ -0,0 +1,336 @@ +// -*- C++ -*- +// +// Copyright (C) 2009 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler_vector_to_list.h + * @brief diagnostics for vector to list. + */ + +// Written by Lixia Liu and Silvius Rus. + +#ifndef _GLIBCXX_PROFILE_PROFILER_VECTOR_TO_LIST_H +#define _GLIBCXX_PROFILE_PROFILER_VECTOR_TO_LIST_H 1 + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#else +#include +#include +#include +#endif +#include "profile/impl/profiler.h" +#include "profile/impl/profiler_node.h" +#include "profile/impl/profiler_trace.h" + +namespace __gnu_profile +{ + +/** @brief A vector-to-list instrumentation line in the object table. */ +class __vector2list_info: public __object_info_base +{ + public: + __vector2list_info() + :_M_shift_count(0), _M_iterate(0), _M_resize(0), _M_list_cost(0), + _M_vector_cost(0), _M_valid(true) {} + __vector2list_info(__stack_t __stack) + : __object_info_base(__stack), _M_shift_count(0), _M_iterate(0), + _M_resize(0), _M_list_cost(0), _M_vector_cost(0), _M_valid(true) {} + virtual ~__vector2list_info() {} + __vector2list_info(const __vector2list_info& __o); + void __merge(const __vector2list_info& __o); + void __write(FILE* __f) const; + float __magnitude() const { return _M_vector_cost - _M_list_cost; } + const char* __advice() const + { return strdup("change std::vector to std::list"); } + + size_t __shift_count() { return _M_shift_count; } + size_t __iterate() { return _M_iterate; } + float __list_cost() { return _M_list_cost; } + size_t __resize() { return _M_resize; } + void __set_list_cost(float __lc) { _M_list_cost = __lc; } + void __set_vector_cost(float __vc) { _M_vector_cost = __vc; } + bool __is_valid() { return _M_valid; } + void __set_invalid() { _M_valid = false; } + + void __opr_insert(size_t __pos, size_t __num); + void __opr_iterate(size_t __num); + void __resize(size_t __from, size_t __to); + void __opr_find(size_t __size); + +private: + size_t _M_shift_count; + size_t _M_iterate; + size_t _M_resize; + float _M_list_cost; + float _M_vector_cost; + bool _M_valid; +}; + +inline __vector2list_info::__vector2list_info(const __vector2list_info& __o) + : __object_info_base(__o) +{ + _M_shift_count = __o._M_shift_count; + _M_iterate = __o._M_iterate; + _M_vector_cost = __o._M_vector_cost; + _M_list_cost = __o._M_list_cost; + _M_valid = __o._M_valid; + _M_resize = __o._M_resize; +} + +inline void __vector2list_info::__merge(const __vector2list_info& __o) +{ + _M_shift_count += __o._M_shift_count; + _M_iterate += __o._M_iterate; + _M_vector_cost += __o._M_vector_cost; + _M_list_cost += __o._M_list_cost; + _M_valid &= __o._M_valid; + _M_resize += __o._M_resize; +} + +inline void __vector2list_info::__opr_insert(size_t __pos, size_t __num) +{ + _M_shift_count += __num - __pos; +} + +inline void __vector2list_info::__resize(size_t __from, size_t __to) +{ + _M_resize += __from; +} + +inline void __vector2list_info::__opr_iterate(size_t __num) +{ + _M_iterate += __num; +} + +inline void __vector2list_info::__opr_find(size_t __size) +{ + // Use average case complexity. + _M_iterate += 3.0 / 4.0 * __size; +} + +/** @brief A vector-to-list instrumentation line in the stack table. */ +class __vector2list_stack_info: public __vector2list_info { + public: + __vector2list_stack_info(const __vector2list_info& __o) + : __vector2list_info(__o) {} +}; + +/** @brief Vector-to-list instrumentation producer. */ +class __trace_vector_to_list + : public __trace_base<__vector2list_info, __vector2list_stack_info> +{ + public: + __trace_vector_to_list(); + ~__trace_vector_to_list() {} + + // Insert a new node at construct with object, callstack and initial size. + void __insert(__object_t __obj, __stack_t __stack); + // Call at destruction/clean to set container final size. + void __destruct(const void* __obj); + + // Find the node in the live map. + __vector2list_info* __find(const void* __obj); + + // Collect cost of operations. + void __opr_insert(const void* __obj, size_t __pos, size_t __num); + void __opr_iterate(const void* __obj, size_t __num); + void __invalid_operator(const void* __obj); + void __resize(const void* __obj, size_t __from, size_t __to); + float __vector_cost(size_t __shift, size_t __iterate, size_t __resize); + float __list_cost(size_t __shift, size_t __iterate, size_t __resize); + void __opr_find(const void* __obj, size_t __size); +}; + +inline __trace_vector_to_list::__trace_vector_to_list() + : __trace_base<__vector2list_info, __vector2list_stack_info>() +{ + __id = "vector-to-list"; +} + +inline void __trace_vector_to_list::__insert(__object_t __obj, + __stack_t __stack) +{ + __add_object(__obj, __vector2list_info(__stack)); +} + +inline void __vector2list_info::__write(FILE* __f) const +{ + fprintf(__f, "%Zu %Zu %Zu %.0f %.0f\n", + _M_shift_count, _M_resize, _M_iterate, _M_vector_cost, _M_list_cost); +} + +inline float __trace_vector_to_list::__vector_cost(size_t __shift, + size_t __iterate, + size_t __resize) +{ + return ( + __shift * _GLIBCXX_PROFILE_DATA(__vector_shift_cost_factor).__value + + __iterate * _GLIBCXX_PROFILE_DATA(__vector_iterate_cost_factor).__value + + __resize * _GLIBCXX_PROFILE_DATA(__vector_resize_cost_factor).__value + ); +} + +inline float __trace_vector_to_list::__list_cost(size_t __shift, + size_t __iterate, + size_t __resize) +{ + return ( + __shift * _GLIBCXX_PROFILE_DATA(__list_shift_cost_factor).__value + + __iterate * _GLIBCXX_PROFILE_DATA(__list_iterate_cost_factor).__value + + __resize * _GLIBCXX_PROFILE_DATA(__list_resize_cost_factor).__value); +} + +inline void __trace_vector_to_list::__destruct(const void* __obj) +{ + if (!__is_on()) + return; + + __vector2list_info* __res = __get_object_info(__obj); + if (!__res) + return; + + float __vc = __vector_cost(__res->__shift_count(), __res->__iterate(), + __res->__resize()); + float __lc = __list_cost(__res->__shift_count(), __res->__iterate(), + __res->__resize()); + __res->__set_vector_cost(__vc); + __res->__set_list_cost(__lc); + + __retire_object(__obj); +} + +inline void __trace_vector_to_list::__opr_insert(const void* __obj, + size_t __pos, size_t __num) +{ + __vector2list_info* __res = __get_object_info(__obj); + if (__res) + __res->__opr_insert(__pos, __num); +} + +inline void __trace_vector_to_list::__opr_iterate(const void* __obj, + size_t __num) +{ + __vector2list_info* __res = __get_object_info(__obj); + if (__res) + __res->__opr_iterate(__num); +} + +inline void __trace_vector_to_list::__invalid_operator(const void* __obj) +{ + __vector2list_info* __res = __get_object_info(__obj); + if (__res) + __res->__set_invalid(); +} + +inline void __trace_vector_to_list::__resize(const void* __obj, size_t __from, + size_t __to) +{ + __vector2list_info* __res = __get_object_info(__obj); + if (__res) + __res->__resize(__from, __to); +} + +inline void __trace_vector_to_list::__opr_find(const void* __obj, + size_t __size) +{ + __vector2list_info* __res = __get_object_info(__obj); + if (__res) + __res->__opr_find(__size); +} + +inline void __trace_vector_to_list_init() +{ + _GLIBCXX_PROFILE_DATA(_S_vector_to_list) = new __trace_vector_to_list(); +} + +inline void __trace_vector_to_list_report(FILE* __f, + __warning_vector_t& __warnings) +{ + if (_GLIBCXX_PROFILE_DATA(_S_vector_to_list)) { + _GLIBCXX_PROFILE_DATA(_S_vector_to_list)->__collect_warnings(__warnings); + _GLIBCXX_PROFILE_DATA(_S_vector_to_list)->__write(__f); + } +} + +inline void __trace_vector_to_list_construct(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_vector_to_list)->__insert(__obj, __get_stack()); +} + +inline void __trace_vector_to_list_destruct(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_vector_to_list)->__destruct(__obj); +} + +inline void __trace_vector_to_list_insert(const void* __obj, + size_t __pos, size_t __num) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_vector_to_list)->__opr_insert(__obj, __pos, __num); +} + + +inline void __trace_vector_to_list_iterate(const void* __obj, size_t __num = 1) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_vector_to_list)->__opr_iterate(__obj, __num); +} + +inline void __trace_vector_to_list_invalid_operator(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_vector_to_list)->__invalid_operator(__obj); +} + +inline void __trace_vector_to_list_resize(const void* __obj, + size_t __from, size_t __to) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_vector_to_list)->__resize(__obj, __from, __to); +} + +inline void __trace_vector_to_list_find(const void* __obj, size_t __size) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_vector_to_list)->__opr_find(__obj, __size); +} + +} // namespace __gnu_profile +#endif /* _GLIBCXX_PROFILE_PROFILER_VECTOR_TO_LIST_H */
impl/profiler_vector_to_list.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler.h =================================================================== --- impl/profiler.h (nonexistent) +++ impl/profiler.h (revision 826) @@ -0,0 +1,410 @@ +// -*- C++ -*- +// +// Copyright (C) 2009, 2010 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler.h + * @brief Interface of the profiling runtime library. + */ + +// Written by Lixia Liu and Silvius Rus. + +#ifndef _GLIBCXX_PROFILE_PROFILER_H +#define _GLIBCXX_PROFILE_PROFILER_H 1 + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#else +#include +#endif + +// Mechanism to define data with inline linkage. +#define _GLIBCXX_PROFILE_DEFINE_UNINIT_DATA(__type, __name) \ + inline __type& \ + __get_##__name() \ + { \ + static __type __name; \ + return __name; \ + } +#define _GLIBCXX_PROFILE_DEFINE_DATA(__type, __name, __initial_value...) \ + inline __type& __get_##__name() { \ + static __type __name(__initial_value); \ + return __name; \ + } +#define _GLIBCXX_PROFILE_DATA(__name) \ + __get_##__name() + +namespace __gnu_profile +{ + /** @brief Reentrance guard. + * + * Mechanism to protect all __gnu_profile operations against recursion, + * multithreaded and exception reentrance. + */ + struct __reentrance_guard + { + static bool + __get_in() + { + if (__inside() == true) + return false; + else + { + __inside() = true; + return true; + } + } + + static bool& + __inside() + { + static __thread bool _S_inside(false); + return _S_inside; + } + + __reentrance_guard() { } + ~__reentrance_guard() { __inside() = false; } + }; + +#define _GLIBCXX_PROFILE_REENTRANCE_GUARD(__x...) \ + { \ + if (__gnu_profile::__reentrance_guard::__get_in()) \ + { \ + __gnu_profile::__reentrance_guard __get_out; \ + __x; \ + } \ + } + + // Forward declarations of implementation functions. + // Don't use any __gnu_profile:: in user code. + // Instead, use the __profcxx... macros, which offer guarded access. + bool __turn_on(); + bool __turn_off(); + bool __is_invalid(); + bool __is_on(); + bool __is_off(); + void __report(void); + void __trace_hashtable_size_resize(const void*, size_t, size_t); + void __trace_hashtable_size_destruct(const void*, size_t, size_t); + void __trace_hashtable_size_construct(const void*, size_t); + void __trace_vector_size_resize(const void*, size_t, size_t); + void __trace_vector_size_destruct(const void*, size_t, size_t); + void __trace_vector_size_construct(const void*, size_t); + void __trace_hash_func_destruct(const void*, size_t, size_t, size_t); + void __trace_hash_func_construct(const void*); + void __trace_vector_to_list_destruct(const void*); + void __trace_vector_to_list_construct(const void*); + void __trace_vector_to_list_insert(const void*, size_t, size_t); + void __trace_vector_to_list_iterate(const void*, size_t); + void __trace_vector_to_list_invalid_operator(const void*); + void __trace_vector_to_list_resize(const void*, size_t, size_t); + void __trace_vector_to_list_find(const void*, size_t); + + void __trace_list_to_slist_destruct(const void*); + void __trace_list_to_slist_construct(const void*); + void __trace_list_to_slist_rewind(const void*); + void __trace_list_to_slist_operation(const void*); + + void __trace_list_to_vector_destruct(const void*); + void __trace_list_to_vector_construct(const void*); + void __trace_list_to_vector_insert(const void*, size_t, size_t); + void __trace_list_to_vector_iterate(const void*, size_t); + void __trace_list_to_vector_invalid_operator(const void*); + void __trace_list_to_vector_resize(const void*, size_t, size_t); + + void __trace_list_to_set_destruct(const void*); + void __trace_list_to_set_construct(const void*); + void __trace_list_to_set_insert(const void*, size_t, size_t); + void __trace_list_to_set_iterate(const void*, size_t); + void __trace_list_to_set_invalid_operator(const void*); + void __trace_list_to_set_find(const void*, size_t); + + void __trace_map_to_unordered_map_construct(const void*); + void __trace_map_to_unordered_map_invalidate(const void*); + void __trace_map_to_unordered_map_insert(const void*, size_t, size_t); + void __trace_map_to_unordered_map_erase(const void*, size_t, size_t); + void __trace_map_to_unordered_map_iterate(const void*, size_t); + void __trace_map_to_unordered_map_find(const void*, size_t); + void __trace_map_to_unordered_map_destruct(const void*); +} // namespace __gnu_profile + +// Master switch turns on all diagnostics that are not explicitly turned off. +#ifdef _GLIBCXX_PROFILE +#ifndef _GLIBCXX_PROFILE_NO_HASHTABLE_TOO_SMALL +#define _GLIBCXX_PROFILE_HASHTABLE_TOO_SMALL +#endif +#ifndef _GLIBCXX_PROFILE_NO_HASHTABLE_TOO_LARGE +#define _GLIBCXX_PROFILE_HASHTABLE_TOO_LARGE +#endif +#ifndef _GLIBCXX_PROFILE_NO_VECTOR_TOO_SMALL +#define _GLIBCXX_PROFILE_VECTOR_TOO_SMALL +#endif +#ifndef _GLIBCXX_PROFILE_NO_VECTOR_TOO_LARGE +#define _GLIBCXX_PROFILE_VECTOR_TOO_LARGE +#endif +#ifndef _GLIBCXX_PROFILE_NO_INEFFICIENT_HASH +#define _GLIBCXX_PROFILE_INEFFICIENT_HASH +#endif +#ifndef _GLIBCXX_PROFILE_NO_VECTOR_TO_LIST +#define _GLIBCXX_PROFILE_VECTOR_TO_LIST +#endif +#ifndef _GLIBCXX_PROFILE_NO_LIST_TO_SLIST +#define _GLIBCXX_PROFILE_LIST_TO_SLIST +#endif +#ifndef _GLIBCXX_PROFILE_NO_LIST_TO_VECTOR +#define _GLIBCXX_PROFILE_LIST_TO_VECTOR +#endif +#ifndef _GLIBCXX_PROFILE_NO_MAP_TO_UNORDERED_MAP +#define _GLIBCXX_PROFILE_MAP_TO_UNORDERED_MAP +#endif +#endif + +// Expose global management routines to user code. +#ifdef _GLIBCXX_PROFILE +#define __profcxx_report() \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__report()) +#define __profcxx_turn_on() \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__turn_on()) +#define __profcxx_turn_off() \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__turn_off()) +#define __profcxx_is_invalid() \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__is_invalid()) +#define __profcxx_is_on() \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__is_on()) +#define __profcxx__is_off() \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__is_off()) +#else +#define __profcxx_report() +#define __profcxx_turn_on() +#define __profcxx_turn_off() +#define __profcxx_is_invalid() +#define __profcxx_is_on() +#define __profcxx_is_off() +#endif + +// Turn on/off instrumentation for HASHTABLE_TOO_SMALL and HASHTABLE_TOO_LARGE. +#if (defined(_GLIBCXX_PROFILE_HASHTABLE_TOO_SMALL) \ + || defined(_GLIBCXX_PROFILE_HASHTABLE_TOO_LARGE)) +#define __profcxx_hashtable_resize(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_hashtable_size_resize(__x)) +#define __profcxx_hashtable_destruct(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_hashtable_size_destruct(__x)) +#define __profcxx_hashtable_construct(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_hashtable_size_construct(__x)) +#else +#define __profcxx_hashtable_resize(__x...) +#define __profcxx_hashtable_destruct(__x...) +#define __profcxx_hashtable_construct(__x...) +#endif + +// Turn on/off instrumentation for VECTOR_TOO_SMALL and VECTOR_TOO_LARGE. +#if (defined(_GLIBCXX_PROFILE_VECTOR_TOO_SMALL) \ + || defined(_GLIBCXX_PROFILE_VECTOR_TOO_LARGE)) +#define __profcxx_vector_resize(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_vector_size_resize(__x)) +#define __profcxx_vector_destruct(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_vector_size_destruct(__x)) +#define __profcxx_vector_construct(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_vector_size_construct(__x)) +#else +#define __profcxx_vector_resize(__x...) +#define __profcxx_vector_destruct(__x...) +#define __profcxx_vector_construct(__x...) +#endif + +// Turn on/off instrumentation for INEFFICIENT_HASH. +#if defined(_GLIBCXX_PROFILE_INEFFICIENT_HASH) +#define __profcxx_hashtable_construct2(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_hash_func_construct(__x)) +#define __profcxx_hashtable_destruct2(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_hash_func_destruct(__x)) +#else +#define __profcxx_hashtable_destruct2(__x...) +#define __profcxx_hashtable_construct2(__x...) +#endif + +// Turn on/off instrumentation for VECTOR_TO_LIST. +#if defined(_GLIBCXX_PROFILE_VECTOR_TO_LIST) +#define __profcxx_vector_construct2(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_vector_to_list_construct(__x)) +#define __profcxx_vector_destruct2(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_vector_to_list_destruct(__x)) +#define __profcxx_vector_insert(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_vector_to_list_insert(__x)) +#define __profcxx_vector_iterate(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_vector_to_list_iterate(__x)) +#define __profcxx_vector_invalid_operator(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_vector_to_list_invalid_operator(__x)) +#define __profcxx_vector_resize2(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_vector_to_list_resize(__x)) +#define __profcxx_vector_find(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_vector_to_list_find(__x)) +#else +#define __profcxx_vector_destruct2(__x...) +#define __profcxx_vector_construct2(__x...) +#define __profcxx_vector_insert(__x...) +#define __profcxx_vector_iterate(__x...) +#define __profcxx_vector_invalid_operator(__x...) +#define __profcxx_vector_resize2(__x...) +#define __profcxx_vector_find(__x...) +#endif + +// Turn on/off instrumentation for LIST_TO_VECTOR. +#if defined(_GLIBCXX_PROFILE_LIST_TO_VECTOR) +#define __profcxx_list_construct2(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_list_to_vector_construct(__x)) +#define __profcxx_list_destruct2(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_list_to_vector_destruct(__x)) +#define __profcxx_list_insert(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_list_to_vector_insert(__x)) +#define __profcxx_list_iterate(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_list_to_vector_iterate(__x)) +#define __profcxx_list_invalid_operator(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_list_to_vector_invalid_operator(__x)) +#else +#define __profcxx_list_destruct2(__x...) +#define __profcxx_list_construct2(__x...) +#define __profcxx_list_insert(__x...) +#define __profcxx_list_iterate(__x...) +#define __profcxx_list_invalid_operator(__x...) +#endif + +// Turn on/off instrumentation for LIST_TO_SLIST. +#if defined(_GLIBCXX_PROFILE_LIST_TO_SLIST) +#define __profcxx_list_rewind(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_list_to_slist_rewind(__x)) +#define __profcxx_list_operation(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_list_to_slist_operation(__x)) +#define __profcxx_list_destruct(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_list_to_slist_destruct(__x)) +#define __profcxx_list_construct(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_list_to_slist_construct(__x)) +#else +#define __profcxx_list_rewind(__x...) +#define __profcxx_list_operation(__x...) +#define __profcxx_list_destruct(__x...) +#define __profcxx_list_construct(__x...) +#endif + +// Turn on/off instrumentation for MAP_TO_UNORDERED_MAP. +#if defined(_GLIBCXX_PROFILE_MAP_TO_UNORDERED_MAP) +#define __profcxx_map_to_unordered_map_construct(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_map_to_unordered_map_construct(__x)) +#define __profcxx_map_to_unordered_map_destruct(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_map_to_unordered_map_destruct(__x)) +#define __profcxx_map_to_unordered_map_insert(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_map_to_unordered_map_insert(__x)) +#define __profcxx_map_to_unordered_map_erase(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_map_to_unordered_map_erase(__x)) +#define __profcxx_map_to_unordered_map_iterate(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_map_to_unordered_map_iterate(__x)) +#define __profcxx_map_to_unordered_map_invalidate(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_map_to_unordered_map_invalidate(__x)) +#define __profcxx_map_to_unordered_map_find(__x...) \ + _GLIBCXX_PROFILE_REENTRANCE_GUARD( \ + __gnu_profile::__trace_map_to_unordered_map_find(__x)) +#else +#define __profcxx_map_to_unordered_map_construct(__x...) \ + +#define __profcxx_map_to_unordered_map_destruct(__x...) +#define __profcxx_map_to_unordered_map_insert(__x...) +#define __profcxx_map_to_unordered_map_erase(__x...) +#define __profcxx_map_to_unordered_map_iterate(__x...) +#define __profcxx_map_to_unordered_map_invalidate(__x...) +#define __profcxx_map_to_unordered_map_find(__x...) +#endif + +// Set default values for compile-time customizable variables. +#ifndef _GLIBCXX_PROFILE_TRACE_PATH_ROOT +#define _GLIBCXX_PROFILE_TRACE_PATH_ROOT "libstdcxx-profile" +#endif +#ifndef _GLIBCXX_PROFILE_TRACE_ENV_VAR +#define _GLIBCXX_PROFILE_TRACE_ENV_VAR "_GLIBCXX_PROFILE_TRACE_PATH_ROOT" +#endif +#ifndef _GLIBCXX_PROFILE_MAX_WARN_COUNT_ENV_VAR +#define _GLIBCXX_PROFILE_MAX_WARN_COUNT_ENV_VAR \ + "_GLIBCXX_PROFILE_MAX_WARN_COUNT" +#endif +#ifndef _GLIBCXX_PROFILE_MAX_WARN_COUNT +#define _GLIBCXX_PROFILE_MAX_WARN_COUNT 10 +#endif +#ifndef _GLIBCXX_PROFILE_MAX_STACK_DEPTH +#define _GLIBCXX_PROFILE_MAX_STACK_DEPTH 32 +#endif +#ifndef _GLIBCXX_PROFILE_MAX_STACK_DEPTH_ENV_VAR +#define _GLIBCXX_PROFILE_MAX_STACK_DEPTH_ENV_VAR \ + "_GLIBCXX_PROFILE_MAX_STACK_DEPTH" +#endif +#ifndef _GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC +#define _GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC 2 << 27 +#endif +#ifndef _GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC_ENV_VAR +#define _GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC_ENV_VAR \ + "_GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC" +#endif + +// Instrumentation hook implementations. +#include "profile/impl/profiler_hash_func.h" +#include "profile/impl/profiler_hashtable_size.h" +#include "profile/impl/profiler_map_to_unordered_map.h" +#include "profile/impl/profiler_vector_size.h" +#include "profile/impl/profiler_vector_to_list.h" +#include "profile/impl/profiler_list_to_slist.h" +#include "profile/impl/profiler_list_to_vector.h" + +#endif // _GLIBCXX_PROFILE_PROFILER_H
impl/profiler.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler_state.h =================================================================== --- impl/profiler_state.h (nonexistent) +++ impl/profiler_state.h (revision 826) @@ -0,0 +1,70 @@ +// -*- C++ -*- +// +// Copyright (C) 2009 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler_state.h + * @brief Global profiler state. + */ + +// Written by Lixia Liu and Silvius Rus. + +#ifndef _GLIBCXX_PROFILE_PROFILER_STATE_H +#define _GLIBCXX_PROFILE_PROFILER_STATE_H 1 + +namespace __gnu_profile +{ + +enum __state_type { __ON, __OFF, __INVALID }; + +_GLIBCXX_PROFILE_DEFINE_DATA(__state_type, __state, __INVALID); + +inline bool __turn(__state_type __s) +{ + return (_GLIBCXX_PROFILE_DATA(__state) + == __sync_val_compare_and_swap(&_GLIBCXX_PROFILE_DATA(__state), + __INVALID, __s)); +} + +inline bool __turn_on() +{ return __turn(__ON); } + +inline bool __turn_off() +{ return __turn(__OFF); } + +inline bool __is_on() +{ return _GLIBCXX_PROFILE_DATA(__state) == __ON; } + +inline bool __is_off() +{ return _GLIBCXX_PROFILE_DATA(__state) == __OFF; } + +inline bool __is_invalid() +{ return _GLIBCXX_PROFILE_DATA(__state) == __INVALID; } + +} // end namespace __gnu_profile +#endif /* _GLIBCXX_PROFILE_PROFILER_STATE_H */
impl/profiler_state.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler_map_to_unordered_map.h =================================================================== --- impl/profiler_map_to_unordered_map.h (nonexistent) +++ impl/profiler_map_to_unordered_map.h (revision 826) @@ -0,0 +1,292 @@ +// -*- C++ -*- +// +// Copyright (C) 2009 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler_map_to_unordered_map.h + * @brief Diagnostics for map to unordered_map. + */ + +// Written by Silvius Rus. + +#ifndef _GLIBCXX_PROFILE_PROFILER_MAP_TO_UNORDERED_MAP_H +#define _GLIBCXX_PROFILE_PROFILER_MAP_TO_UNORDERED_MAP_H 1 + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#else +#include +#include +#include +#endif +#include "profile/impl/profiler.h" +#include "profile/impl/profiler_node.h" +#include "profile/impl/profiler_trace.h" + +namespace __gnu_profile +{ + +inline int __log2(size_t __size) +{ + for (int __bit_count = sizeof(size_t) - 1; __bit_count >= 0; -- __bit_count) + { + if ((2 << __bit_count) & __size) { + return __bit_count; + } + } + return 0; +} + +inline float __map_insert_cost(size_t __size) +{ + return (_GLIBCXX_PROFILE_DATA(__map_insert_cost_factor).__value + * static_cast(__log2(__size))); +} + +inline float __map_erase_cost(size_t __size) +{ + return (_GLIBCXX_PROFILE_DATA(__map_erase_cost_factor).__value + * static_cast(__log2(__size))); +} + +inline float __map_find_cost(size_t __size) +{ + return (_GLIBCXX_PROFILE_DATA(__map_find_cost_factor).__value + * static_cast(__log2(__size))); +} + +/** @brief A map-to-unordered_map instrumentation line in the object table. */ +class __map2umap_info: public __object_info_base +{ + public: + __map2umap_info() + : _M_insert(0), _M_erase(0), _M_find(0), _M_iterate(0), + _M_map_cost(0.0), _M_umap_cost(0.0), _M_valid(true) {} + __map2umap_info(__stack_t __stack) + : __object_info_base(__stack), _M_insert(0), _M_erase(0), _M_find(0), + _M_iterate(0), _M_map_cost(0.0), _M_umap_cost(0.0), _M_valid(true) {} + virtual ~__map2umap_info() {} + __map2umap_info(const __map2umap_info& o); + void __merge(const __map2umap_info& o); + void __write(FILE* __f) const; + float __magnitude() const { return _M_map_cost - _M_umap_cost; } + const char* __advice() const; + + void __record_insert(size_t __size, size_t __count); + void __record_erase(size_t __size, size_t __count); + void __record_find(size_t __size); + void __record_iterate(size_t __count); + void __record_invalidate(); + + private: + size_t _M_insert; + size_t _M_erase; + size_t _M_find; + size_t _M_iterate; + float _M_umap_cost; + float _M_map_cost; + bool _M_valid; +}; + +inline const char* __map2umap_info::__advice() const +{ + return strdup("change std::map to std::unordered_map"); +} + +inline __map2umap_info::__map2umap_info(const __map2umap_info& __o) + : __object_info_base(__o), + _M_insert(__o._M_insert), + _M_erase(__o._M_erase), + _M_find(__o._M_find), + _M_iterate(__o._M_iterate), + _M_map_cost(__o._M_map_cost), + _M_umap_cost(__o._M_umap_cost), + _M_valid(__o._M_valid) +{} + +inline void __map2umap_info::__merge(const __map2umap_info& __o) +{ + _M_insert += __o._M_insert; + _M_erase += __o._M_erase; + _M_find += __o._M_find; + _M_map_cost += __o._M_map_cost; + _M_umap_cost += __o._M_umap_cost; + _M_valid &= __o._M_valid; +} + +inline void __map2umap_info:: __record_insert(size_t __size, size_t __count) +{ + _M_insert += __count; + _M_map_cost += __count * __map_insert_cost(__size); + _M_umap_cost += (__count + * _GLIBCXX_PROFILE_DATA(__umap_insert_cost_factor).__value); +} + +inline void __map2umap_info:: __record_erase(size_t __size, size_t __count) +{ + _M_erase += __count; + _M_map_cost += __count * __map_erase_cost(__size); + _M_umap_cost += (__count + * _GLIBCXX_PROFILE_DATA(__umap_erase_cost_factor).__value); +} + +inline void __map2umap_info:: __record_find(size_t __size) +{ + _M_find += 1; + _M_map_cost += __map_find_cost(__size); + _M_umap_cost += _GLIBCXX_PROFILE_DATA(__umap_find_cost_factor).__value; +} + +inline void __map2umap_info:: __record_iterate(size_t __count) +{ + _M_iterate += __count; + _M_map_cost += (__count + * _GLIBCXX_PROFILE_DATA(__map_iterate_cost_factor).__value); + _M_umap_cost += ( + __count * _GLIBCXX_PROFILE_DATA(__umap_iterate_cost_factor).__value); +} + +inline void __map2umap_info:: __record_invalidate() +{ + _M_valid = false; +} + +inline void __map2umap_info::__write(FILE* __f) const +{ + fprintf(__f, "%Zu %Zu %Zu %Zu %.0f %.0f %s\n", + _M_insert, _M_erase, _M_find, _M_iterate, _M_map_cost, _M_umap_cost, + _M_valid ? "valid" : "invalid"); +} + +/** @brief A map-to-unordered_map instrumentation line in the stack table. */ +class __map2umap_stack_info: public __map2umap_info +{ + public: + __map2umap_stack_info(const __map2umap_info& o) : __map2umap_info(o) {} +}; + +/** @brief Map-to-unordered_map instrumentation producer. */ +class __trace_map2umap + : public __trace_base<__map2umap_info, __map2umap_stack_info> +{ + public: + __trace_map2umap(); +}; + +inline __trace_map2umap::__trace_map2umap() + : __trace_base<__map2umap_info, __map2umap_stack_info>() +{ + __id = "map-to-unordered-map"; +} + +inline void __trace_map_to_unordered_map_init() +{ + _GLIBCXX_PROFILE_DATA(_S_map2umap) = new __trace_map2umap(); +} + +inline void __trace_map_to_unordered_map_report( + FILE* __f, __warning_vector_t& __warnings) +{ + if (_GLIBCXX_PROFILE_DATA(_S_map2umap)) { + _GLIBCXX_PROFILE_DATA(_S_map2umap)->__collect_warnings(__warnings); + _GLIBCXX_PROFILE_DATA(_S_map2umap)->__write(__f); + } +} + +inline void __trace_map_to_unordered_map_construct(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_map2umap)->__add_object( + __obj, __map2umap_info(__get_stack())); +} + +inline void __trace_map_to_unordered_map_destruct(const void* __obj) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_map2umap)->__retire_object(__obj); +} + +inline void __trace_map_to_unordered_map_insert(const void* __obj, + size_t __size, size_t __count) +{ + if (!__profcxx_init()) return; + + __map2umap_info* __info = + _GLIBCXX_PROFILE_DATA(_S_map2umap)->__get_object_info(__obj); + + if (__info) __info->__record_insert(__size, __count); +} + +inline void __trace_map_to_unordered_map_erase(const void* __obj, + size_t __size, size_t __count) +{ + if (!__profcxx_init()) return; + + __map2umap_info* __info = + _GLIBCXX_PROFILE_DATA(_S_map2umap)->__get_object_info(__obj); + + if (__info) __info->__record_erase(__size, __count); +} + +inline void __trace_map_to_unordered_map_find(const void* __obj, size_t __size) +{ + if (!__profcxx_init()) return; + + __map2umap_info* __info = + _GLIBCXX_PROFILE_DATA(_S_map2umap)->__get_object_info(__obj); + + if (__info) __info->__record_find(__size); +} + +inline void __trace_map_to_unordered_map_iterate(const void* __obj, + size_t __count) +{ + if (!__profcxx_init()) return; + + __map2umap_info* __info = + _GLIBCXX_PROFILE_DATA(_S_map2umap)->__get_object_info(__obj); + + if (__info) __info->__record_iterate(__count); +} + +inline void __trace_map_to_unordered_map_invalidate(const void* __obj) +{ + if (!__profcxx_init()) return; + + __map2umap_info* __info = + _GLIBCXX_PROFILE_DATA(_S_map2umap)->__get_object_info(__obj); + + if (__info) __info->__record_invalidate(); +} + +} // namespace __gnu_profile +#endif /* _GLIBCXX_PROFILE_PROFILER_MAP_TO_UNORDERED_MAP_H */
impl/profiler_map_to_unordered_map.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler_hashtable_size.h =================================================================== --- impl/profiler_hashtable_size.h (nonexistent) +++ impl/profiler_hashtable_size.h (revision 826) @@ -0,0 +1,108 @@ +// -*- C++ -*- +// +// Copyright (C) 2009 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler_hashtable_size.h + * @brief Collection of hashtable size traces. + */ + +// Written by Lixia Liu and Silvius Rus. + +#ifndef _GLIBCXX_PROFILE_PROFILER_HASHTABLE_SIZE_H +#define _GLIBCXX_PROFILE_PROFILER_HASHTABLE_SIZE_H 1 + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#else +#include +#include +#include +#endif +#include "profile/impl/profiler.h" +#include "profile/impl/profiler_node.h" +#include "profile/impl/profiler_trace.h" +#include "profile/impl/profiler_state.h" +#include "profile/impl/profiler_container_size.h" + +namespace __gnu_profile +{ + +/** @brief Hashtable size instrumentation trace producer. */ +class __trace_hashtable_size : public __trace_container_size +{ + public: + __trace_hashtable_size() : __trace_container_size() + { + __id = "hashtable-size"; + } +}; + +inline void __trace_hashtable_size_init() +{ + _GLIBCXX_PROFILE_DATA(_S_hashtable_size) = new __trace_hashtable_size(); +} + +inline void __trace_hashtable_size_report(FILE* __f, + __warning_vector_t& __warnings) +{ + if (_GLIBCXX_PROFILE_DATA(_S_hashtable_size)) { + _GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__collect_warnings(__warnings); + _GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__write(__f); + } +} + +inline void __trace_hashtable_size_construct(const void* __obj, size_t __num) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__insert(__obj, __get_stack(), + __num); +} + +inline void __trace_hashtable_size_destruct(const void* __obj, size_t __num, + size_t __inum) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__destruct(__obj, __num, __inum); +} + +inline void __trace_hashtable_size_resize(const void* __obj, size_t __from, + size_t __to) +{ + if (!__profcxx_init()) return; + + _GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__resize(__obj, __from, __to); +} + +} // namespace __gnu_profile + +#endif /* _GLIBCXX_PROFILE_PROFILER_HASHTABLE_SIZE_H */
impl/profiler_hashtable_size.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: impl/profiler_node.h =================================================================== --- impl/profiler_node.h (nonexistent) +++ impl/profiler_node.h (revision 826) @@ -0,0 +1,172 @@ +// -*- C++ -*- +// +// Copyright (C) 2009 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, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, 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. + +/** @file profile/impl/profiler_node.h + * @brief Data structures to represent a single profiling event. + */ + +// Written by Lixia Liu and Silvius Rus. + +#ifndef _GLIBCXX_PROFILE_PROFILER_NODE_H +#define _GLIBCXX_PROFILE_PROFILER_NODE_H 1 + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#include +#include +#else +#include +#include +#include +#endif +#include +#if defined _GLIBCXX_HAVE_EXECINFO_H +#include +#endif + +namespace __gnu_profile +{ +typedef const void* __object_t; +typedef void* __instruction_address_t; +typedef std::_GLIBCXX_STD_PR::vector<__instruction_address_t> __stack_npt; +typedef __stack_npt* __stack_t; + +size_t __stack_max_depth(); + +inline __stack_t __get_stack() +{ +#if defined _GLIBCXX_HAVE_EXECINFO_H + size_t __max_depth = __stack_max_depth(); + if (__max_depth == 0) + return NULL; + __stack_npt __buffer(__max_depth); + int __depth = backtrace(&__buffer[0], __max_depth); + __stack_t __stack = new __stack_npt(__depth); + memcpy(&(*__stack)[0], &__buffer[0], __depth * sizeof(__object_t)); + return __stack; +#else + return NULL; +#endif +} + +inline __size(const __stack_t& __stack) +{ + if (!__stack) { + return 0; + } else { + return __stack->size(); + } +} + +inline void __write(FILE* __f, const __stack_t __stack) +{ + if (!__stack) { + return; + } + + __stack_npt::const_iterator __it; + for (__it = __stack->begin(); __it != __stack->end(); ++__it) { + fprintf(__f, "%p ", *__it); + } +} + +/** @brief Hash function for summary trace using call stack as index. */ +class __stack_hash +{ + public: + size_t operator()(const __stack_t __s) const + { + if (!__s) { + return 0; + } + + uintptr_t __index = 0; + __stack_npt::const_iterator __it; + for (__it = __s->begin(); __it != __s->end(); ++__it) { + __index += reinterpret_cast(*__it); + } + return __index; + } + + bool operator() (const __stack_t __stack1, const __stack_t __stack2) const + { + if (!__stack1 && !__stack2) return true; + if (!__stack1 || !__stack2) return false; + if (__stack1->size() != __stack2->size()) return false; + + size_t __byte_size = __stack1->size() * sizeof(__stack_npt::value_type); + return memcmp(&(*__stack1)[0], &(*__stack2)[0], __byte_size) == 0; + } +}; + +/** @brief Base class for a line in the object table. */ +class __object_info_base +{ + public: + __object_info_base() {} + __object_info_base(__stack_t __stack); + __object_info_base(const __object_info_base& o); + virtual ~__object_info_base() {} + bool __is_valid() const { return _M_valid; } + __stack_t __stack() const { return _M_stack; } + virtual void __write(FILE* f) const = 0; + + protected: + __stack_t _M_stack; + bool _M_valid; +}; + +inline __object_info_base::__object_info_base(__stack_t __stack) +{ + _M_stack = __stack; + _M_valid = true; +} + +inline __object_info_base::__object_info_base(const __object_info_base& __o) +{ + _M_stack = __o._M_stack; + _M_valid = __o._M_valid; +} + +/** @brief Base class for a line in the stack table. */ +template +class __stack_info_base +{ + public: + __stack_info_base() {} + __stack_info_base(const __object_info& __info) = 0; + virtual ~__stack_info_base() {} + void __merge(const __object_info& __info) = 0; + virtual float __magnitude() const = 0; + virtual const char* __get_id() const = 0; +}; + +} // namespace __gnu_profile +#endif /* _GLIBCXX_PROFILE_PROFILER_NODE_H */
impl/profiler_node.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: set.h =================================================================== --- set.h (nonexistent) +++ set.h (revision 826) @@ -0,0 +1,376 @@ +// Profiling set implementation -*- C++ -*- + +// Copyright (C) 2009, 2010 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 3, 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file profile/set.h + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_SET_H +#define _GLIBCXX_PROFILE_SET_H 1 + +#include + +namespace std +{ +namespace __profile +{ + /// Class std::set wrapper with performance instrumentation. + template, + typename _Allocator = std::allocator<_Key> > + class set + : public _GLIBCXX_STD_D::set<_Key,_Compare,_Allocator> + { + typedef _GLIBCXX_STD_D::set<_Key, _Compare, _Allocator> _Base; + + public: + // types: + typedef _Key key_type; + typedef _Key value_type; + typedef _Compare key_compare; + typedef _Compare value_compare; + typedef _Allocator allocator_type; + typedef typename _Base::reference reference; + typedef typename _Base::const_reference const_reference; + + typedef typename _Base::iterator iterator; + typedef typename _Base::const_iterator const_iterator; + typedef typename _Base::reverse_iterator reverse_iterator; + typedef typename _Base::const_reverse_iterator const_reverse_iterator; + + typedef typename _Base::size_type size_type; + typedef typename _Base::difference_type difference_type; + typedef typename _Base::pointer pointer; + typedef typename _Base::const_pointer const_pointer; + + // 23.3.3.1 construct/copy/destroy: + explicit set(const _Compare& __comp = _Compare(), + const _Allocator& __a = _Allocator()) + : _Base(__comp, __a) { } + + template + set(_InputIterator __first, _InputIterator __last, + const _Compare& __comp = _Compare(), + const _Allocator& __a = _Allocator()) + : _Base(__first, __last, __comp, __a) { } + + set(const set& __x) + : _Base(__x) { } + + set(const _Base& __x) + : _Base(__x) { } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + set(set&& __x) + : _Base(std::forward(__x)) + { } + + set(initializer_list __l, + const _Compare& __comp = _Compare(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __comp, __a) { } +#endif + + ~set() { } + + set& + operator=(const set& __x) + { + *static_cast<_Base*>(this) = __x; + return *this; + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + set& + operator=(set&& __x) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } + + set& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l); + return *this; + } +#endif + + using _Base::get_allocator; + + // iterators: + iterator + begin() + { return iterator(_Base::begin()); } + + const_iterator + begin() const + { return const_iterator(_Base::begin()); } + + iterator + end() + { return iterator(_Base::end()); } + + const_iterator + end() const + { return const_iterator(_Base::end()); } + + reverse_iterator + rbegin() + { return reverse_iterator(end()); } + + const_reverse_iterator + rbegin() const + { return const_reverse_iterator(end()); } + + reverse_iterator + rend() + { return reverse_iterator(begin()); } + + const_reverse_iterator + rend() const + { return const_reverse_iterator(begin()); } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + const_iterator + cbegin() const + { return const_iterator(_Base::begin()); } + + const_iterator + cend() const + { return const_iterator(_Base::end()); } + + const_reverse_iterator + crbegin() const + { return const_reverse_iterator(end()); } + + const_reverse_iterator + crend() const + { return const_reverse_iterator(begin()); } +#endif + + // capacity: + using _Base::empty; + using _Base::size; + using _Base::max_size; + + // modifiers: + std::pair + insert(const value_type& __x) + { + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, bool> __res = _Base::insert(__x); + return std::pair(iterator(__res.first), + __res.second); + } + + iterator + insert(iterator __position, const value_type& __x) + { + return iterator(_Base::insert(__position, __x)); + } + + template + void + insert(_InputIterator __first, _InputIterator __last) + { + _Base::insert(__first, __last); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + insert(initializer_list __l) + { _Base::insert(__l); } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + erase(iterator __position) + { return _Base::erase(__position); } +#else + void + erase(iterator __position) + { _Base::erase(__position); } +#endif + + size_type + erase(const key_type& __x) + { + iterator __victim = find(__x); + if (__victim == end()) + return 0; + else + { + _Base::erase(__victim); + return 1; + } + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + erase(iterator __first, iterator __last) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 151. can't currently clear() empty container + while (__first != __last) + this->erase(__first++); + return __last; + } +#else + void + erase(iterator __first, iterator __last) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 151. can't currently clear() empty container + while (__first != __last) + this->erase(__first++); + } +#endif + + void + swap(set& __x) + { + _Base::swap(__x); + } + + void + clear() + { this->erase(begin(), end()); } + + // observers: + using _Base::key_comp; + using _Base::value_comp; + + // set operations: + iterator + find(const key_type& __x) + { return iterator(_Base::find(__x)); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 214. set::find() missing const overload + const_iterator + find(const key_type& __x) const + { return const_iterator(_Base::find(__x)); } + + using _Base::count; + + iterator + lower_bound(const key_type& __x) + { return iterator(_Base::lower_bound(__x)); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 214. set::find() missing const overload + const_iterator + lower_bound(const key_type& __x) const + { return const_iterator(_Base::lower_bound(__x)); } + + iterator + upper_bound(const key_type& __x) + { return iterator(_Base::upper_bound(__x)); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 214. set::find() missing const overload + const_iterator + upper_bound(const key_type& __x) const + { return const_iterator(_Base::upper_bound(__x)); } + + std::pair + equal_range(const key_type& __x) + { + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, _Base_iterator> __res = + _Base::equal_range(__x); + return std::make_pair(iterator(__res.first), + iterator(__res.second)); + } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 214. set::find() missing const overload + std::pair + equal_range(const key_type& __x) const + { + typedef typename _Base::const_iterator _Base_iterator; + std::pair<_Base_iterator, _Base_iterator> __res = + _Base::equal_range(__x); + return std::make_pair(const_iterator(__res.first), + const_iterator(__res.second)); + } + + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + + }; + + template + inline bool + operator==(const set<_Key, _Compare, _Allocator>& __lhs, + const set<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() == __rhs._M_base(); } + + template + inline bool + operator!=(const set<_Key, _Compare, _Allocator>& __lhs, + const set<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() != __rhs._M_base(); } + + template + inline bool + operator<(const set<_Key, _Compare, _Allocator>& __lhs, + const set<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() < __rhs._M_base(); } + + template + inline bool + operator<=(const set<_Key, _Compare, _Allocator>& __lhs, + const set<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() <= __rhs._M_base(); } + + template + inline bool + operator>=(const set<_Key, _Compare, _Allocator>& __lhs, + const set<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() >= __rhs._M_base(); } + + template + inline bool + operator>(const set<_Key, _Compare, _Allocator>& __lhs, + const set<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() > __rhs._M_base(); } + + template + void + swap(set<_Key, _Compare, _Allocator>& __x, + set<_Key, _Compare, _Allocator>& __y) + { return __x.swap(__y); } + +} // namespace __profile +} // namespace std + +#endif
set.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: unordered_set =================================================================== --- unordered_set (nonexistent) +++ unordered_set (revision 826) @@ -0,0 +1,506 @@ +// Profiling unordered_set/unordered_multiset implementation -*- C++ -*- + +// Copyright (C) 2009, 2010 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. + +/** @file profile/unordered_set + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_UNORDERED_SET +#define _GLIBCXX_PROFILE_UNORDERED_SET 1 + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +# include +#else +# include + +#include + +#define _GLIBCXX_BASE unordered_set<_Key, _Hash, _Pred, _Alloc> +#define _GLIBCXX_STD_BASE _GLIBCXX_STD_PR::_GLIBCXX_BASE + +namespace std +{ +namespace __profile +{ + /** @brief Unordered_set wrapper with performance instrumentation. */ + template, + typename _Pred = std::equal_to<_Key>, + typename _Alloc = std::allocator<_Key> > + class unordered_set + : public _GLIBCXX_STD_BASE + { + typedef typename _GLIBCXX_STD_BASE _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + typedef typename _Base::key_type key_type; + typedef typename _Base::value_type value_type; + typedef typename _Base::difference_type difference_type; + typedef typename _Base::reference reference; + typedef typename _Base::const_reference const_reference; + + typedef typename _Base::iterator iterator; + typedef typename _Base::const_iterator const_iterator; + + explicit + unordered_set(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __eql, __a) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + __profcxx_hashtable_construct2(this); + } + + template + unordered_set(_InputIterator __f, _InputIterator __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __eql, __a) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + __profcxx_hashtable_construct2(this); + } + + unordered_set(const _Base& __x) + : _Base(__x) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + __profcxx_hashtable_construct2(this); + } + + unordered_set(unordered_set&& __x) + : _Base(std::forward<_Base>(__x)) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + __profcxx_hashtable_construct2(this); + } + + unordered_set(initializer_list __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __n, __hf, __eql, __a) { } + + unordered_set& + operator=(const unordered_set& __x) + { + *static_cast<_Base*>(this) = __x; + return *this; + } + + unordered_set& + operator=(unordered_set&& __x) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } + + unordered_set& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l); + return *this; + } + + ~unordered_set() + { + __profcxx_hashtable_destruct(this, _Base::bucket_count(), + _Base::size()); + _M_profile_destruct(); + } + + void + swap(unordered_set& __x) + { + _Base::swap(__x); + } + + void + clear() + { + __profcxx_hashtable_destruct(this, _Base::bucket_count(), + _Base::size()); + _M_profile_destruct(); + _Base::clear(); + } + + void + insert(std::initializer_list __l) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__l); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + std::pair + insert(const value_type& __obj) + { + size_type __old_size = _Base::bucket_count(); + std::pair __res = _Base::insert(__obj); + _M_profile_resize(__old_size, _Base::bucket_count()); + return __res; + } + + iterator + insert(const_iterator __iter, const value_type& __v) + { + size_type __old_size = _Base::bucket_count(); + iterator __res = _Base::insert(__iter, __v); + _M_profile_resize(__old_size, _Base::bucket_count()); + return __res; + } + + template + void + insert(_InputIter __first, _InputIter __last) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__first, __last); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + void + insert(const value_type* __first, const value_type* __last) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__first, __last); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + void rehash(size_type __n) + { + size_type __old_size = _Base::bucket_count(); + _Base::rehash(__n); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + private: + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + + void + _M_profile_resize(size_type __old_size, size_type __new_size) + { + if (__old_size != __new_size) + __profcxx_hashtable_resize(this, __old_size, __new_size); + } + + void + _M_profile_destruct() + { + size_type __hops = 0, __lc = 0, __chain = 0; + for (iterator __it = _M_base().begin(); __it != _M_base().end(); + ++__it) + { + while (__it._M_cur_node->_M_next) + { + ++__chain; + ++__it; + } + + if (__chain) + { + ++__chain; + __lc = __lc > __chain ? __lc : __chain; + __hops += __chain * (__chain - 1) / 2; + __chain = 0; + } + } + __profcxx_hashtable_destruct2(this, __lc, _Base::size(), __hops); + } + + }; + + template + inline void + swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, + unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + + template + inline bool + operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, + const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) + { return __x._M_equal(__y); } + + template + inline bool + operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, + const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) + { return !(__x == __y); } + +#undef _GLIBCXX_BASE +#undef _GLIBCXX_STD_BASE +#define _GLIBCXX_STD_BASE _GLIBCXX_STD_PR::_GLIBCXX_BASE +#define _GLIBCXX_BASE unordered_multiset<_Value, _Hash, _Pred, _Alloc> + + /** @brief Unordered_multiset wrapper with performance instrumentation. */ + template, + typename _Pred = std::equal_to<_Value>, + typename _Alloc = std::allocator<_Value> > + class unordered_multiset + : public _GLIBCXX_STD_BASE + { + typedef typename _GLIBCXX_STD_BASE _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + typedef typename _Base::key_type key_type; + typedef typename _Base::value_type value_type; + typedef typename _Base::difference_type difference_type; + typedef typename _Base::reference reference; + typedef typename _Base::const_reference const_reference; + + typedef typename _Base::iterator iterator; + typedef typename _Base::const_iterator const_iterator; + + explicit + unordered_multiset(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __eql, __a) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + } + + template + unordered_multiset(_InputIterator __f, _InputIterator __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __eql, __a) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + } + + unordered_multiset(const _Base& __x) + : _Base(__x) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + } + + unordered_multiset(unordered_multiset&& __x) + : _Base(std::forward<_Base>(__x)) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + } + + unordered_multiset(initializer_list __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __n, __hf, __eql, __a) { } + + unordered_multiset& + operator=(const unordered_multiset& __x) + { + *static_cast<_Base*>(this) = __x; + return *this; + } + + unordered_multiset& + operator=(unordered_multiset&& __x) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } + + unordered_multiset& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l); + return *this; + } + + ~unordered_multiset() + { + __profcxx_hashtable_destruct(this, _Base::bucket_count(), + _Base::size()); + _M_profile_destruct(); + } + + void + swap(unordered_multiset& __x) + { + _Base::swap(__x); + } + + void + clear() + { + __profcxx_hashtable_destruct(this, _Base::bucket_count(), + _Base::size()); + _M_profile_destruct(); + _Base::clear(); + } + + void + insert(std::initializer_list __l) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__l); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + iterator + insert(const value_type& __obj) + { + size_type __old_size = _Base::bucket_count(); + iterator __res = _Base::insert(__obj); + _M_profile_resize(__old_size, _Base::bucket_count()); + return __res; + } + + iterator + insert(const_iterator __iter, const value_type& __v) + { + size_type __old_size = _Base::bucket_count(); + iterator __res = _Base::insert(__iter, __v); + _M_profile_resize(__old_size, _Base::bucket_count()); + return __res; + } + + template + void + insert(_InputIter __first, _InputIter __last) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__first, __last); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + void + insert(const value_type* __first, const value_type* __last) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__first, __last); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + void rehash(size_type __n) + { + size_type __old_size = _Base::bucket_count(); + _Base::rehash(__n); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + private: + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + + void + _M_profile_resize(size_type __old_size, size_type __new_size) + { + if (__old_size != __new_size) + __profcxx_hashtable_resize(this, __old_size, __new_size); + } + + void + _M_profile_destruct() + { + size_type __hops = 0, __lc = 0, __chain = 0; + for (iterator __it = _M_base().begin(); __it != _M_base().end(); + ++__it) + { + while (__it._M_cur_node->_M_next) + { + ++__chain; + ++__it; + } + + if (__chain) + { + ++__chain; + __lc = __lc > __chain ? __lc : __chain; + __hops += __chain * (__chain - 1) / 2; + __chain = 0; + } + } + __profcxx_hashtable_destruct2(this, __lc, _Base::size(), __hops); + } + + }; + + template + inline void + swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + + template + inline bool + operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) + { return __x._M_equal(__y); } + + template + inline bool + operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) + { return !(__x == __y); } + +} // namespace __profile +} // namespace std + +#undef _GLIBCXX_BASE +#undef _GLIBCXX_STD_BASE + +#endif // __GXX_EXPERIMENTAL_CXX0X__ + +#endif Index: vector =================================================================== --- vector (nonexistent) +++ vector (revision 826) @@ -0,0 +1,481 @@ +// Profiling vector implementation -*- C++ -*- + +// Copyright (C) 2009, 2010 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. + +/** @file profile/vector + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_VECTOR +#define _GLIBCXX_PROFILE_VECTOR 1 + +#include +#include +#include +#include + +namespace std +{ +namespace __profile +{ + template > + class vector + : public _GLIBCXX_STD_PR::vector<_Tp, _Allocator> + { + typedef _GLIBCXX_STD_PR::vector<_Tp, _Allocator> _Base; + + public: + typedef typename _Base::reference reference; + typedef typename _Base::const_reference const_reference; + + typedef __iterator_tracker + iterator; + typedef __iterator_tracker + const_iterator; + + typedef typename _Base::size_type size_type; + typedef typename _Base::difference_type difference_type; + + typedef _Tp value_type; + typedef _Allocator allocator_type; + typedef typename _Base::pointer pointer; + typedef typename _Base::const_pointer const_pointer; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + + // 23.2.4.1 construct/copy/destroy: + explicit vector(const _Allocator& __a = _Allocator()) + : _Base(__a) + { + __profcxx_vector_construct(this, this->capacity()); + __profcxx_vector_construct2(this); + } + + explicit vector(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) + { + __profcxx_vector_construct(this, this->capacity()); + __profcxx_vector_construct2(this); + } + + template + vector(_InputIterator __first, _InputIterator __last, + const _Allocator& __a = _Allocator()) + : _Base(__first, __last, __a) + { + __profcxx_vector_construct(this, this->capacity()); + __profcxx_vector_construct2(this); + } + + vector(const vector& __x) + : _Base(__x) + { + __profcxx_vector_construct(this, this->capacity()); + __profcxx_vector_construct2(this); + } + + /// Construction from a release-mode vector + vector(const _Base& __x) + : _Base(__x) + { + __profcxx_vector_construct(this, this->capacity()); + __profcxx_vector_construct2(this); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + vector(vector&& __x) + : _Base(std::forward(__x)) + { + __profcxx_vector_construct(this, this->capacity()); + __profcxx_vector_construct2(this); + } + + vector(initializer_list __l, + const allocator_type& __a = allocator_type()) + : _Base(__l, __a) { } +#endif + + ~vector() { + __profcxx_vector_destruct(this, this->capacity(), this->size()); + __profcxx_vector_destruct2(this); + } + + vector& + operator=(const vector& __x) + { + static_cast<_Base&>(*this) = __x; + return *this; + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + vector& + operator=(vector&& __x) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } + + vector& + operator=(initializer_list __l) + { + static_cast<_Base&>(*this) = __l; + return *this; + } +#endif + + using _Base::assign; + using _Base::get_allocator; + + + // iterators: + iterator + begin() + { return iterator(_Base::begin(), this); } + + const_iterator + begin() const + { return const_iterator(_Base::begin(), this); } + + iterator + end() + { return iterator(_Base::end(), this); } + + const_iterator + end() const + { return const_iterator(_Base::end(), this); } + + reverse_iterator + rbegin() + { return reverse_iterator(end()); } + + const_reverse_iterator + rbegin() const + { return const_reverse_iterator(end()); } + + reverse_iterator + rend() + { return reverse_iterator(begin()); } + + const_reverse_iterator + rend() const + { return const_reverse_iterator(begin()); } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + const_iterator + cbegin() const + { return const_iterator(_Base::begin(), this); } + + const_iterator + cend() const + { return const_iterator(_Base::end(), this); } + + const_reverse_iterator + crbegin() const + { return const_reverse_iterator(end()); } + + const_reverse_iterator + crend() const + { return const_reverse_iterator(begin()); } +#endif + + // 23.2.4.2 capacity: + using _Base::size; + using _Base::max_size; + + void + resize(size_type __sz, _Tp __c = _Tp()) + { + __profcxx_vector_invalid_operator(this); + _M_profile_resize(this, this->capacity(), __sz); + _Base::resize(__sz, __c); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + using _Base::shrink_to_fit; +#endif + + using _Base::empty; + + // element access: + reference + operator[](size_type __n) + { + __profcxx_vector_invalid_operator(this); + return _M_base()[__n]; + } + const_reference + operator[](size_type __n) const + { + __profcxx_vector_invalid_operator(this); + return _M_base()[__n]; + } + + using _Base::at; + + reference + front() + { + return _Base::front(); + } + + const_reference + front() const + { + return _Base::front(); + } + + reference + back() + { + return _Base::back(); + } + + const_reference + back() const + { + return _Base::back(); + } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 464. Suggestion for new member functions in standard containers. + using _Base::data; + + // 23.2.4.3 modifiers: + void + push_back(const _Tp& __x) + { + size_type __old_size = this->capacity(); + _Base::push_back(__x); + _M_profile_resize(this, __old_size, this->capacity()); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + push_back(_Tp&& __x) + { + size_type __old_size = this->capacity(); + _Base::push_back(__x); + _M_profile_resize(this, __old_size, this->capacity()); + } + +#endif + + iterator + insert(iterator __position, const _Tp& __x) + { + __profcxx_vector_insert(this, __position.base() - _Base::begin(), + this->size()); + size_type __old_size = this->capacity(); + typename _Base::iterator __res = _Base::insert(__position.base(), __x); + _M_profile_resize(this, __old_size, this->capacity()); + return iterator(__res, this); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(iterator __position, _Tp&& __x) + { + __profcxx_vector_insert(this, __position.base() - _Base::begin(), + this->size()); + size_type __old_size = this->capacity(); + typename _Base::iterator __res = _Base::insert(__position.base(), __x); + _M_profile_resize(this, __old_size, this->capacity()); + return iterator(__res, this); + } + + void + insert(iterator __position, initializer_list __l) + { this->insert(__position, __l.begin(), __l.end()); } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + swap(vector&& __x) + { + _Base::swap(__x); + } +#endif + + void + swap(vector& __x) + { + _Base::swap(__x); + } + + void + insert(iterator __position, size_type __n, const _Tp& __x) + { + __profcxx_vector_insert(this, __position.base() - _Base::begin(), + this->size()); + size_type __old_size = this->capacity(); + _Base::insert(__position, __n, __x); + _M_profile_resize(this, __old_size, this->capacity()); + } + + template + void + insert(iterator __position, + _InputIterator __first, _InputIterator __last) + { + __profcxx_vector_insert(this, __position.base()-_Base::begin(), + this->size()); + size_type __old_size = this->capacity(); + _Base::insert(__position, __first, __last); + _M_profile_resize(this, __old_size, this->capacity()); + } + + + iterator + erase(iterator __position) + { + typename _Base::iterator __res = _Base::erase(__position.base()); + return iterator(__res, this); + } + + iterator + erase(iterator __first, iterator __last) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 151. can't currently clear() empty container + typename _Base::iterator __res = _Base::erase(__first.base(), + __last.base()); + return iterator(__res, this); + } + + void + clear() + { + __profcxx_vector_destruct(this, this->capacity(), this->size()); + __profcxx_vector_destruct2(this); + _Base::clear(); + } + + inline void _M_profile_find() const + { + __profcxx_vector_find(this, size()); + } + + inline void _M_profile_iterate(int __rewind = 0) const + { + __profcxx_vector_iterate(this); + } + + private: + void _M_profile_resize(void* obj, size_type __old_size, + size_type __new_size) + { + if (__old_size < __new_size) { + __profcxx_vector_resize(this, this->size(), __new_size); + __profcxx_vector_resize2(this, this->size(), __new_size); + } + } + }; + + template + inline bool + operator==(const vector<_Tp, _Alloc>& __lhs, + const vector<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() == __rhs._M_base(); } + + template + inline bool + operator!=(const vector<_Tp, _Alloc>& __lhs, + const vector<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() != __rhs._M_base(); } + + template + inline bool + operator<(const vector<_Tp, _Alloc>& __lhs, + const vector<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() < __rhs._M_base(); } + + template + inline bool + operator<=(const vector<_Tp, _Alloc>& __lhs, + const vector<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() <= __rhs._M_base(); } + + template + inline bool + operator>=(const vector<_Tp, _Alloc>& __lhs, + const vector<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() >= __rhs._M_base(); } + + template + inline bool + operator>(const vector<_Tp, _Alloc>& __lhs, + const vector<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() > __rhs._M_base(); } + + template + inline void + swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs) + { __lhs.swap(__rhs); } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + inline void + swap(vector<_Tp, _Alloc>&& __lhs, vector<_Tp, _Alloc>& __rhs) + { __lhs.swap(__rhs); } + + template + inline void + swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>&& __rhs) + { __lhs.swap(__rhs); } +#endif + +} // namespace __profile + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // DR 1182. + /// std::hash specialization for vector. + template + struct hash<__profile::vector> + : public std::unary_function<__profile::vector, size_t> + { + size_t + operator()(const __profile::vector& __b) const + { return std::hash<_GLIBCXX_STD_D::vector>() + (__b._M_base()); } + }; +#endif + +} // namespace std + +#endif Index: deque =================================================================== --- deque (nonexistent) +++ deque (revision 826) @@ -0,0 +1,425 @@ +// Profiling deque implementation -*- C++ -*- + +// Copyright (C) 2009, 2010 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 3, 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file profile/deque + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_DEQUE +#define _GLIBCXX_PROFILE_DEQUE 1 + +#include + +namespace std +{ +namespace __profile +{ + /// Class std::deque wrapper with performance instrumentation. + template > + class deque + : public _GLIBCXX_STD_D::deque<_Tp, _Allocator> + { + typedef _GLIBCXX_STD_D::deque<_Tp, _Allocator> _Base; + + public: + typedef typename _Base::reference reference; + typedef typename _Base::const_reference const_reference; + + typedef typename _Base::iterator iterator; + typedef typename _Base::const_iterator const_iterator; + typedef typename _Base::reverse_iterator reverse_iterator; + typedef typename _Base::const_reverse_iterator const_reverse_iterator; + + typedef typename _Base::size_type size_type; + typedef typename _Base::difference_type difference_type; + + typedef _Tp value_type; + typedef _Allocator allocator_type; + typedef typename _Base::pointer pointer; + typedef typename _Base::const_pointer const_pointer; + + // 23.2.1.1 construct/copy/destroy: + explicit deque(const _Allocator& __a = _Allocator()) + : _Base(__a) { } + + explicit deque(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) { } + + template + deque(_InputIterator __first, _InputIterator __last, + const _Allocator& __a = _Allocator()) + : _Base(__first, __last, __a) + { } + + deque(const deque& __x) + : _Base(__x) { } + + deque(const _Base& __x) + : _Base(__x) { } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + deque(deque&& __x) + : _Base(std::forward(__x)) + { } + + deque(initializer_list __l, + const allocator_type& __a = allocator_type()) + : _Base(__l, __a) { } +#endif + + ~deque() { } + + deque& + operator=(const deque& __x) + { + *static_cast<_Base*>(this) = __x; + return *this; + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + deque& + operator=(deque&& __x) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } + + deque& + operator=(initializer_list __l) + { + *static_cast<_Base*>(this) = __l; + return *this; + } +#endif + + template + void + assign(_InputIterator __first, _InputIterator __last) + { + _Base::assign(__first, __last); + } + + void + assign(size_type __n, const _Tp& __t) + { + _Base::assign(__n, __t); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + assign(initializer_list __l) + { + _Base::assign(__l); + } +#endif + + using _Base::get_allocator; + + // iterators: + iterator + begin() + { return iterator(_Base::begin()); } + + const_iterator + begin() const + { return const_iterator(_Base::begin()); } + + iterator + end() + { return iterator(_Base::end()); } + + const_iterator + end() const + { return const_iterator(_Base::end()); } + + reverse_iterator + rbegin() + { return reverse_iterator(end()); } + + const_reverse_iterator + rbegin() const + { return const_reverse_iterator(end()); } + + reverse_iterator + rend() + { return reverse_iterator(begin()); } + + const_reverse_iterator + rend() const + { return const_reverse_iterator(begin()); } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + const_iterator + cbegin() const + { return const_iterator(_Base::begin()); } + + const_iterator + cend() const + { return const_iterator(_Base::end()); } + + const_reverse_iterator + crbegin() const + { return const_reverse_iterator(end()); } + + const_reverse_iterator + crend() const + { return const_reverse_iterator(begin()); } +#endif + + // 23.2.1.2 capacity: + using _Base::size; + using _Base::max_size; + + void + resize(size_type __sz, _Tp __c = _Tp()) + { + _Base::resize(__sz, __c); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + using _Base::shrink_to_fit; +#endif + + using _Base::empty; + + // element access: + reference + operator[](size_type __n) + { + return _M_base()[__n]; + } + + const_reference + operator[](size_type __n) const + { + return _M_base()[__n]; + } + + using _Base::at; + + reference + front() + { + return _Base::front(); + } + + const_reference + front() const + { + return _Base::front(); + } + + reference + back() + { + return _Base::back(); + } + + const_reference + back() const + { + return _Base::back(); + } + + // 23.2.1.3 modifiers: + void + push_front(const _Tp& __x) + { + _Base::push_front(__x); + } + + void + push_back(const _Tp& __x) + { + _Base::push_back(__x); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + push_front(_Tp&& __x) + { emplace_front(std::move(__x)); } + + void + push_back(_Tp&& __x) + { emplace_back(std::move(__x)); } + + template + void + emplace_front(_Args&&... __args) + { + _Base::emplace_front(std::forward<_Args>(__args)...); + } + + template + void + emplace_back(_Args&&... __args) + { + _Base::emplace_back(std::forward<_Args>(__args)...); + } + + template + iterator + emplace(iterator __position, _Args&&... __args) + { + typename _Base::iterator __res = _Base::emplace(__position, + std::forward<_Args>(__args)...); + return iterator(__res); + } +#endif + + iterator + insert(iterator __position, const _Tp& __x) + { + typename _Base::iterator __res = _Base::insert(__position, __x); + return iterator(__res); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(iterator __position, _Tp&& __x) + { return emplace(__position, std::move(__x)); } + + void + insert(iterator __p, initializer_list __l) + { + _Base::insert(__p, __l); + } +#endif + + void + insert(iterator __position, size_type __n, const _Tp& __x) + { + _Base::insert(__position, __n, __x); + } + + template + void + insert(iterator __position, + _InputIterator __first, _InputIterator __last) + { + _Base::insert(__position, __first, __last); + } + + void + pop_front() + { + _Base::pop_front(); + } + + void + pop_back() + { + _Base::pop_back(); + } + + iterator + erase(iterator __position) + { + if (__position == begin() || __position == end()-1) + { + return iterator(_Base::erase(__position)); + } + else + { + typename _Base::iterator __res = _Base::erase(__position); + return iterator(__res); + } + } + + iterator + erase(iterator __first, iterator __last) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 151. can't currently clear() empty container + return iterator(_Base::erase(__first, __last)); + } + + void + swap(deque& __x) + { + _Base::swap(__x); + } + + void + clear() + { + _Base::clear(); + } + + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + }; + + template + inline bool + operator==(const deque<_Tp, _Alloc>& __lhs, + const deque<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() == __rhs._M_base(); } + + template + inline bool + operator!=(const deque<_Tp, _Alloc>& __lhs, + const deque<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() != __rhs._M_base(); } + + template + inline bool + operator<(const deque<_Tp, _Alloc>& __lhs, + const deque<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() < __rhs._M_base(); } + + template + inline bool + operator<=(const deque<_Tp, _Alloc>& __lhs, + const deque<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() <= __rhs._M_base(); } + + template + inline bool + operator>=(const deque<_Tp, _Alloc>& __lhs, + const deque<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() >= __rhs._M_base(); } + + template + inline bool + operator>(const deque<_Tp, _Alloc>& __lhs, + const deque<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() > __rhs._M_base(); } + + template + inline void + swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs) + { __lhs.swap(__rhs); } + +} // namespace __profile +} // namespace std + +#endif Index: map.h =================================================================== --- map.h (nonexistent) +++ map.h (revision 826) @@ -0,0 +1,502 @@ +// Profiling map implementation -*- C++ -*- + +// Copyright (C) 2009, 2010 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. + +/** @file profile/map.h + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_MAP_H +#define _GLIBCXX_PROFILE_MAP_H 1 + +#include +#include + +namespace std +{ +namespace __profile +{ + /// Class std::map wrapper with performance instrumentation. + template, + typename _Allocator = std::allocator > > + class map + : public _GLIBCXX_STD_D::map<_Key, _Tp, _Compare, _Allocator> + { + typedef _GLIBCXX_STD_D::map<_Key, _Tp, _Compare, _Allocator> _Base; + + public: + // types: + typedef _Key key_type; + typedef _Tp mapped_type; + typedef std::pair value_type; + typedef _Compare key_compare; + typedef _Allocator allocator_type; + typedef typename _Base::reference reference; + typedef typename _Base::const_reference const_reference; + + typedef typename _Base::iterator iterator; + typedef typename _Base::const_iterator const_iterator; + typedef typename _Base::size_type size_type; + typedef typename _Base::difference_type difference_type; + typedef typename _Base::pointer pointer; + typedef typename _Base::const_pointer const_pointer; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + using _Base::value_compare; + + // 23.3.1.1 construct/copy/destroy: + explicit map(const _Compare& __comp = _Compare(), + const _Allocator& __a = _Allocator()) + : _Base(__comp, __a) { + __profcxx_map_to_unordered_map_construct(this); + } + + template + map(_InputIterator __first, _InputIterator __last, + const _Compare& __comp = _Compare(), + const _Allocator& __a = _Allocator()) + : _Base(__first, __last, __comp, __a) { + __profcxx_map_to_unordered_map_construct(this); + } + + map(const map& __x) + : _Base(__x) { + __profcxx_map_to_unordered_map_construct(this); + } + + map(const _Base& __x) + : _Base(__x) { + __profcxx_map_to_unordered_map_construct(this); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + map(map&& __x) + : _Base(std::forward(__x)) + { } + + map(initializer_list __l, + const _Compare& __c = _Compare(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __c, __a) { } +#endif + + ~map() { + __profcxx_map_to_unordered_map_destruct(this); + } + + map& + operator=(const map& __x) + { + *static_cast<_Base*>(this) = __x; + return *this; + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + map& + operator=(map&& __x) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } + + map& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l); + return *this; + } +#endif + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 133. map missing get_allocator() + using _Base::get_allocator; + + // iterators: + iterator + begin() + { return _Base::begin(); } + + const_iterator + begin() const + { return _Base::begin(); } + + iterator + end() + { return _Base::end(); } + + const_iterator + end() const + { return _Base::end(); } + + reverse_iterator + rbegin() + { + __profcxx_map_to_unordered_map_invalidate(this); + return reverse_iterator(end()); + } + + const_reverse_iterator + rbegin() const + { + __profcxx_map_to_unordered_map_invalidate(this); + return const_reverse_iterator(end()); + } + + reverse_iterator + rend() + { + __profcxx_map_to_unordered_map_invalidate(this); + return reverse_iterator(begin()); + } + + const_reverse_iterator + rend() const + { + __profcxx_map_to_unordered_map_invalidate(this); + return const_reverse_iterator(begin()); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + const_iterator + cbegin() const + { return const_iterator(_Base::begin()); } + + const_iterator + cend() const + { return const_iterator(_Base::end()); } + + const_reverse_iterator + crbegin() const + { + __profcxx_map_to_unordered_map_invalidate(this); + return const_reverse_iterator(end()); + } + + const_reverse_iterator + crend() const + { + __profcxx_map_to_unordered_map_invalidate(this); + return const_reverse_iterator(begin()); + } +#endif + + // capacity: + using _Base::empty; + using _Base::size; + using _Base::max_size; + + // 23.3.1.2 element access: + mapped_type& + operator[](const key_type& __k) + { + __profcxx_map_to_unordered_map_find(this, size()); + return _Base::operator[](__k); + } + + mapped_type& + at(const key_type& __k) + { + __profcxx_map_to_unordered_map_find(this, size()); + return _Base::at(__k); + } + + const mapped_type& + at(const key_type& __k) const + { + __profcxx_map_to_unordered_map_find(this, size()); + return _Base::at(__k); + } + + // modifiers: + std::pair + insert(const value_type& __x) + { + __profcxx_map_to_unordered_map_insert(this, size(), 1); + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, bool> __res = _Base::insert(__x); + return std::pair(iterator(__res.first), + __res.second); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + insert(std::initializer_list __list) + { + size_type size_before = size(); + _Base::insert(__list); + __profcxx_map_to_unordered_map_insert(this, size_before, + size() - size_before); + } +#endif + + iterator + insert(iterator __position, const value_type& __x) + { + size_type size_before = size(); + return iterator(_Base::insert(__position, __x)); + __profcxx_map_to_unordered_map_insert(this, size_before, + size() - size_before); + } + + template + void + insert(_InputIterator __first, _InputIterator __last) + { + size_type size_before = size(); + _Base::insert(__first, __last); + __profcxx_map_to_unordered_map_insert(this, size_before, + size() - size_before); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + erase(iterator __position) + { + iterator __i = _Base::erase(__position); + __profcxx_map_to_unordered_map_erase(this, size(), 1); + return __i; + } +#else + void + erase(iterator __position) + { + _Base::erase(__position); + __profcxx_map_to_unordered_map_erase(this, size(), 1); + } +#endif + + size_type + erase(const key_type& __x) + { + iterator __victim = find(__x); + if (__victim == end()) + return 0; + else + { + _Base::erase(__victim); + return 1; + } + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + erase(iterator __first, iterator __last) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 151. can't currently clear() empty container + while (__first != __last) + this->erase(__first++); + return __last; + } +#else + void + erase(iterator __first, iterator __last) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 151. can't currently clear() empty container + while (__first != __last) + this->erase(__first++); + } +#endif + + void + + swap(map& __x) + { + _Base::swap(__x); + } + + void + clear() + { this->erase(begin(), end()); } + + // observers: + using _Base::key_comp; + using _Base::value_comp; + + // 23.3.1.3 map operations: + iterator + find(const key_type& __x) + { + __profcxx_map_to_unordered_map_find(this, size()); + return iterator(_Base::find(__x)); + } + + const_iterator + find(const key_type& __x) const + { + __profcxx_map_to_unordered_map_find(this, size()); + return const_iterator(_Base::find(__x)); + } + + size_type + count(const key_type& __x) const + { + __profcxx_map_to_unordered_map_find(this, size()); + return _Base::count(__x); + } + + iterator + lower_bound(const key_type& __x) + { + __profcxx_map_to_unordered_map_invalidate(this); + return iterator(_Base::lower_bound(__x)); + } + + const_iterator + lower_bound(const key_type& __x) const + { + __profcxx_map_to_unordered_map_invalidate(this); + return const_iterator(_Base::lower_bound(__x)); + } + + iterator + upper_bound(const key_type& __x) + { + __profcxx_map_to_unordered_map_invalidate(this); + return iterator(_Base::upper_bound(__x)); + } + + const_iterator + upper_bound(const key_type& __x) const + { + __profcxx_map_to_unordered_map_invalidate(this); + return const_iterator(_Base::upper_bound(__x)); + } + + std::pair + equal_range(const key_type& __x) + { + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, _Base_iterator> __res = + _Base::equal_range(__x); + return std::make_pair(iterator(__res.first), + iterator(__res.second)); + } + + std::pair + equal_range(const key_type& __x) const + { + __profcxx_map_to_unordered_map_find(this, size()); + typedef typename _Base::const_iterator _Base_const_iterator; + std::pair<_Base_const_iterator, _Base_const_iterator> __res = + _Base::equal_range(__x); + return std::make_pair(const_iterator(__res.first), + const_iterator(__res.second)); + } + + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + + }; + + template + inline bool + operator==(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, + const map<_Key, _Tp, _Compare, _Allocator>& __rhs) + { + __profcxx_map_to_unordered_map_invalidate(&__lhs); + __profcxx_map_to_unordered_map_invalidate(&__rhs); + return __lhs._M_base() == __rhs._M_base(); + } + + template + inline bool + operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, + const map<_Key, _Tp, _Compare, _Allocator>& __rhs) + { + __profcxx_map_to_unordered_map_invalidate(&__lhs); + __profcxx_map_to_unordered_map_invalidate(&__rhs); + return __lhs._M_base() != __rhs._M_base(); + } + + template + inline bool + operator<(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, + const map<_Key, _Tp, _Compare, _Allocator>& __rhs) + { + __profcxx_map_to_unordered_map_invalidate(&__lhs); + __profcxx_map_to_unordered_map_invalidate(&__rhs); + return __lhs._M_base() < __rhs._M_base(); + } + + template + inline bool + operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, + const map<_Key, _Tp, _Compare, _Allocator>& __rhs) + { + __profcxx_map_to_unordered_map_invalidate(&__lhs); + __profcxx_map_to_unordered_map_invalidate(&__rhs); + return __lhs._M_base() <= __rhs._M_base(); + } + + template + inline bool + operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, + const map<_Key, _Tp, _Compare, _Allocator>& __rhs) + { + __profcxx_map_to_unordered_map_invalidate(&__lhs); + __profcxx_map_to_unordered_map_invalidate(&__rhs); + return __lhs._M_base() >= __rhs._M_base(); + } + + template + inline bool + operator>(const map<_Key, _Tp, _Compare, _Allocator>& __lhs, + const map<_Key, _Tp, _Compare, _Allocator>& __rhs) + { + __profcxx_map_to_unordered_map_invalidate(&__lhs); + __profcxx_map_to_unordered_map_invalidate(&__rhs); + return __lhs._M_base() > __rhs._M_base(); + } + + template + inline void + swap(map<_Key, _Tp, _Compare, _Allocator>& __lhs, + map<_Key, _Tp, _Compare, _Allocator>& __rhs) + { __lhs.swap(__rhs); } + +} // namespace __profile +} // namespace std + +#endif
map.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: unordered_map =================================================================== --- unordered_map (nonexistent) +++ unordered_map (revision 826) @@ -0,0 +1,518 @@ +// Profiling unordered_map/unordered_multimap implementation -*- C++ -*- + +// Copyright (C) 2009, 2010 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. + +/** @file profile/unordered_map + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_UNORDERED_MAP +#define _GLIBCXX_PROFILE_UNORDERED_MAP 1 + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +# include +#else +# include + +#include + +#define _GLIBCXX_BASE unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc> +#define _GLIBCXX_STD_BASE _GLIBCXX_STD_PR::_GLIBCXX_BASE + +namespace std +{ +namespace __profile +{ + /// Class std::unordered_map wrapper with performance instrumentation. + template, + typename _Pred = std::equal_to<_Key>, + typename _Alloc = std::allocator<_Key> > + class unordered_map + : public _GLIBCXX_STD_BASE + { + typedef typename _GLIBCXX_STD_BASE _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + typedef typename _Base::key_type key_type; + typedef typename _Base::value_type value_type; + typedef typename _Base::difference_type difference_type; + typedef typename _Base::reference reference; + typedef typename _Base::const_reference const_reference; + typedef typename _Base::mapped_type mapped_type; + + typedef typename _Base::iterator iterator; + typedef typename _Base::const_iterator const_iterator; + + explicit + unordered_map(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __eql, __a) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + __profcxx_hashtable_construct2(this); + } + + template + unordered_map(_InputIterator __f, _InputIterator __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __eql, __a) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + __profcxx_hashtable_construct2(this); + } + + unordered_map(const _Base& __x) + : _Base(__x) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + __profcxx_hashtable_construct2(this); + } + + unordered_map(unordered_map&& __x) + : _Base(std::forward<_Base>(__x)) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + __profcxx_hashtable_construct2(this); + } + + unordered_map(initializer_list __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __n, __hf, __eql, __a) { } + + unordered_map& + operator=(const unordered_map& __x) + { + *static_cast<_Base*>(this) = __x; + return *this; + } + + unordered_map& + operator=(unordered_map&& __x) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } + + unordered_map& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l); + return *this; + } + + ~unordered_map() + { + __profcxx_hashtable_destruct(this, _Base::bucket_count(), + _Base::size()); + _M_profile_destruct(); + } + + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + + + void + clear() + { + __profcxx_hashtable_destruct(this, _Base::bucket_count(), + _Base::size()); + _M_profile_destruct(); + _Base::clear(); + } + + void + insert(std::initializer_list __l) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__l); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + std::pair + insert(const value_type& __obj) + { + size_type __old_size = _Base::bucket_count(); + std::pair __res = _Base::insert(__obj); + _M_profile_resize(__old_size, _Base::bucket_count()); + return __res; + } + + iterator + insert(const_iterator __iter, const value_type& __v) + { + size_type __old_size = _Base::bucket_count(); + iterator __res = _Base::insert(__iter, __v); + _M_profile_resize(__old_size, _Base::bucket_count()); + return __res; + } + + template + void + insert(_InputIter __first, _InputIter __last) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__first, __last); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + void + insert(const value_type* __first, const value_type* __last) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__first, __last); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + // operator [] + mapped_type& + operator[](const _Key& _k) + { + size_type __old_size = _Base::bucket_count(); + mapped_type& __res = _M_base()[_k]; + size_type __new_size = _Base::bucket_count(); + _M_profile_resize(__old_size, _Base::bucket_count()); + return __res; + } + + void + swap(unordered_map& __x) + { _Base::swap(__x); } + + void rehash(size_type __n) + { + size_type __old_size = _Base::bucket_count(); + _Base::rehash(__n); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + private: + void + _M_profile_resize(size_type __old_size, size_type __new_size) + { + if (__old_size != __new_size) + __profcxx_hashtable_resize(this, __old_size, __new_size); + } + + void + _M_profile_destruct() + { + size_type __hops = 0, __lc = 0, __chain = 0; + for (iterator __it = _M_base().begin(); __it != _M_base().end(); + ++__it) + { + while (__it._M_cur_node->_M_next) + { + ++__chain; + ++__it; + } + if (__chain) + { + ++__chain; + __lc = __lc > __chain ? __lc : __chain; + __hops += __chain * (__chain - 1) / 2; + __chain = 0; + } + } + __profcxx_hashtable_destruct2(this, __lc, _Base::size(), __hops); + } + }; + + template + inline void + swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + + template + inline bool + operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + { return __x._M_equal(__y); } + + template + inline bool + operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + { return !(__x == __y); } + +#undef _GLIBCXX_BASE +#undef _GLIBCXX_STD_BASE +#define _GLIBCXX_BASE unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> +#define _GLIBCXX_STD_BASE _GLIBCXX_STD_PR::_GLIBCXX_BASE + + /// Class std::unordered_multimap wrapper with performance instrumentation. + template, + typename _Pred = std::equal_to<_Key>, + typename _Alloc = std::allocator<_Key> > + class unordered_multimap + : public _GLIBCXX_STD_BASE + { + typedef typename _GLIBCXX_STD_BASE _Base; + + public: + typedef typename _Base::size_type size_type; + typedef typename _Base::hasher hasher; + typedef typename _Base::key_equal key_equal; + typedef typename _Base::allocator_type allocator_type; + typedef typename _Base::key_type key_type; + typedef typename _Base::value_type value_type; + typedef typename _Base::difference_type difference_type; + typedef typename _Base::reference reference; + typedef typename _Base::const_reference const_reference; + + typedef typename _Base::iterator iterator; + typedef typename _Base::const_iterator const_iterator; + + explicit + unordered_multimap(size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__n, __hf, __eql, __a) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + } + template + unordered_multimap(_InputIterator __f, _InputIterator __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__f, __l, __n, __hf, __eql, __a) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + } + + unordered_multimap(const _Base& __x) + : _Base(__x) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + } + + unordered_multimap(unordered_multimap&& __x) + : _Base(std::forward<_Base>(__x)) + { + __profcxx_hashtable_construct(this, _Base::bucket_count()); + } + + unordered_multimap(initializer_list __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __n, __hf, __eql, __a) { } + + unordered_multimap& + operator=(const unordered_multimap& __x) + { + *static_cast<_Base*>(this) = __x; + return *this; + } + + unordered_multimap& + operator=(unordered_multimap&& __x) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } + + unordered_multimap& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l); + return *this; + } + + ~unordered_multimap() + { + __profcxx_hashtable_destruct(this, _Base::bucket_count(), + _Base::size()); + _M_profile_destruct(); + } + + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + + + void + clear() + { + __profcxx_hashtable_destruct(this, _Base::bucket_count(), + _Base::size()); + _M_profile_destruct(); + _Base::clear(); + } + + void + insert(std::initializer_list __l) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__l); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + iterator + insert(const value_type& __obj) + { + size_type __old_size = _Base::bucket_count(); + iterator __res = _Base::insert(__obj); + _M_profile_resize(__old_size, _Base::bucket_count()); + return __res; + } + + iterator + insert(const_iterator __iter, const value_type& __v) + { + size_type __old_size = _Base::bucket_count(); + iterator __res =_Base::insert(__iter, __v); + _M_profile_resize(__old_size, _Base::bucket_count()); + return __res; + } + + template + void + insert(_InputIter __first, _InputIter __last) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__first, __last); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + void + insert(const value_type* __first, const value_type* __last) + { + size_type __old_size = _Base::bucket_count(); + _Base::insert(__first, __last); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + void + swap(unordered_multimap& __x) + { _Base::swap(__x); } + + void rehash(size_type __n) + { + size_type __old_size = _Base::bucket_count(); + _Base::rehash(__n); + _M_profile_resize(__old_size, _Base::bucket_count()); + } + + private: + void + _M_profile_resize(size_type __old_size, size_type __new_size) + { + if (__old_size != __new_size) + __profcxx_hashtable_resize(this, __old_size, __new_size); + } + + void + _M_profile_destruct() + { + size_type __hops = 0, __lc = 0, __chain = 0; + for (iterator __it = _M_base().begin(); __it != _M_base().end(); + ++__it) + { + while (__it._M_cur_node->_M_next) + { + ++__chain; + ++__it; + } + if (__chain) + { + ++__chain; + __lc = __lc > __chain ? __lc : __chain; + __hops += __chain * (__chain - 1) / 2; + __chain = 0; + } + } + __profcxx_hashtable_destruct2(this, __lc, _Base::size(), __hops); + } + + }; + + template + inline void + swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + + template + inline bool + operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + { return __x._M_equal(__y); } + + template + inline bool + operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + { return !(__x == __y); } + +} // namespace __profile +} // namespace std + +#undef _GLIBCXX_BASE +#undef _GLIBCXX_STD_BASE + +#endif // __GXX_EXPERIMENTAL_CXX0X__ + +#endif Index: bitset =================================================================== --- bitset (nonexistent) +++ bitset (revision 826) @@ -0,0 +1,372 @@ +// Profiling bitset implementation -*- C++ -*- + +// Copyright (C) 2009, 2010 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 3, 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file profile/bitset + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_BITSET +#define _GLIBCXX_PROFILE_BITSET + +#include + +namespace std +{ +namespace __profile +{ + /// Class std::bitset wrapper with performance instrumentation. + template + class bitset + : public _GLIBCXX_STD_D::bitset<_Nb> + { + typedef _GLIBCXX_STD_D::bitset<_Nb> _Base; + + public: + // bit reference: + class reference + : private _Base::reference + { + typedef typename _Base::reference _Base_ref; + + friend class bitset; + reference(); + + reference(const _Base_ref& __base, bitset* __seq) + : _Base_ref(__base) + { } + + public: + reference(const reference& __x) + : _Base_ref(__x) + { } + + reference& + operator=(bool __x) + { + *static_cast<_Base_ref*>(this) = __x; + return *this; + } + + reference& + operator=(const reference& __x) + { + *static_cast<_Base_ref*>(this) = __x; + return *this; + } + + bool + operator~() const + { + return ~(*static_cast(this)); + } + + operator bool() const + { + return *static_cast(this); + } + + reference& + flip() + { + _Base_ref::flip(); + return *this; + } + }; + + // 23.3.5.1 constructors: + bitset() : _Base() { } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + bitset(unsigned long long __val) +#else + bitset(unsigned long __val) +#endif + : _Base(__val) { } + + template + explicit + bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str, + typename std::basic_string<_CharT, _Traits, _Alloc>::size_type + __pos = 0, + typename std::basic_string<_CharT, _Traits, _Alloc>::size_type + __n = (std::basic_string<_CharT, _Traits, _Alloc>::npos)) + : _Base(__str, __pos, __n) { } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 396. what are characters zero and one. + template + bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str, + typename std::basic_string<_CharT, _Traits, _Alloc>::size_type + __pos, + typename std::basic_string<_CharT, _Traits, _Alloc>::size_type + __n, + _CharT __zero, _CharT __one = _CharT('1')) + : _Base(__str, __pos, __n, __zero, __one) { } + + bitset(const _Base& __x) : _Base(__x) { } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + bitset(const char* __str) : _Base(__str) { } +#endif + + // 23.3.5.2 bitset operations: + bitset<_Nb>& + operator&=(const bitset<_Nb>& __rhs) + { + _M_base() &= __rhs; + return *this; + } + + bitset<_Nb>& + operator|=(const bitset<_Nb>& __rhs) + { + _M_base() |= __rhs; + return *this; + } + + bitset<_Nb>& + operator^=(const bitset<_Nb>& __rhs) + { + _M_base() ^= __rhs; + return *this; + } + + bitset<_Nb>& + operator<<=(size_t __pos) + { + _M_base() <<= __pos; + return *this; + } + + bitset<_Nb>& + operator>>=(size_t __pos) + { + _M_base() >>= __pos; + return *this; + } + + bitset<_Nb>& + set() + { + _Base::set(); + return *this; + } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 186. bitset::set() second parameter should be bool + bitset<_Nb>& + set(size_t __pos, bool __val = true) + { + _Base::set(__pos, __val); + return *this; + } + + bitset<_Nb>& + reset() + { + _Base::reset(); + return *this; + } + + bitset<_Nb>& + reset(size_t __pos) + { + _Base::reset(__pos); + return *this; + } + + bitset<_Nb> operator~() const { return bitset(~_M_base()); } + + bitset<_Nb>& + flip() + { + _Base::flip(); + return *this; + } + + bitset<_Nb>& + flip(size_t __pos) + { + _Base::flip(__pos); + return *this; + } + + // element access: + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 11. Bitset minor problems + reference + operator[](size_t __pos) + { + return reference(_M_base()[__pos], this); + } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 11. Bitset minor problems + bool + operator[](size_t __pos) const + { + return _M_base()[__pos]; + } + + using _Base::to_ulong; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + using _Base::to_ullong; +#endif + + template + std::basic_string<_CharT, _Traits, _Alloc> + to_string() const + { return _M_base().template to_string<_CharT, _Traits, _Alloc>(); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 396. what are characters zero and one. + template + std::basic_string<_CharT, _Traits, _Alloc> + to_string(_CharT __zero, _CharT __one = _CharT('1')) const + { + return _M_base().template + to_string<_CharT, _Traits, _Alloc>(__zero, __one); + } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 434. bitset::to_string() hard to use. + template + std::basic_string<_CharT, _Traits, std::allocator<_CharT> > + to_string() const + { return to_string<_CharT, _Traits, std::allocator<_CharT> >(); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 853. to_string needs updating with zero and one. + template + std::basic_string<_CharT, _Traits, std::allocator<_CharT> > + to_string(_CharT __zero, _CharT __one = _CharT('1')) const + { return to_string<_CharT, _Traits, + std::allocator<_CharT> >(__zero, __one); } + + template + std::basic_string<_CharT, std::char_traits<_CharT>, + std::allocator<_CharT> > + to_string() const + { + return to_string<_CharT, std::char_traits<_CharT>, + std::allocator<_CharT> >(); + } + + template + std::basic_string<_CharT, std::char_traits<_CharT>, + std::allocator<_CharT> > + to_string(_CharT __zero, _CharT __one = _CharT('1')) const + { + return to_string<_CharT, std::char_traits<_CharT>, + std::allocator<_CharT> >(__zero, __one); + } + + std::basic_string, std::allocator > + to_string() const + { + return to_string,std::allocator >(); + } + + std::basic_string, std::allocator > + to_string(char __zero, char __one = '1') const + { + return to_string, + std::allocator >(__zero, __one); + } + + using _Base::count; + using _Base::size; + + bool + operator==(const bitset<_Nb>& __rhs) const + { return _M_base() == __rhs; } + + bool + operator!=(const bitset<_Nb>& __rhs) const + { return _M_base() != __rhs; } + + using _Base::test; + using _Base::all; + using _Base::any; + using _Base::none; + + bitset<_Nb> + operator<<(size_t __pos) const + { return bitset<_Nb>(_M_base() << __pos); } + + bitset<_Nb> + operator>>(size_t __pos) const + { return bitset<_Nb>(_M_base() >> __pos); } + + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + }; + + template + bitset<_Nb> + operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) + { return bitset<_Nb>(__x) &= __y; } + + template + bitset<_Nb> + operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) + { return bitset<_Nb>(__x) |= __y; } + + template + bitset<_Nb> + operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) + { return bitset<_Nb>(__x) ^= __y; } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x) + { return __is >> __x._M_base(); } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const bitset<_Nb>& __x) + { return __os << __x._M_base(); } +} // namespace __profile + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // DR 1182. + /// std::hash specialization for bitset. + template + struct hash<__profile::bitset<_Nb>> + : public std::unary_function<__profile::bitset<_Nb>, size_t> + { + size_t + operator()(const __profile::bitset<_Nb>& __b) const + { return std::hash<_GLIBCXX_STD_D::bitset<_Nb>>()(__b._M_base()); } + }; +#endif + +} // namespace std + +#endif Index: iterator_tracker.h =================================================================== --- iterator_tracker.h (nonexistent) +++ iterator_tracker.h (revision 826) @@ -0,0 +1,301 @@ +// Profiling iterator implementation -*- C++ -*- + +// Copyright (C) 2009, 2010 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 3, 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file profile/iterator_tracker.h + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_ITERATOR_TRACKER +#define _GLIBCXX_PROFILE_ITERATOR_TRACKER 1 + +#include + +namespace std +{ +namespace __profile +{ + +template +class __iterator_tracker +{ + typedef __iterator_tracker _Self; + // The underlying iterator + _Iterator _M_current; + // The underlying data structure + const _Sequence* _M_ds; + typedef std::iterator_traits<_Iterator> _Traits; + + public: + typedef _Iterator _Base_iterator; + typedef typename _Traits::iterator_category iterator_category; + typedef typename _Traits::value_type value_type; + typedef typename _Traits::difference_type difference_type; + typedef typename _Traits::reference reference; + typedef typename _Traits::pointer pointer; + + __iterator_tracker() : _M_current(), _M_ds(0) { } + __iterator_tracker(const _Iterator& __i, const _Sequence* seq) + : _M_current(__i), _M_ds(seq) { } + __iterator_tracker(const __iterator_tracker& __x) + : _M_current(__x._M_current), _M_ds(__x._M_ds) { } + template + __iterator_tracker(const __iterator_tracker<_MutableIterator, typename __gnu_cxx::__enable_if<(std::__are_same<_MutableIterator, typename _Sequence::iterator::_Base_iterator>::__value), _Sequence>::__type>& __x) + : _M_current(__x.base()), _M_ds(__x._M_get_sequence()) { } + + _Iterator + base() const { return _M_current; } + /** + * @brief Conversion to underlying non-debug iterator to allow + * better interaction with non-profile containers. + */ + operator _Iterator() const { return _M_current; } + + pointer + operator->() const { return &*_M_current; } + + __iterator_tracker& + operator++() + { + _M_ds->_M_profile_iterate(); + ++_M_current; + return *this; + } + + __iterator_tracker& + operator++(int) + { + _M_ds->_M_profile_iterate(); + __iterator_tracker __tmp(*this); + ++_M_current; + return __tmp; + } + + __iterator_tracker& + operator--() + { + _M_ds->_M_profile_iterate(1); + --_M_current; + return *this; + } + + __iterator_tracker& + operator--(int) + { + _M_ds->_M_profile_iterate(1); + __iterator_tracker __tmp(*this); + --_M_current; + return __tmp; + } + + __iterator_tracker& + operator=(const __iterator_tracker& __x) + { + _M_current = __x._M_current; + return *this; + } + + reference + operator*() const + { + return *_M_current; + } + + // ------ Random access iterator requirements ------ + reference + operator[](const difference_type& __n) const + { + return _M_current[__n]; + } + + __iterator_tracker& + operator+=(const difference_type& __n) + { + _M_current += __n; + return *this; + } + + __iterator_tracker + operator+(const difference_type& __n) const + { + __iterator_tracker __tmp(*this); + __tmp += __n; + return __tmp; + } + + __iterator_tracker& + operator-=(const difference_type& __n) + { + _M_current += -__n; + return *this; + } + + __iterator_tracker + operator-(const difference_type& __n) const + { + __iterator_tracker __tmp(*this); + __tmp -= __n; + return __tmp; + } + + void + _M_find() + { + _M_ds->_M_profile_find(); + } + + const _Sequence* + _M_get_sequence() const + { + return static_cast(_M_ds); + } +}; + +template +inline bool +operator==(const __iterator_tracker<_IteratorL, _Sequence>& __lhs, + const __iterator_tracker<_IteratorR, _Sequence>& __rhs) +{ + return __lhs.base() == __rhs.base(); +} + +template +inline bool +operator==(const __iterator_tracker<_Iterator, _Sequence>& __lhs, + const __iterator_tracker<_Iterator, _Sequence>& __rhs) +{ + return __lhs.base() == __rhs.base(); +} + +template +inline bool +operator!=(const __iterator_tracker<_IteratorL, _Sequence>& __lhs, + const __iterator_tracker<_IteratorR, _Sequence>& __rhs) +{ + return __lhs.base() != __rhs.base(); +} + +template +inline bool +operator!=(const __iterator_tracker<_Iterator, _Sequence>& __lhs, + const __iterator_tracker<_Iterator, _Sequence>& __rhs) +{ + return __lhs.base() != __rhs.base(); +} + +template +inline bool +operator<(const __iterator_tracker<_IteratorL, _Sequence>& __lhs, + const __iterator_tracker<_IteratorR, _Sequence>& __rhs) +{ + return __lhs.base() < __rhs.base(); +} + +template +inline bool +operator<(const __iterator_tracker<_Iterator, _Sequence>& __lhs, + const __iterator_tracker<_Iterator, _Sequence>& __rhs) +{ + return __lhs.base() < __rhs.base(); +} + +template +inline bool +operator<=(const __iterator_tracker<_IteratorL, _Sequence>& __lhs, + const __iterator_tracker<_IteratorR, _Sequence>& __rhs) +{ + return __lhs.base() <= __rhs.base(); +} + +template +inline bool +operator<=(const __iterator_tracker<_Iterator, _Sequence>& __lhs, + const __iterator_tracker<_Iterator, _Sequence>& __rhs) +{ + return __lhs.base() <= __rhs.base(); +} + +template +inline bool +operator>(const __iterator_tracker<_IteratorL, _Sequence>& __lhs, + const __iterator_tracker<_IteratorR, _Sequence>& __rhs) +{ + return __lhs.base() > __rhs.base(); +} + +template +inline bool +operator>(const __iterator_tracker<_Iterator, _Sequence>& __lhs, + const __iterator_tracker<_Iterator, _Sequence>& __rhs) +{ + return __lhs.base() > __rhs.base(); +} + +template +inline bool +operator>=(const __iterator_tracker<_IteratorL, _Sequence>& __lhs, + const __iterator_tracker<_IteratorR, _Sequence>& __rhs) +{ + return __lhs.base() >= __rhs.base(); +} + +template +inline bool +operator>=(const __iterator_tracker<_Iterator, _Sequence>& __lhs, + const __iterator_tracker<_Iterator, _Sequence>& __rhs) +{ + return __lhs.base() >= __rhs.base(); +} + +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// According to the resolution of DR179 not only the various comparison +// operators but also operator- must accept mixed iterator/const_iterator +// parameters. + template + inline typename __iterator_tracker<_IteratorL, _Sequence>::difference_type + operator-(const __iterator_tracker<_IteratorL, _Sequence>& __lhs, + const __iterator_tracker<_IteratorR, _Sequence>& __rhs) +{ + return __lhs.base() - __rhs.base(); +} + +template +inline typename __iterator_tracker<_Iterator, _Sequence>::difference_type +operator-(const __iterator_tracker<_Iterator, _Sequence>& __lhs, + const __iterator_tracker<_Iterator, _Sequence>& __rhs) +{ + return __lhs.base() - __rhs.base(); +} + +template +inline __iterator_tracker<_Iterator, _Sequence> +operator+(typename __iterator_tracker<_Iterator,_Sequence>::difference_type + __n, + const __iterator_tracker<_Iterator, _Sequence>& __i) +{ + return __i + __n; +} + +} // namespace __profile +} // namespace std +#endif
iterator_tracker.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: list =================================================================== --- list (nonexistent) +++ list (revision 826) @@ -0,0 +1,610 @@ +// Profiling list implementation -*- C++ -*- + +// Copyright (C) 2009, 2010 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 3, 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file profile/list + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_LIST +#define _GLIBCXX_PROFILE_LIST 1 + +#include +#include +#include + +namespace std +{ +namespace __profile +{ + /** @brief List wrapper with performance instrumentation. */ +template > + class list + : public _GLIBCXX_STD_D::list<_Tp, _Allocator> + { + typedef _GLIBCXX_STD_D::list<_Tp, _Allocator> _Base; + + public: + typedef typename _Base::reference reference; + typedef typename _Base::const_reference const_reference; + + typedef __iterator_tracker + iterator; + typedef __iterator_tracker + const_iterator; + + typedef typename _Base::size_type size_type; + typedef typename _Base::difference_type difference_type; + + typedef _Tp value_type; + typedef _Allocator allocator_type; + typedef typename _Base::pointer pointer; + typedef typename _Base::const_pointer const_pointer; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + // 23.2.2.1 construct/copy/destroy: + explicit list(const _Allocator& __a = _Allocator()) + : _Base(__a) + { + __profcxx_list_construct(this); // list2slist + __profcxx_list_construct2(this); // list2vector + } + + explicit list(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) + { + __profcxx_list_construct(this); + __profcxx_list_construct2(this); + } + + template + list(_InputIterator __first, _InputIterator __last, + const _Allocator& __a = _Allocator()) + : _Base(__first, __last, __a) + { + __profcxx_list_construct(this); + __profcxx_list_construct2(this); + } + + list(const list& __x) + : _Base(__x) + { + __profcxx_list_construct(this); + __profcxx_list_construct2(this); + } + + list(const _Base& __x) + : _Base(__x) + { + __profcxx_list_construct(this); + __profcxx_list_construct2(this); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + list(list&& __x) + : _Base(std::forward(__x)) + { + __profcxx_list_construct(this); + __profcxx_list_construct2(this); + } + + list(initializer_list __l, + const allocator_type& __a = allocator_type()) + : _Base(__l, __a) { } +#endif + + ~list() { + __profcxx_list_destruct(this); + __profcxx_list_destruct2(this); + } + + list& + operator=(const list& __x) + { + static_cast<_Base&>(*this) = __x; + return *this; + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + list& + operator=(list&& __x) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } + + list& + operator=(initializer_list __l) + { + static_cast<_Base&>(*this) = __l; + return *this; + } + + void + assign(initializer_list __l) + { _Base::assign(__l); } +#endif + + template + void + assign(_InputIterator __first, _InputIterator __last) + { _Base::assign(__first, __last); } + + void + assign(size_type __n, const _Tp& __t) + { _Base::assign(__n, __t); } + + using _Base::get_allocator; + + // iterators: + iterator + begin() + { return iterator(_Base::begin(), this); } + + const_iterator + begin() const + { return const_iterator(_Base::begin(), this); } + + iterator + end() + { + __profcxx_list_rewind(this); + return iterator(_Base::end(), this); + } + + const_iterator + end() const + { + __profcxx_list_rewind(this); + return const_iterator(_Base::end(), this); + } + + reverse_iterator + rbegin() + { + __profcxx_list_rewind(this); + return reverse_iterator(end()); + } + + const_reverse_iterator + rbegin() const + { + __profcxx_list_rewind(this); + return const_reverse_iterator(end()); + } + + reverse_iterator + rend() + { return reverse_iterator(begin()); } + + const_reverse_iterator + rend() const + { return const_reverse_iterator(begin()); } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + const_iterator + cbegin() const + { return const_iterator(_Base::begin(), this); } + + const_iterator + cend() const + { return const_iterator(_Base::end(), this); } + + const_reverse_iterator + crbegin() const + { return const_reverse_iterator(end()); } + + const_reverse_iterator + crend() const + { return const_reverse_iterator(begin()); } +#endif + + // 23.2.2.2 capacity: + using _Base::empty; + using _Base::size; + using _Base::max_size; + + void + resize(size_type __sz, _Tp __c = _Tp()) + { _Base::resize(__sz, __c); } + + // element access: + reference + front() + { return _Base::front(); } + + const_reference + front() const + { return _Base::front(); } + + reference + back() + { + __profcxx_list_rewind(this); + return _Base::back(); + } + + const_reference + back() const + { + __profcxx_list_rewind(this); + return _Base::back(); + } + + // 23.2.2.3 modifiers: + void + push_front(const value_type& __x) + { + __profcxx_list_invalid_operator(this); + __profcxx_list_operation(this); + _Base::push_front(__x); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + using _Base::emplace_front; +#endif + + void + pop_front() + { + __profcxx_list_operation(this); + _Base::pop_front(); + } + + using _Base::push_back; + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + using _Base::emplace_back; +#endif + + void + pop_back() + { + iterator __victim = end(); + --__victim; + _Base::pop_back(); + __profcxx_list_rewind(this); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + iterator + emplace(iterator __position, _Args&&... __args) + { + return iterator(_Base::emplace(__position.base(), + std::forward<_Args>(__args)...)); + } +#endif + + iterator + insert(iterator __position, const _Tp& __x) + { + _M_profile_insert(this, __position, size()); + return iterator(_Base::insert(__position.base(), __x), this); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(iterator __position, _Tp&& __x) + { + _M_profile_insert(this, __position, size()); + return iterator(_Base::emplace(__position.base(), std::move(__x)), + this); + } + + void + insert(iterator __position, initializer_list __l) + { + _M_profile_insert(this, __position, size()); + _Base::insert(__position.base(), __l); + } +#endif + + void + insert(iterator __position, size_type __n, const _Tp& __x) + { + _M_profile_insert(this, __position, size()); + _Base::insert(__position.base(), __n, __x); + } + + template + void + insert(iterator __position, _InputIterator __first, + _InputIterator __last) + { + _M_profile_insert(this, __position, size()); + _Base::insert(__position.base(), __first, __last); + } + + iterator + erase(iterator __position) + { return iterator(_Base::erase(__position.base()), this); } + + iterator + erase(iterator __position, iterator __last) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 151. can't currently clear() empty container + return iterator(_Base::erase(__position.base(), __last.base()), this); + } + + void + swap(list& __x) + { _Base::swap(__x); } + + void + clear() + { _Base::clear(); } + + // 23.2.2.4 list operations: + void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + splice(iterator __position, list&& __x) +#else + splice(iterator __position, list& __x) +#endif + { this->splice(__position, _GLIBCXX_MOVE(__x), __x.begin(), __x.end()); } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + splice(iterator __position, list& __x) + { this->splice(__position, std::move(__x)); } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + splice(iterator __position, list& __x, iterator __i) + { this->splice(__position, std::move(__x), __i); } +#endif + + void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + splice(iterator __position, list&& __x, iterator __i) +#else + splice(iterator __position, list& __x, iterator __i) +#endif + { + // We used to perform the splice_alloc check: not anymore, redundant + // after implementing the relevant bits of N1599. + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()), + __i.base()); + } + + void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + splice(iterator __position, list&& __x, iterator __first, + iterator __last) +#else + splice(iterator __position, list& __x, iterator __first, + iterator __last) +#endif + { + // We used to perform the splice_alloc check: not anymore, redundant + // after implementing the relevant bits of N1599. + + _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()), + __first.base(), __last.base()); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + splice(iterator __position, list& __x, iterator __first, iterator __last) + { this->splice(__position, std::move(__x), __first, __last); } +#endif + + void + remove(const _Tp& __value) + { + for (iterator __x = begin(); __x != end(); ) + { + if (*__x == __value) + __x = erase(__x); + else + ++__x; + } + } + + template + void + remove_if(_Predicate __pred) + { + for (iterator __x = begin(); __x != end(); ) + { + __profcxx_list_operation(this); + if (__pred(*__x)) + __x = erase(__x); + else + ++__x; + } + } + + void + unique() + { + iterator __first = begin(); + iterator __last = end(); + if (__first == __last) + return; + iterator __next = __first; + while (++__next != __last) + { + __profcxx_list_operation(this); + if (*__first == *__next) + erase(__next); + else + __first = __next; + __next = __first; + } + } + + template + void + unique(_BinaryPredicate __binary_pred) + { + iterator __first = begin(); + iterator __last = end(); + if (__first == __last) + return; + iterator __next = __first; + while (++__next != __last) + { + __profcxx_list_operation(this); + if (__binary_pred(*__first, *__next)) + erase(__next); + else + __first = __next; + __next = __first; + } + } + + void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + merge(list&& __x) +#else + merge(list& __x) +#endif + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 300. list::merge() specification incomplete + if (this != &__x) + { _Base::merge(_GLIBCXX_MOVE(__x._M_base())); } + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + merge(list& __x) + { this->merge(std::move(__x)); } +#endif + + template + void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + merge(list&& __x, _Compare __comp) +#else + merge(list& __x, _Compare __comp) +#endif + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 300. list::merge() specification incomplete + if (this != &__x) + { _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp); } + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + void + merge(list& __x, _Compare __comp) + { this->merge(std::move(__x), __comp); } +#endif + + void + sort() { _Base::sort(); } + + template + void + sort(_StrictWeakOrdering __pred) { _Base::sort(__pred); } + + using _Base::reverse; + + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + + inline void _M_profile_find() const + { } + + inline void _M_profile_iterate(int __rewind = 0) const + { + __profcxx_list_operation(this); + __profcxx_list_iterate(this); + if (__rewind) + __profcxx_list_rewind(this); + } + + private: + size_type _M_profile_insert(void* obj, iterator __pos, size_type __size) + { + size_type __shift = 0; + typename _Base::iterator __it = __pos.base(); + for ( ; __it!=_Base::end(); __it++) + __shift++; + __profcxx_list_rewind(this); + __profcxx_list_operation(this); + __profcxx_list_insert(this, __shift, __size); + } + }; + + template + inline bool + operator==(const list<_Tp, _Alloc>& __lhs, + const list<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() == __rhs._M_base(); } + + template + inline bool + operator!=(const list<_Tp, _Alloc>& __lhs, + const list<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() != __rhs._M_base(); } + + template + inline bool + operator<(const list<_Tp, _Alloc>& __lhs, + const list<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() < __rhs._M_base(); } + + template + inline bool + operator<=(const list<_Tp, _Alloc>& __lhs, + const list<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() <= __rhs._M_base(); } + + template + inline bool + operator>=(const list<_Tp, _Alloc>& __lhs, + const list<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() >= __rhs._M_base(); } + + template + inline bool + operator>(const list<_Tp, _Alloc>& __lhs, + const list<_Tp, _Alloc>& __rhs) + { return __lhs._M_base() > __rhs._M_base(); } + + template + inline void + swap(list<_Tp, _Alloc>& __lhs, list<_Tp, _Alloc>& __rhs) + { __lhs.swap(__rhs); } + +} // namespace __profile +} // namespace std + +#endif Index: set =================================================================== --- set (nonexistent) +++ set (revision 826) @@ -0,0 +1,41 @@ +// Profiling set/multiset implementation -*- C++ -*- + +// Copyright (C) 2009 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. + +/** @file profile/set + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_SET +#define _GLIBCXX_PROFILE_SET 1 + +#include +#include +#include + +#endif Index: multiset.h =================================================================== --- multiset.h (nonexistent) +++ multiset.h (revision 826) @@ -0,0 +1,372 @@ +// Profiling multiset implementation -*- C++ -*- + +// Copyright (C) 2009, 2010 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 3, 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file profile/multiset.h + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_MULTISET_H +#define _GLIBCXX_PROFILE_MULTISET_H 1 + +#include + +namespace std +{ +namespace __profile +{ + /// Class std::multiset wrapper with performance instrumentation. + template, + typename _Allocator = std::allocator<_Key> > + class multiset + : public _GLIBCXX_STD_D::multiset<_Key, _Compare, _Allocator> + { + typedef _GLIBCXX_STD_D::multiset<_Key, _Compare, _Allocator> _Base; + + public: + // types: + typedef _Key key_type; + typedef _Key value_type; + typedef _Compare key_compare; + typedef _Compare value_compare; + typedef _Allocator allocator_type; + typedef typename _Base::reference reference; + typedef typename _Base::const_reference const_reference; + + typedef typename _Base::iterator iterator; + typedef typename _Base::const_iterator const_iterator; + typedef typename _Base::reverse_iterator reverse_iterator; + typedef typename _Base::const_reverse_iterator const_reverse_iterator; + + typedef typename _Base::size_type size_type; + typedef typename _Base::difference_type difference_type; + typedef typename _Base::pointer pointer; + typedef typename _Base::const_pointer const_pointer; + + // 23.3.3.1 construct/copy/destroy: + explicit multiset(const _Compare& __comp = _Compare(), + const _Allocator& __a = _Allocator()) + : _Base(__comp, __a) { } + + template + multiset(_InputIterator __first, _InputIterator __last, + const _Compare& __comp = _Compare(), + const _Allocator& __a = _Allocator()) + : _Base(__first, __last, __comp, __a) { } + + multiset(const multiset& __x) + : _Base(__x) { } + + multiset(const _Base& __x) + : _Base(__x) { } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + multiset(multiset&& __x) + : _Base(std::forward(__x)) + { } + + multiset(initializer_list __l, + const _Compare& __comp = _Compare(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __comp, __a) { } +#endif + + ~multiset() { } + + multiset& + operator=(const multiset& __x) + { + *static_cast<_Base*>(this) = __x; + return *this; + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + multiset& + operator=(multiset&& __x) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } + + multiset& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l); + return *this; + } +#endif + + using _Base::get_allocator; + + // iterators: + iterator + begin() + { return iterator(_Base::begin()); } + + const_iterator + begin() const + { return const_iterator(_Base::begin()); } + + iterator + end() + { return iterator(_Base::end()); } + + const_iterator + end() const + { return const_iterator(_Base::end()); } + + reverse_iterator + rbegin() + { return reverse_iterator(end()); } + + const_reverse_iterator + rbegin() const + { return const_reverse_iterator(end()); } + + reverse_iterator + rend() + { return reverse_iterator(begin()); } + + const_reverse_iterator + rend() const + { return const_reverse_iterator(begin()); } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + const_iterator + cbegin() const + { return const_iterator(_Base::begin()); } + + const_iterator + cend() const + { return const_iterator(_Base::end()); } + + const_reverse_iterator + crbegin() const + { return const_reverse_iterator(end()); } + + const_reverse_iterator + crend() const + { return const_reverse_iterator(begin()); } +#endif + + // capacity: + using _Base::empty; + using _Base::size; + using _Base::max_size; + + // modifiers: + iterator + insert(const value_type& __x) + { return iterator(_Base::insert(__x)); } + + iterator + insert(iterator __position, const value_type& __x) + { + return iterator(_Base::insert(__position, __x)); + } + + template + void + insert(_InputIterator __first, _InputIterator __last) + { + _Base::insert(__first, __last); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + insert(initializer_list __l) + { _Base::insert(__l); } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + erase(iterator __position) + { return _Base::erase(__position); } +#else + void + erase(iterator __position) + { _Base::erase(__position); } +#endif + + size_type + erase(const key_type& __x) + { + std::pair __victims = this->equal_range(__x); + size_type __count = 0; + while (__victims.first != __victims.second) + { + iterator __victim = __victims.first++; + _Base::erase(__victim); + ++__count; + } + return __count; + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + erase(iterator __first, iterator __last) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 151. can't currently clear() empty container + while (__first != __last) + this->erase(__first++); + return __last; + } +#else + void + erase(iterator __first, iterator __last) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 151. can't currently clear() empty container + while (__first != __last) + this->erase(__first++); + } +#endif + + void + swap(multiset& __x) + { + _Base::swap(__x); + } + + void + clear() + { this->erase(begin(), end()); } + + // observers: + using _Base::key_comp; + using _Base::value_comp; + + // multiset operations: + iterator + find(const key_type& __x) + { return iterator(_Base::find(__x)); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 214. set::find() missing const overload + const_iterator + find(const key_type& __x) const + { return const_iterator(_Base::find(__x)); } + + using _Base::count; + + iterator + lower_bound(const key_type& __x) + { return iterator(_Base::lower_bound(__x)); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 214. set::find() missing const overload + const_iterator + lower_bound(const key_type& __x) const + { return const_iterator(_Base::lower_bound(__x)); } + + iterator + upper_bound(const key_type& __x) + { return iterator(_Base::upper_bound(__x)); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 214. set::find() missing const overload + const_iterator + upper_bound(const key_type& __x) const + { return const_iterator(_Base::upper_bound(__x)); } + + std::pair + equal_range(const key_type& __x) + { + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, _Base_iterator> __res = + _Base::equal_range(__x); + return std::make_pair(iterator(__res.first), + iterator(__res.second)); + } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 214. set::find() missing const overload + std::pair + equal_range(const key_type& __x) const + { + typedef typename _Base::const_iterator _Base_iterator; + std::pair<_Base_iterator, _Base_iterator> __res = + _Base::equal_range(__x); + return std::make_pair(const_iterator(__res.first), + const_iterator(__res.second)); + } + + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + + }; + + template + inline bool + operator==(const multiset<_Key, _Compare, _Allocator>& __lhs, + const multiset<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() == __rhs._M_base(); } + + template + inline bool + operator!=(const multiset<_Key, _Compare, _Allocator>& __lhs, + const multiset<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() != __rhs._M_base(); } + + template + inline bool + operator<(const multiset<_Key, _Compare, _Allocator>& __lhs, + const multiset<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() < __rhs._M_base(); } + + template + inline bool + operator<=(const multiset<_Key, _Compare, _Allocator>& __lhs, + const multiset<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() <= __rhs._M_base(); } + + template + inline bool + operator>=(const multiset<_Key, _Compare, _Allocator>& __lhs, + const multiset<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() >= __rhs._M_base(); } + + template + inline bool + operator>(const multiset<_Key, _Compare, _Allocator>& __lhs, + const multiset<_Key, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() > __rhs._M_base(); } + + template + void + swap(multiset<_Key, _Compare, _Allocator>& __x, + multiset<_Key, _Compare, _Allocator>& __y) + { return __x.swap(__y); } + +} // namespace __profile +} // namespace std + +#endif
multiset.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: map =================================================================== --- map (nonexistent) +++ map (revision 826) @@ -0,0 +1,41 @@ +// Profiling map/multimap implementation -*- C++ -*- + +// Copyright (C) 2009 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. + +/** @file profile/map + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_MAP +#define _GLIBCXX_PROFILE_MAP 1 + +#include +#include +#include + +#endif Index: multimap.h =================================================================== --- multimap.h (nonexistent) +++ multimap.h (revision 826) @@ -0,0 +1,372 @@ +// Profiling multimap implementation -*- C++ -*- + +// Copyright (C) 2009, 2010 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 3, 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file profile/multimap.h + * This file is a GNU profile extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_PROFILE_MULTIMAP_H +#define _GLIBCXX_PROFILE_MULTIMAP_H 1 + +#include + +namespace std +{ +namespace __profile +{ + /// Class std::multimap wrapper with performance instrumentation. + template, + typename _Allocator = std::allocator > > + class multimap + : public _GLIBCXX_STD_D::multimap<_Key, _Tp, _Compare, _Allocator> + { + typedef _GLIBCXX_STD_D::multimap<_Key, _Tp, _Compare, _Allocator> _Base; + + public: + // types: + typedef _Key key_type; + typedef _Tp mapped_type; + typedef std::pair value_type; + typedef _Compare key_compare; + typedef _Allocator allocator_type; + typedef typename _Base::reference reference; + typedef typename _Base::const_reference const_reference; + + typedef typename _Base::iterator iterator; + typedef typename _Base::const_iterator const_iterator; + typedef typename _Base::reverse_iterator reverse_iterator; + typedef typename _Base::const_reverse_iterator const_reverse_iterator; + + typedef typename _Base::size_type size_type; + typedef typename _Base::difference_type difference_type; + typedef typename _Base::pointer pointer; + typedef typename _Base::const_pointer const_pointer; + + using _Base::value_compare; + + // 23.3.1.1 construct/copy/destroy: + explicit multimap(const _Compare& __comp = _Compare(), + const _Allocator& __a = _Allocator()) + : _Base(__comp, __a) { } + + template + multimap(_InputIterator __first, _InputIterator __last, + const _Compare& __comp = _Compare(), + const _Allocator& __a = _Allocator()) + : _Base(__first, __last, __comp, __a) { } + + multimap(const multimap& __x) + : _Base(__x) { } + + multimap(const _Base& __x) + : _Base(__x) { } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + multimap(multimap&& __x) + : _Base(std::forward(__x)) + { } + + multimap(initializer_list __l, + const _Compare& __c = _Compare(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __c, __a) { } +#endif + + ~multimap() { } + + multimap& + operator=(const multimap& __x) + { + *static_cast<_Base*>(this) = __x; + return *this; + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + multimap& + operator=(multimap&& __x) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } + + multimap& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l); + return *this; + } +#endif + + using _Base::get_allocator; + + // iterators: + iterator + begin() + { return iterator(_Base::begin()); } + + const_iterator + begin() const + { return const_iterator(_Base::begin()); } + + iterator + end() + { return iterator(_Base::end()); } + + const_iterator + end() const + { return const_iterator(_Base::end()); } + + reverse_iterator + rbegin() + { return reverse_iterator(end()); } + + const_reverse_iterator + rbegin() const + { return const_reverse_iterator(end()); } + + reverse_iterator + rend() + { return reverse_iterator(begin()); } + + const_reverse_iterator + rend() const + { return const_reverse_iterator(begin()); } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + const_iterator + cbegin() const + { return const_iterator(_Base::begin()); } + + const_iterator + cend() const + { return const_iterator(_Base::end()); } + + const_reverse_iterator + crbegin() const + { return const_reverse_iterator(end()); } + + const_reverse_iterator + crend() const + { return const_reverse_iterator(begin()); } +#endif + + // capacity: + using _Base::empty; + using _Base::size; + using _Base::max_size; + + // modifiers: + iterator + insert(const value_type& __x) + { return iterator(_Base::insert(__x)); } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + insert(std::initializer_list __list) + { _Base::insert(__list); } +#endif + + iterator + insert(iterator __position, const value_type& __x) + { + return iterator(_Base::insert(__position, __x)); + } + + template + void + insert(_InputIterator __first, _InputIterator __last) + { + _Base::insert(__first, __last); + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + erase(iterator __position) + { return _Base::erase(__position); } +#else + void + erase(iterator __position) + { _Base::erase(__position); } +#endif + + size_type + erase(const key_type& __x) + { + std::pair __victims = this->equal_range(__x); + size_type __count = 0; + while (__victims.first != __victims.second) + { + iterator __victim = __victims.first++; + _Base::erase(__victim); + ++__count; + } + return __count; + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + erase(iterator __first, iterator __last) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 151. can't currently clear() empty container + while (__first != __last) + this->erase(__first++); + return __last; + } +#else + void + erase(iterator __first, iterator __last) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 151. can't currently clear() empty container + while (__first != __last) + this->erase(__first++); + } +#endif + + void + swap(multimap& __x) + { + _Base::swap(__x); + } + + void + clear() + { this->erase(begin(), end()); } + + // observers: + using _Base::key_comp; + using _Base::value_comp; + + // 23.3.1.3 multimap operations: + iterator + find(const key_type& __x) + { return iterator(_Base::find(__x)); } + + const_iterator + find(const key_type& __x) const + { return const_iterator(_Base::find(__x)); } + + using _Base::count; + + iterator + lower_bound(const key_type& __x) + { return iterator(_Base::lower_bound(__x)); } + + const_iterator + lower_bound(const key_type& __x) const + { return const_iterator(_Base::lower_bound(__x)); } + + iterator + upper_bound(const key_type& __x) + { return iterator(_Base::upper_bound(__x)); } + + const_iterator + upper_bound(const key_type& __x) const + { return const_iterator(_Base::upper_bound(__x)); } + + std::pair + equal_range(const key_type& __x) + { + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, _Base_iterator> __res = + _Base::equal_range(__x); + return std::make_pair(iterator(__res.first), + iterator(__res.second)); + } + + std::pair + equal_range(const key_type& __x) const + { + typedef typename _Base::const_iterator _Base_const_iterator; + std::pair<_Base_const_iterator, _Base_const_iterator> __res = + _Base::equal_range(__x); + return std::make_pair(const_iterator(__res.first), + const_iterator(__res.second)); + } + + _Base& + _M_base() { return *this; } + + const _Base& + _M_base() const { return *this; } + }; + + template + inline bool + operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, + const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() == __rhs._M_base(); } + + template + inline bool + operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, + const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() != __rhs._M_base(); } + + template + inline bool + operator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, + const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() < __rhs._M_base(); } + + template + inline bool + operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, + const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() <= __rhs._M_base(); } + + template + inline bool + operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, + const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() >= __rhs._M_base(); } + + template + inline bool + operator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, + const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) + { return __lhs._M_base() > __rhs._M_base(); } + + template + inline void + swap(multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, + multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) + { __lhs.swap(__rhs); } + +} // namespace __profile +} // namespace std + +#endif
multimap.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.