3 // Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License along
21 // with this library; see the file COPYING3. If not see
22 // <http://www.gnu.org/licenses/>.
24 /** @file profile/impl/profiler_hash_func.h
25 * @brief Data structures to represent profiling traces.
28 // Written by Lixia Liu and Silvius Rus.
30 #ifndef _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H
31 #define _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H 1
33 #include "profile/impl/profiler.h"
34 #include "profile/impl/profiler_node.h"
35 #include "profile/impl/profiler_trace.h"
37 namespace __gnu_profile
39 /** @brief A hash performance instrumentation line in the object table. */
41 : public __object_info_base
45 : _M_longest_chain(0), _M_accesses(0), _M_hops(0) { }
47 __hashfunc_info(const __hashfunc_info& __o)
48 : __object_info_base(__o), _M_longest_chain(__o._M_longest_chain),
49 _M_accesses(__o._M_accesses), _M_hops(__o._M_hops) { }
51 __hashfunc_info(__stack_t __stack)
52 : __object_info_base(__stack), _M_longest_chain(0),
53 _M_accesses(0), _M_hops(0) { }
55 virtual ~__hashfunc_info() { }
58 __merge(const __hashfunc_info& __o)
60 _M_longest_chain = std::max(_M_longest_chain, __o._M_longest_chain);
61 _M_accesses += __o._M_accesses;
62 _M_hops += __o._M_hops;
66 __destruct(std::size_t __chain, std::size_t __accesses,
69 _M_longest_chain = std::max(_M_longest_chain, __chain);
70 _M_accesses += __accesses;
75 __write(FILE* __f) const
76 { std::fprintf(__f, "%Zu %Zu %Zu\n", _M_hops,
77 _M_accesses, _M_longest_chain); }
81 { return static_cast<float>(_M_hops); }
85 { return "change hash function"; }
88 std::size_t _M_longest_chain;
89 std::size_t _M_accesses;
94 /** @brief A hash performance instrumentation line in the stack table. */
95 class __hashfunc_stack_info
96 : public __hashfunc_info
99 __hashfunc_stack_info(const __hashfunc_info& __o)
100 : __hashfunc_info(__o) { }
104 /** @brief Hash performance instrumentation producer. */
105 class __trace_hash_func
106 : public __trace_base<__hashfunc_info, __hashfunc_stack_info>
110 : __trace_base<__hashfunc_info, __hashfunc_stack_info>()
111 { __id = "hash-distr"; }
113 ~__trace_hash_func() {}
115 // Insert a new node at construct with object, callstack and initial size.
117 __insert(__object_t __obj, __stack_t __stack)
118 { __add_object(__obj, __hashfunc_info(__stack)); }
120 // Call at destruction/clean to set container final size.
122 __destruct(const void* __obj, std::size_t __chain,
123 std::size_t __accesses, std::size_t __hops)
128 // First find the item from the live objects and update the informations.
129 __hashfunc_info* __objs = __get_object_info(__obj);
133 __objs->__destruct(__chain, __accesses, __hops);
134 __retire_object(__obj);
140 __trace_hash_func_init()
141 { _GLIBCXX_PROFILE_DATA(_S_hash_func) = new __trace_hash_func(); }
144 __trace_hash_func_report(FILE* __f, __warning_vector_t& __warnings)
146 if (_GLIBCXX_PROFILE_DATA(_S_hash_func))
148 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__collect_warnings(__warnings);
149 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__write(__f);
154 __trace_hash_func_construct(const void* __obj)
156 if (!__profcxx_init())
159 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__insert(__obj, __get_stack());
163 __trace_hash_func_destruct(const void* __obj, std::size_t __chain,
164 std::size_t __accesses, std::size_t __hops)
166 if (!__profcxx_init())
169 _GLIBCXX_PROFILE_DATA(_S_hash_func)->__destruct(__obj, __chain,
173 } // namespace __gnu_profile
174 #endif /* _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H */