]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/profile/impl/profiler_map_to_unordered_map.h
array: Clean useless white chars.
[thirdparty/gcc.git] / libstdc++-v3 / include / profile / impl / profiler_map_to_unordered_map.h
CommitLineData
1218d701
SR
1// -*- C++ -*-
2//
aa118a03 3// Copyright (C) 2009-2014 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
SR
23
24/** @file profile/impl/profiler_map_to_unordered_map.h
25 * @brief Diagnostics for map to unordered_map.
26 */
27
28// Written by Silvius Rus.
29
6b223191
BK
30#ifndef _GLIBCXX_PROFILE_PROFILER_MAP_TO_UNORDERED_MAP_H
31#define _GLIBCXX_PROFILE_PROFILER_MAP_TO_UNORDERED_MAP_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 37namespace __gnu_profile
1218d701 38{
b0af13ea 39 inline int
c7d42abb 40 __log2(std::size_t __size)
6b223191 41 {
c7d42abb 42 for (int __bit_count = sizeof(std::size_t) - 1; __bit_count >= 0;
f3de79d4 43 -- __bit_count)
b0af13ea
PC
44 if ((2 << __bit_count) & __size)
45 return __bit_count;
46 return 0;
1218d701 47 }
1218d701 48
b0af13ea 49 inline float
c7d42abb 50 __map_insert_cost(std::size_t __size)
f3de79d4 51 { return (_GLIBCXX_PROFILE_DATA(__map_insert_cost_factor).__value
b0af13ea
PC
52 * static_cast<float>(__log2(__size))); }
53
54 inline float
c7d42abb 55 __map_erase_cost(std::size_t __size)
b0af13ea
PC
56 { return (_GLIBCXX_PROFILE_DATA(__map_erase_cost_factor).__value
57 * static_cast<float>(__log2(__size))); }
58
59 inline float
c7d42abb 60 __map_find_cost(std::size_t __size)
b0af13ea
PC
61 { return (_GLIBCXX_PROFILE_DATA(__map_find_cost_factor).__value
62 * static_cast<float>(__log2(__size))); }
63
f3de79d4 64 /** @brief A map-to-unordered_map instrumentation line in the
b0af13ea 65 object table. */
c7d42abb 66 class __map2umap_info
b0af13ea
PC
67 : public __object_info_base
68 {
69 public:
70 __map2umap_info()
71 : _M_insert(0), _M_erase(0), _M_find(0), _M_iterate(0),
72 _M_umap_cost(0.0), _M_map_cost(0.0), _M_valid(true) { }
f3de79d4 73
b0af13ea 74 __map2umap_info(__stack_t __stack)
f3de79d4 75 : __object_info_base(__stack), _M_insert(0), _M_erase(0), _M_find(0),
b0af13ea
PC
76 _M_iterate(0), _M_umap_cost(0.0), _M_map_cost(0.0), _M_valid(true) { }
77
78 virtual ~__map2umap_info() { }
79
80 __map2umap_info(const __map2umap_info& __o)
81 : __object_info_base(__o), _M_insert(__o._M_insert),
82 _M_erase(__o._M_erase), _M_find(__o._M_find),
83 _M_iterate(__o._M_iterate), _M_umap_cost(__o._M_umap_cost),
84 _M_map_cost(__o._M_map_cost), _M_valid(__o._M_valid) { }
85
86 void
87 __merge(const __map2umap_info& __o)
88 {
89 _M_insert += __o._M_insert;
90 _M_erase += __o._M_erase;
91 _M_find += __o._M_find;
92 _M_umap_cost += __o._M_umap_cost;
93 _M_map_cost += __o._M_map_cost;
94 _M_valid &= __o._M_valid;
95 }
1218d701 96
b0af13ea
PC
97 void
98 __write(FILE* __f) const
99 {
c7d42abb
PC
100 std::fprintf(__f, "%Zu %Zu %Zu %Zu %.0f %.0f %s\n",
101 _M_insert, _M_erase, _M_find, _M_iterate, _M_map_cost,
102 _M_umap_cost, _M_valid ? "valid" : "invalid");
b0af13ea 103 }
c7d42abb 104
b0af13ea
PC
105 float
106 __magnitude() const
107 { return _M_map_cost - _M_umap_cost; }
108
c7d42abb 109 std::string
b0af13ea 110 __advice() const
f3de79d4 111 { return "prefer an unordered container"; }
b0af13ea
PC
112
113 void
c7d42abb 114 __record_insert(std::size_t __size, std::size_t __count)
b0af13ea 115 {
f3de79d4
FD
116 ++_M_insert;
117 if (__count)
118 {
119 _M_map_cost += __count * __map_insert_cost(__size);
120 _M_umap_cost
121 += (__count
122 * _GLIBCXX_PROFILE_DATA(__umap_insert_cost_factor).__value);
123 }
b0af13ea 124 }
1218d701 125
b0af13ea 126 void
c7d42abb 127 __record_erase(std::size_t __size, std::size_t __count)
b0af13ea 128 {
f3de79d4
FD
129 ++_M_erase;
130 if (__count)
131 {
132 _M_map_cost += __count * __map_erase_cost(__size);
133 _M_umap_cost
134 += (__count
135 * _GLIBCXX_PROFILE_DATA(__umap_erase_cost_factor).__value);
136 }
b0af13ea 137 }
1218d701 138
b0af13ea 139 void
c7d42abb 140 __record_find(std::size_t __size)
b0af13ea 141 {
f3de79d4 142 ++_M_find;
b0af13ea
PC
143 _M_map_cost += __map_find_cost(__size);
144 _M_umap_cost += _GLIBCXX_PROFILE_DATA(__umap_find_cost_factor).__value;
145 }
6b223191 146
b0af13ea 147 void
c7d42abb 148 __record_iterate(std::size_t __count)
b0af13ea
PC
149 {
150 _M_iterate += __count;
151 _M_map_cost
152 += (__count
153 * _GLIBCXX_PROFILE_DATA(__map_iterate_cost_factor).__value);
154 _M_umap_cost
155 += (__count
156 * _GLIBCXX_PROFILE_DATA(__umap_iterate_cost_factor).__value);
157 }
6b223191 158
b0af13ea
PC
159 void
160 __record_invalidate()
161 { _M_valid = false; }
162
163 private:
c7d42abb
PC
164 std::size_t _M_insert;
165 std::size_t _M_erase;
166 std::size_t _M_find;
167 std::size_t _M_iterate;
b0af13ea
PC
168 float _M_umap_cost;
169 float _M_map_cost;
170 bool _M_valid;
171 };
172
173
f3de79d4 174 /** @brief A map-to-unordered_map instrumentation line in the
b0af13ea 175 stack table. */
f3de79d4 176 class __map2umap_stack_info
b0af13ea
PC
177 : public __map2umap_info
178 {
179 public:
180 __map2umap_stack_info(const __map2umap_info& __o)
181 : __map2umap_info(__o) { }
182 };
183
184 /** @brief Map-to-unordered_map instrumentation producer. */
185 class __trace_map2umap
f3de79d4 186 : public __trace_base<__map2umap_info, __map2umap_stack_info>
b0af13ea
PC
187 {
188 public:
189 __trace_map2umap()
a1360f57 190 : __trace_base<__map2umap_info, __map2umap_stack_info>()
f3de79d4 191 { __id = "ordered-to-unordered"; }
b0af13ea 192 };
6b223191 193
b0af13ea
PC
194 inline void
195 __trace_map_to_unordered_map_init()
196 { _GLIBCXX_PROFILE_DATA(_S_map2umap) = new __trace_map2umap(); }
6b223191 197
b0af13ea
PC
198 inline void
199 __trace_map_to_unordered_map_report(FILE* __f,
200 __warning_vector_t& __warnings)
201 {
f3de79d4 202 if (_GLIBCXX_PROFILE_DATA(_S_map2umap))
b0af13ea
PC
203 {
204 _GLIBCXX_PROFILE_DATA(_S_map2umap)->__collect_warnings(__warnings);
205 _GLIBCXX_PROFILE_DATA(_S_map2umap)->__write(__f);
206 }
6b223191 207 }
1218d701 208
b0af13ea
PC
209 inline void
210 __trace_map_to_unordered_map_construct(const void* __obj)
211 {
212 if (!__profcxx_init())
213 return;
1218d701 214
b0af13ea
PC
215 _GLIBCXX_PROFILE_DATA(_S_map2umap)->
216 __add_object(__obj, __map2umap_info(__get_stack()));
217 }
1218d701 218
b0af13ea
PC
219 inline void
220 __trace_map_to_unordered_map_destruct(const void* __obj)
221 {
222 if (!__profcxx_init())
223 return;
1218d701 224
b0af13ea
PC
225 _GLIBCXX_PROFILE_DATA(_S_map2umap)->__retire_object(__obj);
226 }
1218d701 227
b0af13ea 228 inline void
f3de79d4 229 __trace_map_to_unordered_map_insert(const void* __obj,
c7d42abb 230 std::size_t __size, std::size_t __count)
b0af13ea
PC
231 {
232 if (!__profcxx_init())
233 return;
1218d701 234
b0af13ea
PC
235 __map2umap_info* __info
236 = _GLIBCXX_PROFILE_DATA(_S_map2umap)->__get_object_info(__obj);
1218d701 237
b0af13ea
PC
238 if (__info)
239 __info->__record_insert(__size, __count);
240 }
1218d701 241
b0af13ea 242 inline void
f3de79d4 243 __trace_map_to_unordered_map_erase(const void* __obj,
c7d42abb 244 std::size_t __size, std::size_t __count)
b0af13ea 245 {
f3de79d4 246 if (!__profcxx_init())
b0af13ea 247 return;
1218d701 248
f3de79d4 249 __map2umap_info* __info
b0af13ea 250 = _GLIBCXX_PROFILE_DATA(_S_map2umap)->__get_object_info(__obj);
1218d701 251
b0af13ea
PC
252 if (__info)
253 __info->__record_erase(__size, __count);
254 }
1218d701 255
b0af13ea 256 inline void
c7d42abb 257 __trace_map_to_unordered_map_find(const void* __obj, std::size_t __size)
b0af13ea
PC
258 {
259 if (!__profcxx_init())
260 return;
1218d701 261
b0af13ea
PC
262 __map2umap_info* __info
263 = _GLIBCXX_PROFILE_DATA(_S_map2umap)->__get_object_info(__obj);
1218d701 264
b0af13ea
PC
265 if (__info)
266 __info->__record_find(__size);
267 }
1218d701 268
b0af13ea 269 inline void
c7d42abb 270 __trace_map_to_unordered_map_iterate(const void* __obj, std::size_t __count)
b0af13ea
PC
271 {
272 if (!__profcxx_init())
273 return;
274
275 __map2umap_info* __info
276 = _GLIBCXX_PROFILE_DATA(_S_map2umap)->__get_object_info(__obj);
f3de79d4 277
b0af13ea
PC
278 if (__info)
279 __info->__record_iterate(__count);
280 }
1218d701 281
b0af13ea
PC
282 inline void
283 __trace_map_to_unordered_map_invalidate(const void* __obj)
284 {
285 if (!__profcxx_init())
286 return;
1218d701 287
b0af13ea
PC
288 __map2umap_info* __info
289 = _GLIBCXX_PROFILE_DATA(_S_map2umap)->__get_object_info(__obj);
1218d701 290
b0af13ea
PC
291 if (__info)
292 __info->__record_invalidate();
293 }
1218d701 294
9ee6a740 295} // namespace __gnu_profile
6b223191 296#endif /* _GLIBCXX_PROFILE_PROFILER_MAP_TO_UNORDERED_MAP_H */