libstdc++
|
00001 // -*- C++ -*- 00002 // 00003 // Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the terms 00007 // of the GNU General Public License as published by the Free Software 00008 // Foundation; either version 2, or (at your option) any later 00009 // version. 00010 00011 // This library is distributed in the hope that it will be useful, but 00012 // WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // General Public License for more details. 00015 00016 // You should have received a copy of the GNU General Public License 00017 // along with this library; see the file COPYING. If not, write to 00018 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 00019 // MA 02111-1307, USA. 00020 00021 // As a special exception, you may use this file as part of a free 00022 // software library without restriction. Specifically, if other files 00023 // instantiate templates or use macros or inline functions from this 00024 // file, or you compile this file and link it with other files to 00025 // produce an executable, this file does not by itself cause the 00026 // resulting executable to be covered by the GNU General Public 00027 // License. This exception does not however invalidate any other 00028 // reasons why the executable file might be covered by the GNU General 00029 // Public License. 00030 00031 /** @file profile/impl/profiler_hash_func.h 00032 * @brief Data structures to represent profiling traces. 00033 */ 00034 00035 // Written by Lixia Liu and Silvius Rus. 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 /** @brief A hash performance instrumentation line in the object table. */ 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 /** @brief A hash performance instrumentation line in the stack table. */ 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 /** @brief Hash performance instrumentation producer. */ 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 // Insert a new node at construct with object, callstack and initial size. 00123 void 00124 __insert(__object_t __obj, __stack_t __stack) 00125 { __add_object(__obj, __hashfunc_info(__stack)); } 00126 00127 // Call at destruction/clean to set container final size. 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 // First find the item from the live objects and update the informations. 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 } // namespace __gnu_profile 00181 #endif /* _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H */