Commit b0af13ea by Paolo Carlini Committed by Paolo Carlini

profiler_list_to_slist.h: Fix formatting, other minor stylistic changes.

2010-06-22  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/profile/impl/profiler_list_to_slist.h: Fix formatting,
	other minor stylistic changes.
	* include/profile/impl/profiler_container_size.h: Likewise.
	* include/profile/impl/profiler_vector_size.h: Likewise.
	* include/profile/impl/profiler_hash_func.h: Likewise.
	* include/profile/impl/profiler_trace.h: Likewise.
	* include/profile/impl/profiler_list_to_vector.h: Likewise.
	* include/profile/impl/profiler_vector_to_list.h: Likewise.
	* include/profile/impl/profiler_state.h: Likewise.
	* include/profile/impl/profiler_map_to_unordered_map.h: Likewise.
	* include/profile/impl/profiler_hashtable_size.h: Likewise.
	* include/profile/impl/profiler_node.h: Likewise.

From-SVN: r161236
parent b2e894b5
2010-06-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/profile/impl/profiler_list_to_slist.h: Fix formatting,
other minor stylistic changes.
* include/profile/impl/profiler_container_size.h: Likewise.
* include/profile/impl/profiler_vector_size.h: Likewise.
* include/profile/impl/profiler_hash_func.h: Likewise.
* include/profile/impl/profiler_trace.h: Likewise.
* include/profile/impl/profiler_list_to_vector.h: Likewise.
* include/profile/impl/profiler_vector_to_list.h: Likewise.
* include/profile/impl/profiler_state.h: Likewise.
* include/profile/impl/profiler_map_to_unordered_map.h: Likewise.
* include/profile/impl/profiler_hashtable_size.h: Likewise.
* include/profile/impl/profiler_node.h: Likewise.
2010-06-22 Matthias Klose <doko@ubuntu.com> 2010-06-22 Matthias Klose <doko@ubuntu.com>
* python/libstdcxx/v6/printers.py: Don't use string exceptions. * python/libstdcxx/v6/printers.py: Don't use string exceptions.
......
...@@ -55,166 +55,153 @@ ...@@ -55,166 +55,153 @@
namespace __gnu_profile namespace __gnu_profile
{ {
/** @brief A container size instrumentation line in the object table. */
/** @brief A container size instrumentation line in the object table. */ class __container_size_info
class __container_size_info: public __object_info_base : public __object_info_base
{ {
public: public:
__container_size_info(); __container_size_info()
__container_size_info(const __container_size_info& __o); : _M_init(0), _M_max(0), _M_min(0), _M_total(0), _M_item_min(0),
__container_size_info(__stack_t __stack, size_t __num); _M_item_max(0), _M_item_total(0), _M_count(0), _M_resize(0), _M_cost(0)
virtual ~__container_size_info() {} { }
void __write(FILE* f) const; __container_size_info(const __container_size_info& __o)
float __magnitude() const { return static_cast<float>(_M_cost); } : __object_info_base(__o), _M_init(__o._M_init), _M_max(__o._M_max),
const char* __advice() const; _M_min(__o._M_min), _M_total(__o._M_total),
_M_item_min(__o._M_item_min), _M_item_max(__o._M_item_max),
_M_item_total(__o._M_item_total), _M_count(__o._M_count),
_M_resize(__o._M_resize), _M_cost(__o._M_cost)
{ }
__container_size_info(__stack_t __stack, size_t __num)
: __object_info_base(__stack), _M_init(__num), _M_max(__num),
_M_min(0), _M_total(0), _M_item_min(0), _M_item_max(0),
_M_item_total(0), _M_count(0), _M_resize(0), _M_cost(0)
{ }
virtual ~__container_size_info() { }
void
__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);
}
void __merge(const __container_size_info& __o); float
// Call if a container is destructed or cleaned. __magnitude() const
void __destruct(size_t __num, size_t __inum); { return static_cast<float>(_M_cost); }
// 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: const char*
size_t _M_init; __advice() const
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; std::stringstream __message;
if (_M_init < _M_item_max) if (_M_init < _M_item_max)
__message << "change initial container size from " << _M_init __message << "change initial container size from " << _M_init
<< " to " << _M_item_max; << " to " << _M_item_max;
return strdup(__message.str().c_str()); return strdup(__message.str().c_str());
} }
inline void __container_size_info::__destruct(size_t __num, size_t __inum) void
{ __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;
}
// Call if a container is destructed or cleaned.
void
__destruct(size_t __num, size_t __inum)
{
_M_max = std::max(_M_max, __num); _M_max = std::max(_M_max, __num);
_M_item_max = std::max(_M_item_max, __inum); _M_item_max = std::max(_M_item_max, __inum);
if (_M_min == 0) { if (_M_min == 0)
{
_M_min = __num; _M_min = __num;
_M_item_min = __inum; _M_item_min = __inum;
} else { }
else
{
_M_min = std::min(_M_min, __num); _M_min = std::min(_M_min, __num);
_M_item_min = std::min(_M_item_min, __inum); _M_item_min = std::min(_M_item_min, __inum);
} }
_M_total += __num; _M_total += __num;
_M_item_total += __inum; _M_item_total += __inum;
_M_count += 1; _M_count += 1;
} }
inline void __container_size_info::__resize(size_t __from, size_t __to) // Estimate the cost of resize/rehash.
{ float
__resize_cost(size_t __from, size_t)
{ return __from; }
// Call if container is resized.
void
__resize(size_t __from, size_t __to)
{
_M_cost += this->__resize_cost(__from, __to); _M_cost += this->__resize_cost(__from, __to);
_M_resize += 1; _M_resize += 1;
_M_max = std::max(_M_max, __to); _M_max = std::max(_M_max, __to);
} }
inline __container_size_info::__container_size_info(__stack_t __stack, private:
size_t __num) size_t _M_init;
: __object_info_base(__stack), _M_init(0), _M_max(0), _M_item_max(0), size_t _M_max; // range of # buckets
_M_min(0), _M_item_min(0), _M_total(0), _M_item_total(0), _M_cost(0), size_t _M_min;
_M_count(0), _M_resize(0) size_t _M_total;
{ size_t _M_item_min; // range of # items
_M_init = _M_max = __num; size_t _M_item_max;
_M_item_min = _M_item_max = _M_item_total = _M_total = 0; size_t _M_item_total;
_M_min = 0; size_t _M_count;
_M_count = 0; size_t _M_resize;
_M_resize = 0; size_t _M_cost;
} };
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( /** @brief A container size instrumentation line in the stack table. */
const __container_size_info& __o) class __container_size_stack_info
: __object_info_base(__o) : public __container_size_info
{ {
_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: public:
__container_size_stack_info(const __container_size_info& __o) __container_size_stack_info(const __container_size_info& __o)
: __container_size_info(__o) {} : __container_size_info(__o) { }
}; };
/** @brief Container size instrumentation trace producer. */
class __trace_container_size /** @brief Container size instrumentation trace producer. */
class __trace_container_size
: public __trace_base<__container_size_info, __container_size_stack_info> : public __trace_base<__container_size_info, __container_size_stack_info>
{ {
public: public:
~__trace_container_size() {} ~__trace_container_size() { }
__trace_container_size() __trace_container_size()
: __trace_base<__container_size_info, __container_size_stack_info>() {}; : __trace_base<__container_size_info, __container_size_stack_info>() { };
// Insert a new node at construct with object, callstack and initial size. // Insert a new node at construct with object, callstack and initial size.
void __insert(const __object_t __obj, __stack_t __stack, size_t __num); void
// Call at destruction/clean to set container final size. __insert(const __object_t __obj, __stack_t __stack, size_t __num)
void __destruct(const void* __obj, size_t __num, size_t __inum); { __add_object(__obj, __container_size_info(__stack, __num)); }
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, // XXX Undefined?
__stack_t __stack, size_t __num) void
{ __construct(const void* __obj, size_t __inum);
__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, // Call at destruction/clean to set container final size.
size_t __num, size_t __inum) void
{ __destruct(const void* __obj, size_t __num, size_t __inum)
if (!__is_on()) return; {
if (!__is_on())
return;
__object_t __obj_handle = static_cast<__object_t>(__obj); __object_t __obj_handle = static_cast<__object_t>(__obj);
...@@ -224,19 +211,22 @@ inline void __trace_container_size::__destruct(const void* __obj, ...@@ -224,19 +211,22 @@ inline void __trace_container_size::__destruct(const void* __obj,
__object_info->__destruct(__num, __inum); __object_info->__destruct(__num, __inum);
__retire_object(__obj_handle); __retire_object(__obj_handle);
} }
inline void __trace_container_size::__resize(const void* __obj, int __from, // Call at resize to set resize/cost information.
int __to) void
{ __resize(const void* __obj, int __from, int __to)
if (!__is_on()) return; {
if (!__is_on())
return;
__container_size_info* __object_info = __get_object_info(__obj); __container_size_info* __object_info = __get_object_info(__obj);
if (!__object_info) if (!__object_info)
return; return;
__object_info->__resize(__from, __to); __object_info->__resize(__from, __to);
} }
};
} // namespace __gnu_profile } // namespace __gnu_profile
#endif /* _GLIBCXX_PROFILE_PROFILER_CONTAINER_SIZE_H */ #endif /* _GLIBCXX_PROFILE_PROFILER_CONTAINER_SIZE_H */
...@@ -52,95 +52,92 @@ ...@@ -52,95 +52,92 @@
namespace __gnu_profile namespace __gnu_profile
{ {
/** @brief A hash performance instrumentation line in the object table. */
/** @brief A hash performance instrumentation line in the object table. */ class __hashfunc_info
class __hashfunc_info: public __object_info_base : public __object_info_base
{ {
public: public:
__hashfunc_info() __hashfunc_info()
:_M_longest_chain(0), _M_accesses(0), _M_hops(0) {} : _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); __hashfunc_info(const __hashfunc_info& __o)
void __destruct(size_t __chain, size_t __accesses, size_t __hops); : __object_info_base(__o), _M_longest_chain(__o._M_longest_chain),
void __write(FILE* __f) const; _M_accesses(__o._M_accesses), _M_hops(__o._M_hops) { }
float __magnitude() const { return static_cast<float>(_M_hops); }
const char* __advice() const { return strdup("change hash function"); }
private: __hashfunc_info(__stack_t __stack)
size_t _M_longest_chain; : __object_info_base(__stack),
size_t _M_accesses; _M_longest_chain(0), _M_accesses(0), _M_hops(0){ }
size_t _M_hops;
};
inline __hashfunc_info::__hashfunc_info(const __hashfunc_info& __o) virtual ~__hashfunc_info() {}
: __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) void
{ __merge(const __hashfunc_info& __o)
{
_M_longest_chain = std::max(_M_longest_chain, __o._M_longest_chain); _M_longest_chain = std::max(_M_longest_chain, __o._M_longest_chain);
_M_accesses += __o._M_accesses; _M_accesses += __o._M_accesses;
_M_hops += __o._M_hops; _M_hops += __o._M_hops;
} }
inline void __hashfunc_info::__destruct(size_t __chain, size_t __accesses, void
size_t __hops) __destruct(size_t __chain, size_t __accesses, size_t __hops)
{ {
_M_longest_chain = std::max(_M_longest_chain, __chain); _M_longest_chain = std::max(_M_longest_chain, __chain);
_M_accesses += __accesses; _M_accesses += __accesses;
_M_hops += __hops; _M_hops += __hops;
} }
/** @brief A hash performance instrumentation line in the stack table. */ void
class __hashfunc_stack_info: public __hashfunc_info { __write(FILE* __f) const
public: { fprintf(__f, "%Zu %Zu %Zu\n", _M_hops, _M_accesses, _M_longest_chain); }
__hashfunc_stack_info(const __hashfunc_info& __o) : __hashfunc_info(__o) {}
};
/** @brief Hash performance instrumentation producer. */ float
class __trace_hash_func __magnitude() const
: public __trace_base<__hashfunc_info, __hashfunc_stack_info> { return static_cast<float>(_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;
};
/** @brief A hash performance instrumentation line in the stack table. */
class __hashfunc_stack_info
: public __hashfunc_info
{
public: public:
__trace_hash_func(); __hashfunc_stack_info(const __hashfunc_info& __o)
~__trace_hash_func() {} : __hashfunc_info(__o) { }
};
// 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() /** @brief Hash performance instrumentation producer. */
class __trace_hash_func
: public __trace_base<__hashfunc_info, __hashfunc_stack_info>
{
public:
__trace_hash_func()
: __trace_base<__hashfunc_info, __hashfunc_stack_info>() : __trace_base<__hashfunc_info, __hashfunc_stack_info>()
{ { __id = "hash-distr"; }
__id = "hash-distr";
}
inline void __trace_hash_func::__insert(__object_t __obj, __stack_t __stack) ~__trace_hash_func() {}
{
__add_object(__obj, __hashfunc_info(__stack));
}
inline void __hashfunc_info::__write(FILE* __f) const // Insert a new node at construct with object, callstack and initial size.
{ void
fprintf(__f, "%Zu %Zu %Zu\n", _M_hops, _M_accesses, _M_longest_chain); __insert(__object_t __obj, __stack_t __stack)
} { __add_object(__obj, __hashfunc_info(__stack)); }
inline void __trace_hash_func::__destruct(const void* __obj, size_t __chain, // Call at destruction/clean to set container final size.
void
__destruct(const void* __obj, size_t __chain,
size_t __accesses, size_t __hops) size_t __accesses, size_t __hops)
{ {
if (!__is_on()) return; if (!__is_on())
return;
// First find the item from the live objects and update the informations. // First find the item from the live objects and update the informations.
__hashfunc_info* __objs = __get_object_info(__obj); __hashfunc_info* __objs = __get_object_info(__obj);
...@@ -149,37 +146,43 @@ inline void __trace_hash_func::__destruct(const void* __obj, size_t __chain, ...@@ -149,37 +146,43 @@ inline void __trace_hash_func::__destruct(const void* __obj, size_t __chain,
__objs->__destruct(__chain, __accesses, __hops); __objs->__destruct(__chain, __accesses, __hops);
__retire_object(__obj); __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, inline void
__warning_vector_t& __warnings) __trace_hash_func_init()
{ { _GLIBCXX_PROFILE_DATA(_S_hash_func) = new __trace_hash_func(); }
if (_GLIBCXX_PROFILE_DATA(_S_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)->__collect_warnings(__warnings);
_GLIBCXX_PROFILE_DATA(_S_hash_func)->__write(__f); _GLIBCXX_PROFILE_DATA(_S_hash_func)->__write(__f);
} }
} }
inline void __trace_hash_func_construct(const void* __obj) inline void
{ __trace_hash_func_construct(const void* __obj)
if (!__profcxx_init()) return; {
if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_hash_func)->__insert(__obj, __get_stack()); _GLIBCXX_PROFILE_DATA(_S_hash_func)->__insert(__obj, __get_stack());
} }
inline void __trace_hash_func_destruct(const void* __obj, size_t __chain, inline void
__trace_hash_func_destruct(const void* __obj, size_t __chain,
size_t __accesses, size_t __hops) size_t __accesses, size_t __hops)
{ {
if (!__profcxx_init()) return; if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_hash_func)->__destruct(__obj, __chain, __accesses, _GLIBCXX_PROFILE_DATA(_S_hash_func)->__destruct(__obj, __chain, __accesses,
__hops); __hops);
} }
} // namespace __gnu_profile } // namespace __gnu_profile
#endif /* _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H */ #endif /* _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H */
// -*- C++ -*- // -*- C++ -*-
// //
// Copyright (C) 2009 Free Software Foundation, Inc. // Copyright (C) 2009, 2010 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -54,54 +54,60 @@ ...@@ -54,54 +54,60 @@
namespace __gnu_profile namespace __gnu_profile
{ {
/** @brief Hashtable size instrumentation trace producer. */
/** @brief Hashtable size instrumentation trace producer. */ class __trace_hashtable_size
class __trace_hashtable_size : public __trace_container_size : public __trace_container_size
{
public:
__trace_hashtable_size() : __trace_container_size()
{ {
__id = "hashtable-size"; public:
} __trace_hashtable_size()
}; : __trace_container_size()
{ __id = "hashtable-size"; }
};
inline void __trace_hashtable_size_init() inline void
{ __trace_hashtable_size_init()
_GLIBCXX_PROFILE_DATA(_S_hashtable_size) = new __trace_hashtable_size(); { _GLIBCXX_PROFILE_DATA(_S_hashtable_size) = new __trace_hashtable_size(); }
}
inline void __trace_hashtable_size_report(FILE* __f, inline void
__warning_vector_t& __warnings) __trace_hashtable_size_report(FILE* __f, __warning_vector_t& __warnings)
{ {
if (_GLIBCXX_PROFILE_DATA(_S_hashtable_size)) { if (_GLIBCXX_PROFILE_DATA(_S_hashtable_size))
_GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__collect_warnings(__warnings); {
_GLIBCXX_PROFILE_DATA(_S_hashtable_size)->
__collect_warnings(__warnings);
_GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__write(__f); _GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__write(__f);
} }
} }
inline void __trace_hashtable_size_construct(const void* __obj, size_t __num) inline void
{ __trace_hashtable_size_construct(const void* __obj, size_t __num)
if (!__profcxx_init()) return; {
if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__insert(__obj, __get_stack(), _GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__insert(__obj, __get_stack(),
__num); __num);
} }
inline void __trace_hashtable_size_destruct(const void* __obj, size_t __num, inline void
__trace_hashtable_size_destruct(const void* __obj, size_t __num,
size_t __inum) size_t __inum)
{ {
if (!__profcxx_init()) return; if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__destruct(__obj, __num, __inum); _GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__destruct(__obj, __num, __inum);
} }
inline void __trace_hashtable_size_resize(const void* __obj, size_t __from, inline void
__trace_hashtable_size_resize(const void* __obj, size_t __from,
size_t __to) size_t __to)
{ {
if (!__profcxx_init()) return; if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__resize(__obj, __from, __to); _GLIBCXX_PROFILE_DATA(_S_hashtable_size)->__resize(__obj, __from, __to);
} }
} // namespace __gnu_profile } // namespace __gnu_profile
......
// -*- C++ -*- // -*- C++ -*-
// //
// Copyright (C) 2009 Free Software Foundation, Inc. // Copyright (C) 2009, 2010 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -52,66 +52,111 @@ ...@@ -52,66 +52,111 @@
namespace __gnu_profile namespace __gnu_profile
{ {
class __list2slist_info
class __list2slist_info: public __object_info_base : public __object_info_base
{ {
public: public:
__list2slist_info() : _M_rewind(false), _M_operations(0) {} __list2slist_info()
: _M_rewind(false), _M_operations(0) { }
__list2slist_info(__stack_t __stack) __list2slist_info(__stack_t __stack)
: _M_rewind(false), _M_operations(0),__object_info_base(__stack) {} : __object_info_base(__stack), _M_rewind(false), _M_operations(0) { }
virtual ~__list2slist_info() {}
__list2slist_info(const __list2slist_info& __o) : __object_info_base(__o) virtual ~__list2slist_info() { }
{ _M_rewind = __o._M_rewind; _M_operations = __o._M_operations; }
__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, // 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 // 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 // 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 // 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. // 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. // This could be implemented by passing the size classes in the config
// For now, we always assume F to be 1. // file. For now, we always assume F to be 1.
float __magnitude() const
{ if (!_M_rewind) return _M_operations; else return 0; } float
void __merge(const __list2slist_info& __o) {}; __magnitude() const
void __write(FILE* __f) const; {
const char* __advice() const if (!_M_rewind)
return _M_operations;
else
return 0;
}
void
__merge(const __list2slist_info&) { };
void
__write(FILE* __f) const
{ fprintf(__f, "%s\n", _M_rewind ? "invalid" : "valid"); }
const char*
__advice() const
{ return strdup("change std::list to std::forward_list"); } { 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: void
__opr_rewind()
{
_M_rewind = true;
_M_valid = false;
}
void
__record_operation()
{ _M_operations++; }
bool
__has_rewind()
{ return _M_rewind; }
private:
bool _M_rewind; bool _M_rewind;
size_t _M_operations; size_t _M_operations;
}; };
class __list2slist_stack_info: public __list2slist_info { class __list2slist_stack_info
: public __list2slist_info
{
public: public:
__list2slist_stack_info(const __list2slist_info& __o) __list2slist_stack_info(const __list2slist_info& __o)
: __list2slist_info(__o) {} : __list2slist_info(__o) { }
}; };
class __trace_list_to_slist class __trace_list_to_slist
: public __trace_base<__list2slist_info, __list2slist_stack_info> : public __trace_base<__list2slist_info, __list2slist_stack_info>
{ {
public: public:
~__trace_list_to_slist() {} ~__trace_list_to_slist() { }
__trace_list_to_slist() __trace_list_to_slist()
: __trace_base<__list2slist_info, __list2slist_stack_info>() : __trace_base<__list2slist_info, __list2slist_stack_info>()
{ __id = "list-to-slist"; } { __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 void
{ __opr_rewind(const void* __obj)
fprintf(__f, "%s\n", _M_rewind ? "invalid" : "valid"); {
} __list2slist_info* __res = __get_object_info(__obj);
if (__res)
__res->__opr_rewind();
}
inline void __trace_list_to_slist::__destruct(const void* __obj) void
{ __record_operation(const void* __obj)
{
__list2slist_info* __res = __get_object_info(__obj);
if (__res)
__res->__record_operation();
}
void
__insert(const __object_t __obj, __stack_t __stack)
{ __add_object(__obj, __list2slist_info(__stack)); }
void
__destruct(const void* __obj)
{
if (!__is_on()) if (!__is_on())
return; return;
...@@ -120,63 +165,60 @@ inline void __trace_list_to_slist::__destruct(const void* __obj) ...@@ -120,63 +165,60 @@ inline void __trace_list_to_slist::__destruct(const void* __obj)
return; return;
__retire_object(__obj); __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, inline void
__warning_vector_t& __warnings) __trace_list_to_slist_init()
{ { _GLIBCXX_PROFILE_DATA(_S_list_to_slist) = new __trace_list_to_slist(); }
if (_GLIBCXX_PROFILE_DATA(_S_list_to_slist)) {
_GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__collect_warnings(__warnings); 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); _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) inline void
{ __trace_list_to_slist_rewind(const void* __obj)
if (!__profcxx_init()) return; {
if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__opr_rewind(__obj); _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__opr_rewind(__obj);
} }
inline void __trace_list_to_slist_operation(const void* __obj) inline void
{ __trace_list_to_slist_operation(const void* __obj)
if (!__profcxx_init()) return; {
if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__record_operation(__obj); _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__record_operation(__obj);
} }
inline void __trace_list_to_slist_construct(const void* __obj) inline void
{ __trace_list_to_slist_construct(const void* __obj)
if (!__profcxx_init()) return; {
if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__insert(__obj, __get_stack()); _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__insert(__obj, __get_stack());
} }
inline void __trace_list_to_slist_destruct(const void* __obj) inline void
{ __trace_list_to_slist_destruct(const void* __obj)
if (!__profcxx_init()) return; {
if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__destruct(__obj); _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__destruct(__obj);
} }
} // namespace __gnu_profile } // namespace __gnu_profile
#endif /* _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H */ #endif /* _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H */
...@@ -53,15 +53,16 @@ ...@@ -53,15 +53,16 @@
namespace __gnu_profile namespace __gnu_profile
{ {
typedef const void* __object_t; typedef const void* __object_t;
typedef void* __instruction_address_t; typedef void* __instruction_address_t;
typedef std::_GLIBCXX_STD_PR::vector<__instruction_address_t> __stack_npt; typedef std::_GLIBCXX_STD_PR::vector<__instruction_address_t> __stack_npt;
typedef __stack_npt* __stack_t; typedef __stack_npt* __stack_t;
size_t __stack_max_depth(); size_t __stack_max_depth();
inline __stack_t __get_stack() inline __stack_t
{ __get_stack()
{
#if defined _GLIBCXX_HAVE_EXECINFO_H #if defined _GLIBCXX_HAVE_EXECINFO_H
size_t __max_depth = __stack_max_depth(); size_t __max_depth = __stack_max_depth();
if (__max_depth == 0) if (__max_depth == 0)
...@@ -74,99 +75,103 @@ inline __stack_t __get_stack() ...@@ -74,99 +75,103 @@ inline __stack_t __get_stack()
#else #else
return 0; return 0;
#endif #endif
} }
inline __size(const __stack_t& __stack) inline size_t
{ __size(__stack_t __stack)
if (!__stack) { {
if (!__stack)
return 0; return 0;
} else { else
return __stack->size(); return __stack->size();
} }
}
inline void __write(FILE* __f, const __stack_t __stack) // XXX
{ inline void
if (!__stack) { __write(FILE* __f, __stack_t __stack)
{
if (!__stack)
return; return;
}
__stack_npt::const_iterator __it; __stack_npt::const_iterator __it;
for (__it = __stack->begin(); __it != __stack->end(); ++__it) { for (__it = __stack->begin(); __it != __stack->end(); ++__it)
fprintf(__f, "%p ", *__it); fprintf(__f, "%p ", *__it);
} }
}
/** @brief Hash function for summary trace using call stack as index. */ /** @brief Hash function for summary trace using call stack as index. */
class __stack_hash class __stack_hash
{ {
public: public:
size_t operator()(const __stack_t __s) const size_t
operator()(__stack_t __s) const
{ {
if (!__s) { if (!__s)
return 0; return 0;
}
uintptr_t __index = 0; uintptr_t __index = 0;
__stack_npt::const_iterator __it; __stack_npt::const_iterator __it;
for (__it = __s->begin(); __it != __s->end(); ++__it) { for (__it = __s->begin(); __it != __s->end(); ++__it)
__index += reinterpret_cast<uintptr_t>(*__it); __index += reinterpret_cast<uintptr_t>(*__it);
}
return __index; return __index;
} }
bool operator() (const __stack_t __stack1, const __stack_t __stack2) const bool operator() (__stack_t __stack1, __stack_t __stack2) const
{ {
if (!__stack1 && !__stack2) return true; if (!__stack1 && !__stack2)
if (!__stack1 || !__stack2) return false; return true;
if (__stack1->size() != __stack2->size()) return false; if (!__stack1 || !__stack2)
return false;
if (__stack1->size() != __stack2->size())
return false;
size_t __byte_size = __stack1->size() * sizeof(__stack_npt::value_type); size_t __byte_size = __stack1->size() * sizeof(__stack_npt::value_type);
return memcmp(&(*__stack1)[0], &(*__stack2)[0], __byte_size) == 0; return memcmp(&(*__stack1)[0], &(*__stack2)[0], __byte_size) == 0;
} }
}; };
/** @brief Base class for a line in the object table. */
class __object_info_base /** @brief Base class for a line in the object table. */
{ class __object_info_base
{
public: public:
__object_info_base() {} __object_info_base() { }
__object_info_base(__stack_t __stack);
__object_info_base(const __object_info_base& o); __object_info_base(__stack_t __stack)
virtual ~__object_info_base() {} : _M_stack(__stack), _M_valid(true) { }
bool __is_valid() const { return _M_valid; }
__stack_t __stack() const { return _M_stack; } __object_info_base(const __object_info_base& __o)
: _M_stack(__o._M_stack), _M_valid(__o._M_valid) { }
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; virtual void __write(FILE* f) const = 0;
protected: protected:
__stack_t _M_stack; __stack_t _M_stack;
bool _M_valid; 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. */ /** @brief Base class for a line in the stack table. */
template<typename __object_info> template<typename __object_info>
class __stack_info_base class __stack_info_base
{ {
public: public:
__stack_info_base() {} __stack_info_base() { }
__stack_info_base(const __object_info& __info) = 0; __stack_info_base(const __object_info& __info) = 0;
virtual ~__stack_info_base() {} virtual ~__stack_info_base() {}
void __merge(const __object_info& __info) = 0; void __merge(const __object_info& __info) = 0;
virtual float __magnitude() const = 0; virtual float __magnitude() const = 0;
virtual const char* __get_id() const = 0; virtual const char* __get_id() const = 0;
}; };
} // namespace __gnu_profile } // namespace __gnu_profile
#endif /* _GLIBCXX_PROFILE_PROFILER_NODE_H */ #endif /* _GLIBCXX_PROFILE_PROFILER_NODE_H */
// -*- C++ -*- // -*- C++ -*-
// //
// Copyright (C) 2009 Free Software Foundation, Inc. // Copyright (C) 2009, 2010 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -39,32 +39,35 @@ ...@@ -39,32 +39,35 @@
namespace __gnu_profile namespace __gnu_profile
{ {
enum __state_type { __ON, __OFF, __INVALID };
enum __state_type { __ON, __OFF, __INVALID }; _GLIBCXX_PROFILE_DEFINE_DATA(__state_type, __state, __INVALID);
_GLIBCXX_PROFILE_DEFINE_DATA(__state_type, __state, __INVALID); inline bool
__turn(__state_type __s)
inline bool __turn(__state_type __s) { return (_GLIBCXX_PROFILE_DATA(__state)
{
return (_GLIBCXX_PROFILE_DATA(__state)
== __sync_val_compare_and_swap(&_GLIBCXX_PROFILE_DATA(__state), == __sync_val_compare_and_swap(&_GLIBCXX_PROFILE_DATA(__state),
__INVALID, __s)); __INVALID, __s)); }
}
inline bool __turn_on() inline bool
{ return __turn(__ON); } __turn_on()
{ return __turn(__ON); }
inline bool __turn_off() inline bool
{ return __turn(__OFF); } __turn_off()
{ return __turn(__OFF); }
inline bool __is_on() inline bool
{ return _GLIBCXX_PROFILE_DATA(__state) == __ON; } __is_on()
{ return _GLIBCXX_PROFILE_DATA(__state) == __ON; }
inline bool __is_off() inline bool
{ return _GLIBCXX_PROFILE_DATA(__state) == __OFF; } __is_off()
{ return _GLIBCXX_PROFILE_DATA(__state) == __OFF; }
inline bool __is_invalid() inline bool
{ return _GLIBCXX_PROFILE_DATA(__state) == __INVALID; } __is_invalid()
{ return _GLIBCXX_PROFILE_DATA(__state) == __INVALID; }
} // end namespace __gnu_profile } // end namespace __gnu_profile
#endif /* _GLIBCXX_PROFILE_PROFILER_STATE_H */ #endif /* _GLIBCXX_PROFILE_PROFILER_STATE_H */
// -*- C++ -*- // -*- C++ -*-
// //
// Copyright (C) 2009 Free Software Foundation, Inc. // Copyright (C) 2009, 2010 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the terms
...@@ -54,50 +54,57 @@ ...@@ -54,50 +54,57 @@
namespace __gnu_profile namespace __gnu_profile
{ {
/** @brief Hashtable size instrumentation trace producer. */
/** @brief Hashtable size instrumentation trace producer. */ class __trace_vector_size
class __trace_vector_size : public __trace_container_size : public __trace_container_size
{ {
public: public:
__trace_vector_size() : __trace_container_size() { __id = "vector-size"; } __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_init()
{ _GLIBCXX_PROFILE_DATA(_S_vector_size) = new __trace_vector_size(); }
inline void __trace_vector_size_report(FILE* __f,
__warning_vector_t& __warnings) inline void
{ __trace_vector_size_report(FILE* __f, __warning_vector_t& __warnings)
if (_GLIBCXX_PROFILE_DATA(_S_vector_size)) { {
if (_GLIBCXX_PROFILE_DATA(_S_vector_size))
{
_GLIBCXX_PROFILE_DATA(_S_vector_size)->__collect_warnings(__warnings); _GLIBCXX_PROFILE_DATA(_S_vector_size)->__collect_warnings(__warnings);
_GLIBCXX_PROFILE_DATA(_S_vector_size)->__write(__f); _GLIBCXX_PROFILE_DATA(_S_vector_size)->__write(__f);
} }
} }
inline void __trace_vector_size_construct(const void* __obj, size_t __num) inline void
{ __trace_vector_size_construct(const void* __obj, size_t __num)
if (!__profcxx_init()) return; {
if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_vector_size)->__insert(__obj, __get_stack(), __num); _GLIBCXX_PROFILE_DATA(_S_vector_size)->__insert(__obj, __get_stack(),
} __num);
}
inline void __trace_vector_size_destruct(const void* __obj, size_t __num, inline void
size_t __inum) __trace_vector_size_destruct(const void* __obj, size_t __num, size_t __inum)
{ {
if (!__profcxx_init()) return; if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_vector_size)->__destruct(__obj, __num, __inum); _GLIBCXX_PROFILE_DATA(_S_vector_size)->__destruct(__obj, __num, __inum);
} }
inline void __trace_vector_size_resize(const void* __obj, size_t __from, inline void
size_t __to) __trace_vector_size_resize(const void* __obj, size_t __from, size_t __to)
{ {
if (!__profcxx_init()) return; if (!__profcxx_init())
return;
_GLIBCXX_PROFILE_DATA(_S_vector_size)->__resize(__obj, __from, __to); _GLIBCXX_PROFILE_DATA(_S_vector_size)->__resize(__obj, __from, __to);
} }
} // namespace __gnu_profile } // namespace __gnu_profile
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment