summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrus <rus@138bc75d-0d04-0410-961f-82ee72b054a4>2009-03-11 22:00:47 +0000
committerrus <rus@138bc75d-0d04-0410-961f-82ee72b054a4>2009-03-11 22:00:47 +0000
commitd33da0580a584b85b7b4b7e7a4c5823cc023df24 (patch)
tree02363e048540eefbd8fd9e39076f46ec188e3975
parent4fbd591f54fd6e7cf60cf957f0844bfc7793d0c1 (diff)
downloadgcc-d33da0580a584b85b7b4b7e7a4c5823cc023df24.tar.gz
New diagnostic: map_to_unordered_map.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/profile-stdlib@144793 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog.profile-stdlib12
-rw-r--r--libstdc++-v3/include/profile/base.h2
-rw-r--r--libstdc++-v3/include/profile/map.h411
-rw-r--r--libstdc++-v3/libprofc++/Makefile.am6
-rw-r--r--libstdc++-v3/libprofc++/Makefile.in9
-rw-r--r--libstdc++-v3/libprofc++/profiler.h39
-rw-r--r--libstdc++-v3/libprofc++/profiler_map_to_unordered_map.cc141
-rw-r--r--libstdc++-v3/libprofc++/profiler_map_to_unordered_map.h202
-rw-r--r--libstdc++-v3/libprofc++/profiler_trace.cc4
-rw-r--r--libstdc++-v3/libprofc++/profiler_trace.h1
10 files changed, 771 insertions, 56 deletions
diff --git a/libstdc++-v3/ChangeLog.profile-stdlib b/libstdc++-v3/ChangeLog.profile-stdlib
index 15d1bae5fe2..058928b7bb7 100644
--- a/libstdc++-v3/ChangeLog.profile-stdlib
+++ b/libstdc++-v3/ChangeLog.profile-stdlib
@@ -1,3 +1,15 @@
+2009-03-11 Silvius Rus <rus@google.com>
+ * libprofc++/Makefile.am: Add modules.
+ * libprofc++/Makefile.in: Add modules.
+ * libprofc++/profiler_trace.cc: Add calls to initialization and report
+ for map_to_unordered_map.
+ * libprofc++/profiler.h: Add hooks for trace_map_to_unordered_map.
+ * libprofc++/profiler_map_to_unordered_map.cc: New file.
+ * libprofc++/profiler_map_to_unordered_map.h: New file.
+ * include/profile/base.h: Fix author field.
+ * include/profile/map.h: Update from include/debug/map.h. Add calls
+ to trace_map_to_unordered_map hooks.
+
2008-11-10 Silvius Rus <rus@google.com>
* libprofc++/Makefile.in: Add modules.
* libprofc++/profiler_vector_size.cc: Refactor.
diff --git a/libstdc++-v3/include/profile/base.h b/libstdc++-v3/include/profile/base.h
index 7c1f66a8db7..c7ff0d77eff 100644
--- a/libstdc++-v3/include/profile/base.h
+++ b/libstdc++-v3/include/profile/base.h
@@ -33,7 +33,7 @@
* This file is a GNU profile extension to the Standard C++ Library.
*/
-// Written by Johannes Singler.
+// Written by Lixia Liu
#ifndef _GLIBCXX_PROFILE_BASE_H
#define _GLIBCXX_PROFILE_BASE_H 1
diff --git a/libstdc++-v3/include/profile/map.h b/libstdc++-v3/include/profile/map.h
index 8923b59a2eb..43b7c55ba90 100644
--- a/libstdc++-v3/include/profile/map.h
+++ b/libstdc++-v3/include/profile/map.h
@@ -35,6 +35,8 @@
#ifndef _GLIBCXX_PROFILE_MAP_H
#define _GLIBCXX_PROFILE_MAP_H 1
+//#include <profile/safe_sequence.h>
+//#include <profile/safe_iterator.h>
#include <utility>
namespace std
@@ -44,33 +46,257 @@ namespace __profile
template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
class map
- : public _GLIBCXX_STD_PR::map<_Key, _Tp, _Compare, _Allocator>
+ : 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<const _Key, _Tp> 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 __gnu_profile::_Safe_iterator<typename _Base::iterator, map>
+// iterator;
+// typedef __gnu_profile::_Safe_iterator<typename _Base::const_iterator, map>
+// 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<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_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) { }
+ const _Allocator& __a = _Allocator())
+ : _Base(__comp, __a) {
+ __profcxx_map_to_unordered_map_construct(this);
+ }
template<typename _InputIterator>
map(_InputIterator __first, _InputIterator __last,
- const _Compare& __comp = _Compare(),
- const _Allocator& __a = _Allocator())
- : _Base(__first, __last, __comp, __a) { }
+ 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) { }
+ : _Base(__x) {
+ __profcxx_map_to_unordered_map_construct(this);
+ }
map(const _Base& __x)
- : _Base(__x) { }
+ : _Base(__x) {
+ __profcxx_map_to_unordered_map_construct(this);
+ }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
map(map&& __x)
: _Base(std::forward<map>(__x))
- { }
+ { this->_M_swap(__x); }
+
+ map(initializer_list<value_type> __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 675.
+ clear();
+ swap(__x);
+ return *this;
+ }
+
+ map&
+ operator=(initializer_list<value_type> __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(), this); }
+
+ const_iterator
+ cend() const
+ { return const_iterator(_Base::end(), this); }
+
+ 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);
+ }
+
+ // modifiers:
+ std::pair<iterator, bool>
+ 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, bool>(iterator(__res.first, this),
+ __res.second);
+ }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ void
+ insert(std::initializer_list<value_type> __list)
+ { _Base::insert(__list); }
#endif
- ~map() { }
+
+ iterator
+ insert(iterator __position, const value_type& __x)
+ {
+ return iterator(_Base::insert(__position.base(), __x), this);
+ }
+
+ template<typename _InputIterator>
+ 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);
+ }
+
+ void
+ erase(iterator __position)
+ {
+ _Base::erase(__position.base());
+ __profcxx_map_to_unordered_map_erase(this, size(), 1);
+ }
+
+ size_type
+ erase(const key_type& __x)
+ {
+ iterator __victim = find(__x);
+ if (__victim == end())
+ return 0;
+ else
+ {
+ _Base::erase(__victim.base());
+ return 1;
+ }
+ }
+
+ void
+ erase(iterator __first, iterator __last)
+ {
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 151. can't currently clear() empty container
+ while (__first != __last)
+ this->erase(__first++);
+ }
void
#ifdef __GXX_EXPERIMENTAL_CXX0X__
@@ -79,99 +305,186 @@ namespace __profile
swap(map& __x)
#endif
{
- _Base::swap(__x);
+ _Base::swap(__x);
+ this->_M_swap(__x);
}
+ void
+ clear()
+ { this->erase(begin(), end()); }
- map&
- operator=(const map& __x)
+ // observers:
+ using _Base::key_comp;
+ using _Base::value_comp;
+
+ // 23.3.1.3 map operations:
+ iterator
+ find(const key_type& __x)
{
- *static_cast<_Base*>(this) = __x;
- return *this;
+ __profcxx_map_to_unordered_map_find(this, size());
+ return iterator(_Base::find(__x), this);
}
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- map&
- operator=(map&& __x)
+ const_iterator
+ find(const key_type& __x) const
{
- // NB: DR 675.
- _Base::clear();
- _Base::swap(__x);
- return *this;
+ __profcxx_map_to_unordered_map_find(this, size());
+ return const_iterator(_Base::find(__x), this);
}
-#endif
- _Base&
- _M_base() { return *this; }
+ 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), this);
+ }
+
+ const_iterator
+ lower_bound(const key_type& __x) const
+ {
+ __profcxx_map_to_unordered_map_invalidate(this);
+ return const_iterator(_Base::lower_bound(__x), this);
+ }
+
+ iterator
+ upper_bound(const key_type& __x)
+ {
+ __profcxx_map_to_unordered_map_invalidate(this);
+ return iterator(_Base::upper_bound(__x), this);
+ }
+
+ const_iterator
+ upper_bound(const key_type& __x) const
+ {
+ __profcxx_map_to_unordered_map_invalidate(this);
+ return const_iterator(_Base::upper_bound(__x), this);
+ }
+
+ std::pair<iterator,iterator>
+ 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, this),
+ iterator(__res.second, this));
+ }
+
+ std::pair<const_iterator,const_iterator>
+ 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, this),
+ const_iterator(__res.second, this));
+ }
+
+ _Base&
+ _M_base() { return *this; }
const _Base&
_M_base() const { return *this; }
+
};
template<typename _Key, typename _Tp,
- typename _Compare, typename _Allocator>
+ typename _Compare, typename _Allocator>
inline bool
operator==(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
- const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
- { return __lhs._M_base() == __rhs._M_base(); }
+ 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<typename _Key, typename _Tp,
- typename _Compare, typename _Allocator>
+ typename _Compare, typename _Allocator>
inline bool
operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
- const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
- { return __lhs._M_base() != __rhs._M_base(); }
+ 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<typename _Key, typename _Tp,
- typename _Compare, typename _Allocator>
+ typename _Compare, typename _Allocator>
inline bool
operator<(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
- const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
- { return __lhs._M_base() < __rhs._M_base(); }
+ 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<typename _Key, typename _Tp,
- typename _Compare, typename _Allocator>
+ typename _Compare, typename _Allocator>
inline bool
operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
- const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
- { return __lhs._M_base() <= __rhs._M_base(); }
+ 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<typename _Key, typename _Tp,
- typename _Compare, typename _Allocator>
+ typename _Compare, typename _Allocator>
inline bool
operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
- const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
- { return __lhs._M_base() >= __rhs._M_base(); }
+ 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<typename _Key, typename _Tp,
- typename _Compare, typename _Allocator>
+ typename _Compare, typename _Allocator>
inline bool
operator>(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
- const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
- { return __lhs._M_base() > __rhs._M_base(); }
+ 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<typename _Key, typename _Tp,
- typename _Compare, typename _Allocator>
+ typename _Compare, typename _Allocator>
inline void
swap(map<_Key, _Tp, _Compare, _Allocator>& __lhs,
- map<_Key, _Tp, _Compare, _Allocator>& __rhs)
+ map<_Key, _Tp, _Compare, _Allocator>& __rhs)
{ __lhs.swap(__rhs); }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename _Key, typename _Tp,
- typename _Compare, typename _Allocator>
+ typename _Compare, typename _Allocator>
inline void
swap(map<_Key, _Tp, _Compare, _Allocator>&& __lhs,
- map<_Key, _Tp, _Compare, _Allocator>& __rhs)
+ map<_Key, _Tp, _Compare, _Allocator>& __rhs)
{ __lhs.swap(__rhs); }
template<typename _Key, typename _Tp,
- typename _Compare, typename _Allocator>
+ typename _Compare, typename _Allocator>
inline void
swap(map<_Key, _Tp, _Compare, _Allocator>& __lhs,
- map<_Key, _Tp, _Compare, _Allocator>&& __rhs)
+ map<_Key, _Tp, _Compare, _Allocator>&& __rhs)
{ __lhs.swap(__rhs); }
#endif
+
} // namespace __profile
} // namespace std
diff --git a/libstdc++-v3/libprofc++/Makefile.am b/libstdc++-v3/libprofc++/Makefile.am
index 7f46388e9c3..5d846f0a08f 100644
--- a/libstdc++-v3/libprofc++/Makefile.am
+++ b/libstdc++-v3/libprofc++/Makefile.am
@@ -31,12 +31,14 @@ headers = \
profiler.h \
sources = \
- profiler_node.cc \
+ profiler_node.cc \
profiler_trace.cc \
profiler_state.cc \
profiler_container_size.cc \
profiler_hashtable_size.cc \
- profiler_vector_size.cc
+ profiler_vector_size.cc \
+ profiler_vector_to_list.cc \
+ profiler_map_to_unordered_map.cc
libprofc___la_SOURCES = $(sources) $(c_sources)
libprofc__convenience_la_SOURCES = $(sources) $(c_sources)
diff --git a/libstdc++-v3/libprofc++/Makefile.in b/libstdc++-v3/libprofc++/Makefile.in
index 666dbc99bc3..593a6d67bee 100644
--- a/libstdc++-v3/libprofc++/Makefile.in
+++ b/libstdc++-v3/libprofc++/Makefile.in
@@ -81,7 +81,8 @@ am__libprofc___la_SOURCES_DIST = profiler_node.cc profiler_trace.cc \
profiler_vector_size.cc \
profiler_state.cc \
profiler_hash_func.cc \
- profiler_vector_to_list.cc
+ profiler_vector_to_list.cc \
+ profiler_map_to_unordered_map.cc
am__objects_1 = ${am__libprofc___la_SOURCES_DIST:.cc=.lo}
am_libprofc___la_OBJECTS = $(am__objects_1)
libprofc___la_OBJECTS = $(am_libprofc___la_OBJECTS)
@@ -336,7 +337,8 @@ sources = \
profiler_vector_size.cc \
profiler_state.cc \
profiler_hash_func.cc \
- profiler_vector_to_list.cc
+ profiler_vector_to_list.cc \
+ profiler_map_to_unordered_map.cc
libprofc___la_SOURCES = $(sources) $(c_sources)
libprofc__convenience_la_SOURCES = $(sources) $(c_sources)
@@ -699,6 +701,9 @@ cp-demangle.lo: cp-demangle.c
cp-demangle.o: cp-demangle.c
$(C_COMPILE) -DIN_GLIBCPP_V3 -Wno-error -c $<
+profiler_map_to_unordered_map.lo: profiler_map_to_unordered_map.cc profiler_node.h profiler_map_to_unordered_map.h
+ $(LTCOMPILE) -std=c++0x -c $<
+
profiler_vector_to_list.lo: profiler_vector_to_list.cc profiler_node.h profiler_vector_to_list.h
$(LTCOMPILE) -std=c++0x -c $<
diff --git a/libstdc++-v3/libprofc++/profiler.h b/libstdc++-v3/libprofc++/profiler.h
index 8df0f898a6e..53059ff8028 100644
--- a/libstdc++-v3/libprofc++/profiler.h
+++ b/libstdc++-v3/libprofc++/profiler.h
@@ -48,7 +48,9 @@ bool is_invalid();
bool is_on();
bool is_off();
-// Instrumentation hooks.
+// Instrumentation hooks. Do not use them directly in instrumented headers.
+// Instead use the corresponding __profcxx_ wrapper declared below, to enable
+// compile-time on/off switching.
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);
@@ -63,6 +65,13 @@ 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_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 cxxprof_runtime
// Master switch turns on all diagnostics.
@@ -73,6 +82,7 @@ void trace_vector_to_list_resize(const void*, size_t, size_t);
#define _GLIBCXX_PROFILE_VECTOR_TOO_LARGE
#define _GLIBCXX_PROFILE_INEFFICIENT_HASH
#define _GLIBCXX_PROFILE_VECTOR_TO_LIST
+#define _GLIBCXX_PROFILE_MAP_TO_UNORDERED_MAP
#endif
// Turn on/off instrumentation for HASHTABLE_TOO_SMALL and HASHTABLE_TOO_LARGE.
@@ -141,4 +151,31 @@ void trace_vector_to_list_resize(const void*, size_t, size_t);
#define __profcxx_vector_resize2(x...)
#endif
+// Turn on/off instrumentation for MAP_TO_UNORDERED_MAP.
+#if (defined(_GLIBCXX_PROFILE_MAP_TO_UNORDERED_MAP) \
+ && !defined(_NO_GLIBCXX_PROFILE_MAP_TO_UNORDERED_MAP))
+#define __profcxx_map_to_unordered_map_construct \
+ cxxprof_runtime::trace_map_to_unordered_map_construct
+#define __profcxx_map_to_unordered_map_destruct \
+ cxxprof_runtime::trace_map_to_unordered_map_destruct
+#define __profcxx_map_to_unordered_map_insert \
+ cxxprof_runtime::trace_map_to_unordered_map_insert
+#define __profcxx_map_to_unordered_map_insert \
+ cxxprof_runtime::trace_map_to_unordered_map_erase
+#define __profcxx_map_to_unordered_map_iterate \
+ cxxprof_runtime::trace_map_to_unordered_map_erase
+#define __profcxx_map_to_unordered_map_invalidate \
+ cxxprof_runtime::trace_map_to_unordered_map_invalidate
+#define __profcxx_map_to_unordered_map_find \
+ cxxprof_runtime::trace_map_to_unordered_map_find
+#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
+
#endif // PROFCXX_PROFILER_H__
diff --git a/libstdc++-v3/libprofc++/profiler_map_to_unordered_map.cc b/libstdc++-v3/libprofc++/profiler_map_to_unordered_map.cc
new file mode 100644
index 00000000000..f7603cc141f
--- /dev/null
+++ b/libstdc++-v3/libprofc++/profiler_map_to_unordered_map.cc
@@ -0,0 +1,141 @@
+// -*- C++ -*-
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the 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 libprofc++/profiler_vector_to_list.cc
+ * @brief Data structures to represent profiling traces.
+ */
+
+// Written by Silvius Rus <silvius.rus@gmail.com>
+
+#include "profiler.h"
+#include "profiler_node.h"
+#include "profiler_trace.h"
+#include "profiler_state.h"
+#include "profiler_map_to_unordered_map.h"
+#include <cstdlib>
+#include <cstdio>
+#include <cstring>
+#include <cassert>
+
+namespace cxxprof_runtime
+{
+
+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");
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+// Initialization and report.
+//////////////////////////////////////////////////////////////////////////////
+
+static trace_map2umap* _S_map2umap = NULL;
+
+void trace_map_to_unordered_map_init() {
+ _S_map2umap = new trace_map2umap();
+}
+
+void trace_map_to_unordered_map_report(FILE* f) {
+ if (_S_map2umap) {
+ _S_map2umap->write(f);
+ delete _S_map2umap;
+ _S_map2umap = NULL;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// Implementations of instrumentation hooks.
+//////////////////////////////////////////////////////////////////////////////
+
+void trace_map_to_unordered_map_construct(const void* __obj)
+{
+ if (!__profcxx_init()) return;
+
+ _S_map2umap->add_object(__obj, map2umap_info(get_stack()));
+}
+
+void trace_map_to_unordered_map_destruct(const void* __obj)
+{
+ if (!__profcxx_init()) return;
+
+ _S_map2umap->retire_object(__obj);
+}
+
+void trace_map_to_unordered_map_insert(const void* obj, size_t size,
+ size_t count)
+{
+ if (!__profcxx_init()) return;
+
+ map2umap_info* info = _S_map2umap->get_object_info(obj);
+
+ if (info) info->record_insert(size, count);
+}
+
+void trace_map_to_unordered_map_erase(const void* obj, size_t size,
+ size_t count)
+{
+ if (!__profcxx_init()) return;
+
+ map2umap_info* info = _S_map2umap->get_object_info(obj);
+
+ if (info) info->record_erase(size, count);
+}
+
+void trace_map_to_unordered_map_find(const void* obj, size_t size)
+{
+ if (!__profcxx_init()) return;
+
+ map2umap_info* info = _S_map2umap->get_object_info(obj);
+
+ if (info) info->record_find(size);
+}
+
+void trace_map_to_unordered_map_iterate(const void* obj, size_t count)
+{
+ if (!__profcxx_init()) return;
+
+ map2umap_info* info = _S_map2umap->get_object_info(obj);
+
+ if (info) info->record_iterate(count);
+}
+
+void trace_map_to_unordered_map_invalidate(const void* obj)
+{
+ if (!__profcxx_init()) return;
+
+ map2umap_info* info = _S_map2umap->get_object_info(obj);
+
+ if (info) info->record_invalidate();
+}
+
+} // namespace cxxprof_runtime
diff --git a/libstdc++-v3/libprofc++/profiler_map_to_unordered_map.h b/libstdc++-v3/libprofc++/profiler_map_to_unordered_map.h
new file mode 100644
index 00000000000..3a42b12f756
--- /dev/null
+++ b/libstdc++-v3/libprofc++/profiler_map_to_unordered_map.h
@@ -0,0 +1,202 @@
+// -*- C++ -*-
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the 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 libprofc++/profiler_trace.h
+ * @brief Data structures to represent profiling traces.
+ */
+
+// Written by Silvius Rus <silvius.rus@gmail.com>
+
+#ifndef PROFCXX_PROFILER_MAP_TO_UNORDERED_MAP_H__
+#define PROFCXX_PROFILER_MAP_TO_UNORDERED_MAP_H__ 1
+
+#include "profiler.h"
+#include "profiler_node.h"
+#include "profiler_trace.h"
+#include <cstdlib>
+#include <cstdio>
+#include <cstring>
+#include <cassert>
+
+namespace cxxprof_runtime
+{
+
+// Cost model. XXX: this must be taken from the machine model instead.
+// Map operations:
+// - insert: 1.5 * log(size)
+// - erase: 1.5 * log(size)
+// - find: log(size)
+// - iterate: 2.3
+// Unordered map operations:
+// - insert: 12
+// - erase: 12
+// - find: 10
+// - iterate: 1.7
+
+const float map_insert_cost_factor = 1.5;
+const float map_erase_cost_factor = 1.5;
+const float map_find_cost_factor = 1;
+const float map_iterate_cost = 2.3;
+
+const float umap_insert_cost = 12.0;
+const float umap_erase_cost = 12.0;
+const float umap_find_cost = 10.0;
+const float umap_iterate_cost = 1.7;
+
+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 map_insert_cost_factor * static_cast<float>(log2(size));
+}
+
+inline float map_erase_cost(size_t size)
+{
+ return map_erase_cost_factor * static_cast<float>(log2(size));
+}
+
+inline float map_find_cost(size_t size)
+{
+ return map_find_cost_factor * static_cast<float>(log2(size));
+}
+
+// Class for vector to list
+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;
+
+ 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 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 * umap_insert_cost;
+}
+
+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 * umap_erase_cost;
+}
+
+inline void map2umap_info:: record_find(size_t size)
+{
+ _M_find += 1;
+ _M_map_cost += map_find_cost(size);
+ _M_umap_cost += umap_find_cost;
+}
+
+inline void map2umap_info:: record_iterate(size_t count)
+{
+ _M_iterate += count;
+ _M_map_cost += count * map_iterate_cost;
+ _M_umap_cost += count * umap_iterate_cost;
+}
+
+inline void map2umap_info:: record_invalidate()
+{
+ _M_valid = false;
+}
+
+class map2umap_stack_info: public map2umap_info {
+ public:
+ map2umap_stack_info(const map2umap_info& o) : map2umap_info(o) {}
+};
+
+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";
+}
+
+} // namespace cxxprof_runtime
+#endif /* PROFCXX_PROFILER_MAP_TO_UNORDERED_MAP_H__ */
diff --git a/libstdc++-v3/libprofc++/profiler_trace.cc b/libstdc++-v3/libprofc++/profiler_trace.cc
index 00ecb2bc5f7..a4d377bf3ef 100644
--- a/libstdc++-v3/libprofc++/profiler_trace.cc
+++ b/libstdc++-v3/libprofc++/profiler_trace.cc
@@ -68,10 +68,12 @@ void trace_vector_size_init();
void trace_hashtable_size_init();
void trace_hash_func_init();
void trace_vector_to_list_init();
+void trace_map_to_unordered_map_init();
void trace_vector_size_report(FILE* f);
void trace_hashtable_size_report(FILE* f);
void trace_hash_func_report(FILE* f);
void trace_vector_to_list_report(FILE* f);
+void trace_map_to_unordered_map_report(FILE* f);
static size_t env_to_size_t(const char* env_var, size_t default_value)
{
@@ -116,6 +118,7 @@ static void __profcxx_report(void)
trace_hashtable_size_report(f);
trace_hash_func_report(f);
trace_vector_to_list_report(f);
+ trace_map_to_unordered_map_report(f);
fclose(f);
}
@@ -157,6 +160,7 @@ void __profcxx_init_unconditional()
trace_hashtable_size_init();
trace_hash_func_init();
trace_vector_to_list_init();
+ trace_map_to_unordered_map_init();
// Go live.
turn_on();
diff --git a/libstdc++-v3/libprofc++/profiler_trace.h b/libstdc++-v3/libprofc++/profiler_trace.h
index defbadc25f0..cc2211533ee 100644
--- a/libstdc++-v3/libprofc++/profiler_trace.h
+++ b/libstdc++-v3/libprofc++/profiler_trace.h
@@ -167,7 +167,6 @@ void trace_base<object_info, stack_info>::retire_object(object_t object)
stack_table_byte_size += (sizeof(instruction_address_t) * stack->size()
+ sizeof(stack) + sizeof(stack_info));
cxxprof_runtime::write(stdout, stack);
- printf(" Adding to stack table.\n");
stack_table.insert(make_pair(stack, stack_info(info)));
} else {
printf("Out of profiler memory: %s.\n", id);