Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H
00038 #define _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H 1
00039
00040 #include "profile/impl/profiler.h"
00041 #include "profile/impl/profiler_node.h"
00042 #include "profile/impl/profiler_trace.h"
00043
00044 namespace __gnu_profile
00045 {
00046
00047 class __hashfunc_info
00048 : public __object_info_base
00049 {
00050 public:
00051 __hashfunc_info()
00052 : _M_longest_chain(0), _M_accesses(0), _M_hops(0) { }
00053
00054 __hashfunc_info(const __hashfunc_info& __o)
00055 : __object_info_base(__o), _M_longest_chain(__o._M_longest_chain),
00056 _M_accesses(__o._M_accesses), _M_hops(__o._M_hops) { }
00057
00058 __hashfunc_info(__stack_t __stack)
00059 : __object_info_base(__stack), _M_longest_chain(0),
00060 _M_accesses(0), _M_hops(0) { }
00061
00062 virtual ~__hashfunc_info() { }
00063
00064 void
00065 __merge(const __hashfunc_info& __o)
00066 {
00067 _M_longest_chain = std::max(_M_longest_chain, __o._M_longest_chain);
00068 _M_accesses += __o._M_accesses;
00069 _M_hops += __o._M_hops;
00070 }
00071
00072 void
00073 __destruct(std::size_t __chain, std::size_t __accesses,
00074 std::size_t __hops)
00075 {
00076 _M_longest_chain = std::max(_M_longest_chain, __chain);
00077 _M_accesses += __accesses;
00078 _M_hops += __hops;
00079 }
00080
00081 void
00082 __write(FILE* __f) const
00083 { std::fprintf(__f, "%Zu %Zu %Zu\n", _M_hops,
00084 _M_accesses, _M_longest_chain); }
00085
00086 float
00087 __magnitude() const
00088 { return static_cast<float>(_M_hops); }
00089
00090 std::string
00091 __advice() const
00092 { return "change hash function"; }
00093
00094 private:
00095 std::size_t _M_longest_chain;
00096 std::size_t _M_accesses;
00097 std::size_t _M_hops;
00098 };
00099
00100
00101
00102 class __hashfunc_stack_info
00103 : public __hashfunc_info
00104 {
00105 public:
00106 __hashfunc_stack_info(const __hashfunc_info& __o)
00107 : __hashfunc_info(__o) { }
00108 };
00109
00110
00111
00112 class __trace_hash_func
00113 : public __trace_base<__hashfunc_info, __hashfunc_stack_info>
00114 {
00115 public:
00116 __trace_hash_func()
00117 : __trace_base<__hashfunc_info, __hashfunc_stack_info>()
00118 { __id = "hash-distr"; }
00119
00120 ~__trace_hash_func() {}
00121
00122
00123 void
00124 __insert(__object_t __obj, __stack_t __stack)
00125 { __add_object(__obj, __hashfunc_info(__stack)); }
00126
00127
00128 void
00129 __destruct(const void* __obj, std::size_t __chain,
00130 std::size_t __accesses, std::size_t __hops)
00131 {
00132 if (!__is_on())
00133 return;
00134
00135
00136 __hashfunc_info* __objs = __get_object_info(__obj);
00137 if (!__objs)
00138 return;
00139
00140 __objs->__destruct(__chain, __accesses, __hops);
00141 __retire_object(__obj);
00142 }
00143 };
00144
00145
00146 inline void
00147 __trace_hash_func_init()
00148 { _GLIBCXX_PROFILE_DATA(_S_hash_func) = new __trace_hash_func(); }
00149
00150 inline void
00151 __trace_hash_func_report(FILE* __f, __warning_vector_t& __warnings)
00152 {
00153 if (_GLIBCXX_PROFILE_DATA(_S_hash_func))
00154 {
00155 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__collect_warnings(__warnings);
00156 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__write(__f);
00157 }
00158 }
00159
00160 inline void
00161 __trace_hash_func_construct(const void* __obj)
00162 {
00163 if (!__profcxx_init())
00164 return;
00165
00166 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__insert(__obj, __get_stack());
00167 }
00168
00169 inline void
00170 __trace_hash_func_destruct(const void* __obj, std::size_t __chain,
00171 std::size_t __accesses, std::size_t __hops)
00172 {
00173 if (!__profcxx_init())
00174 return;
00175
00176 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__destruct(__obj, __chain,
00177 __accesses, __hops);
00178 }
00179
00180 }
00181 #endif