]>
Commit | Line | Data |
---|---|---|
1218d701 SR |
1 | // -*- C++ -*- |
2 | // | |
a5544970 | 3 | // Copyright (C) 2009-2019 Free Software Foundation, Inc. |
1218d701 SR |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
4bee90f7 PC |
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) | |
9 | // any later version. | |
10 | // | |
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. | |
1889b253 PC |
15 | |
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. | |
19 | ||
4bee90f7 PC |
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/>. | |
1218d701 | 23 | |
30f276c1 | 24 | /** @file profile/impl/profiler_hash_func.h |
1218d701 SR |
25 | * @brief Data structures to represent profiling traces. |
26 | */ | |
27 | ||
28 | // Written by Lixia Liu and Silvius Rus. | |
29 | ||
6b223191 BK |
30 | #ifndef _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H |
31 | #define _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H 1 | |
1218d701 | 32 | |
1218d701 SR |
33 | #include "profile/impl/profiler.h" |
34 | #include "profile/impl/profiler_node.h" | |
35 | #include "profile/impl/profiler_trace.h" | |
36 | ||
9ee6a740 | 37 | namespace __gnu_profile |
1218d701 | 38 | { |
b0af13ea | 39 | /** @brief A hash performance instrumentation line in the object table. */ |
c7d42abb | 40 | class __hashfunc_info |
b0af13ea PC |
41 | : public __object_info_base |
42 | { | |
43 | public: | |
b0af13ea | 44 | __hashfunc_info(__stack_t __stack) |
3f04c1b4 PC |
45 | : __object_info_base(__stack), _M_longest_chain(0), |
46 | _M_accesses(0), _M_hops(0) { } | |
47 | ||
b0af13ea PC |
48 | void |
49 | __merge(const __hashfunc_info& __o) | |
50 | { | |
b12db708 | 51 | __object_info_base::__merge(__o); |
b0af13ea PC |
52 | _M_longest_chain = std::max(_M_longest_chain, __o._M_longest_chain); |
53 | _M_accesses += __o._M_accesses; | |
54 | _M_hops += __o._M_hops; | |
55 | } | |
56 | ||
57 | void | |
c7d42abb PC |
58 | __destruct(std::size_t __chain, std::size_t __accesses, |
59 | std::size_t __hops) | |
b0af13ea PC |
60 | { |
61 | _M_longest_chain = std::max(_M_longest_chain, __chain); | |
62 | _M_accesses += __accesses; | |
63 | _M_hops += __hops; | |
64 | } | |
65 | ||
66 | void | |
67 | __write(FILE* __f) const | |
c7d42abb PC |
68 | { std::fprintf(__f, "%Zu %Zu %Zu\n", _M_hops, |
69 | _M_accesses, _M_longest_chain); } | |
b0af13ea PC |
70 | |
71 | float | |
72 | __magnitude() const | |
73 | { return static_cast<float>(_M_hops); } | |
74 | ||
c7d42abb | 75 | std::string |
b0af13ea | 76 | __advice() const |
c7d42abb | 77 | { return "change hash function"; } |
b0af13ea PC |
78 | |
79 | private: | |
c7d42abb PC |
80 | std::size_t _M_longest_chain; |
81 | std::size_t _M_accesses; | |
82 | std::size_t _M_hops; | |
b0af13ea PC |
83 | }; |
84 | ||
b0af13ea PC |
85 | /** @brief A hash performance instrumentation line in the stack table. */ |
86 | class __hashfunc_stack_info | |
87 | : public __hashfunc_info | |
88 | { | |
89 | public: | |
90 | __hashfunc_stack_info(const __hashfunc_info& __o) | |
91 | : __hashfunc_info(__o) { } | |
92 | }; | |
93 | ||
b0af13ea PC |
94 | /** @brief Hash performance instrumentation producer. */ |
95 | class __trace_hash_func | |
96 | : public __trace_base<__hashfunc_info, __hashfunc_stack_info> | |
97 | { | |
98 | public: | |
99 | __trace_hash_func() | |
a1360f57 | 100 | : __trace_base<__hashfunc_info, __hashfunc_stack_info>() |
b0af13ea PC |
101 | { __id = "hash-distr"; } |
102 | ||
103 | ~__trace_hash_func() {} | |
104 | ||
b0af13ea PC |
105 | // Call at destruction/clean to set container final size. |
106 | void | |
b12db708 FD |
107 | __destruct(__hashfunc_info* __obj_info, |
108 | std::size_t __chain, std::size_t __accesses, std::size_t __hops) | |
b0af13ea | 109 | { |
b12db708 | 110 | if (!__obj_info) |
b0af13ea PC |
111 | return; |
112 | ||
b12db708 FD |
113 | __obj_info->__destruct(__chain, __accesses, __hops); |
114 | __retire_object(__obj_info); | |
b0af13ea PC |
115 | } |
116 | }; | |
117 | ||
b0af13ea PC |
118 | inline void |
119 | __trace_hash_func_init() | |
120 | { _GLIBCXX_PROFILE_DATA(_S_hash_func) = new __trace_hash_func(); } | |
121 | ||
122 | inline void | |
b12db708 FD |
123 | __trace_hash_func_free() |
124 | { delete _GLIBCXX_PROFILE_DATA(_S_hash_func); } | |
1218d701 | 125 | |
b0af13ea | 126 | inline void |
b12db708 FD |
127 | __trace_hash_func_report(FILE* __f, __warning_vector_t& __warnings) |
128 | { __trace_report(_GLIBCXX_PROFILE_DATA(_S_hash_func), __f, __warnings); } | |
129 | ||
130 | inline __hashfunc_info* | |
131 | __trace_hash_func_construct() | |
b0af13ea PC |
132 | { |
133 | if (!__profcxx_init()) | |
b12db708 FD |
134 | return 0; |
135 | ||
136 | if (!__reentrance_guard::__get_in()) | |
137 | return 0; | |
1218d701 | 138 | |
b12db708 FD |
139 | __reentrance_guard __get_out; |
140 | return _GLIBCXX_PROFILE_DATA(_S_hash_func)->__add_object(__get_stack()); | |
b0af13ea | 141 | } |
a1360f57 | 142 | |
b0af13ea | 143 | inline void |
b12db708 FD |
144 | __trace_hash_func_destruct(__hashfunc_info* __obj_info, |
145 | std::size_t __chain, std::size_t __accesses, | |
146 | std::size_t __hops) | |
b0af13ea | 147 | { |
b12db708 | 148 | _GLIBCXX_PROFILE_DATA(_S_hash_func)->__destruct(__obj_info, __chain, |
c7d42abb | 149 | __accesses, __hops); |
b0af13ea | 150 | } |
1218d701 | 151 | |
9ee6a740 | 152 | } // namespace __gnu_profile |
6b223191 | 153 | #endif /* _GLIBCXX_PROFILE_PROFILER_HASH_FUNC_H */ |