STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
profiler_list_to_vector.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Copyright (C) 2009-2013 Free Software Foundation, Inc.
4 //
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)
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.
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 
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/>.
23 
28 // Written by Changhee Jung.
29 
30 #ifndef _GLIBCXX_PROFILE_PROFILER_LIST_TO_VECTOR_H
31 #define _GLIBCXX_PROFILE_PROFILER_LIST_TO_VECTOR_H 1
32 
33 #include <sstream>
34 
35 #include "profile/impl/profiler.h"
38 
39 namespace __gnu_profile
40 {
43  : public __object_info_base
44  {
45  public:
49 
51  : __object_info_base(__stack), _M_shift_count(0), _M_iterate(0),
53  _M_max_size(0) { }
54 
55  virtual ~__list2vector_info() { }
56 
62 
63  void
65  {
67  _M_iterate += __o._M_iterate;
70  _M_valid &= __o._M_valid;
71  _M_resize += __o._M_resize;
73  }
74 
75  void
76  __write(FILE* __f) const
77  {
78  std::fprintf(__f, "%Zu %Zu %Zu %.0f %.0f\n", _M_shift_count,
80  }
81 
82  float
83  __magnitude() const
84  { return _M_list_cost - _M_vector_cost; }
85 
87  __advice() const
88  {
89  std::stringstream __sstream;
90  __sstream
91  << "change std::list to std::vector and its initial size from 0 to "
92  << _M_max_size;
93  return __sstream.str();
94  }
95 
98  { return _M_shift_count; }
99 
102  { return _M_iterate; }
103 
104  float
106  { return _M_list_cost; }
107 
110  { return _M_resize; }
111 
112  void
113  __set_list_cost(float __lc)
114  { _M_list_cost = __lc; }
115 
116  void
117  __set_vector_cost(float __vc)
118  { _M_vector_cost = __vc; }
119 
120  bool
122  { return _M_valid; }
123 
124  void
126  { _M_valid = false; }
127 
128  void
130  {
131  _M_shift_count += __shift;
132  _M_max_size = std::max(_M_max_size, __size);
133  }
134 
135  void
137  { _M_iterate += __num;}
138 
139  void
141  { _M_resize += __from; }
142 
143  private:
149  bool _M_valid;
151  };
152 
154  : public __list2vector_info
155  {
156  public:
158  : __list2vector_info(__o) {}
159  };
160 
162  : public __trace_base<__list2vector_info, __list2vector_stack_info>
163  {
164  public:
167  { __id = "list-to-vector"; }
168 
170 
171  // Insert a new node at construct with object, callstack and initial size.
172  void
173  __insert(__object_t __obj, __stack_t __stack)
174  { __add_object(__obj, __list2vector_info(__stack)); }
175 
176  // Call at destruction/clean to set container final size.
177  void
178  __destruct(const void* __obj)
179  {
180  if (!__is_on())
181  return;
182 
183  __list2vector_info* __res = __get_object_info(__obj);
184  if (!__res)
185  return;
186 
187  float __vc = __vector_cost(__res->__shift_count(), __res->__iterate());
188  float __lc = __list_cost(__res->__shift_count(), __res->__iterate());
189  __res->__set_vector_cost(__vc);
190  __res->__set_list_cost(__lc);
191  __retire_object(__obj);
192  }
193 
194  // Find the node in the live map.
195  __list2vector_info* __find(const void* __obj);
196 
197  // Collect cost of operations.
198  void
199  __opr_insert(const void* __obj, std::size_t __shift, std::size_t __size)
200  {
201  __list2vector_info* __res = __get_object_info(__obj);
202  if (__res)
203  __res->__opr_insert(__shift, __size);
204  }
205 
206  void
207  __opr_iterate(const void* __obj, std::size_t __num)
208  {
209  __list2vector_info* __res = __get_object_info(__obj);
210  if (__res)
211  __res->__opr_iterate(__num);
212  }
213 
214  void
215  __invalid_operator(const void* __obj)
216  {
217  __list2vector_info* __res = __get_object_info(__obj);
218  if (__res)
219  __res->__set_invalid();
220  }
221 
222  void
223  __resize(const void* __obj, std::size_t __from, std::size_t __to)
224  {
225  __list2vector_info* __res = __get_object_info(__obj);
226  if (__res)
227  __res->__resize(__from, __to);
228  }
229 
230  float
232  {
233  // The resulting vector will use a 'reserve' method.
234  return (__shift
235  * _GLIBCXX_PROFILE_DATA(__vector_shift_cost_factor).__value
236  + __iterate
237  * _GLIBCXX_PROFILE_DATA(__vector_iterate_cost_factor).__value);
238  }
239 
240  float
241  __list_cost(std::size_t __shift, std::size_t __iterate)
242  {
243  return (__shift
244  * _GLIBCXX_PROFILE_DATA(__list_shift_cost_factor).__value
245  + __iterate
246  * _GLIBCXX_PROFILE_DATA(__list_iterate_cost_factor).__value);
247  }
248  };
249 
250 
251  inline void
253  { _GLIBCXX_PROFILE_DATA(_S_list_to_vector) = new __trace_list_to_vector(); }
254 
255  inline void
257  {
258  if (_GLIBCXX_PROFILE_DATA(_S_list_to_vector))
259  {
260  _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->
261  __collect_warnings(__warnings);
262  _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__write(__f);
263  }
264  }
265 
266  inline void
268  {
269  if (!__profcxx_init())
270  return;
271 
272  _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__insert(__obj, __get_stack());
273  }
274 
275  inline void
277  {
278  if (!__profcxx_init())
279  return;
280 
281  _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__destruct(__obj);
282  }
283 
284  inline void
285  __trace_list_to_vector_insert(const void* __obj,
286  std::size_t __shift, std::size_t __size)
287  {
288  if (!__profcxx_init())
289  return;
290 
291  _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__opr_insert(__obj, __shift,
292  __size);
293  }
294 
295  inline void
296  __trace_list_to_vector_iterate(const void* __obj, std::size_t __num = 1)
297  {
298  if (!__profcxx_init())
299  return;
300 
301  _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__opr_iterate(__obj, __num);
302  }
303 
304  inline void
306  {
307  if (!__profcxx_init())
308  return;
309 
310  _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__invalid_operator(__obj);
311  }
312 
313  inline void
314  __trace_list_to_vector_resize(const void* __obj,
315  std::size_t __from, std::size_t __to)
316  {
317  if (!__profcxx_init())
318  return;
319 
320  _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__resize(__obj, __from, __to);
321  }
322 
323 } // namespace __gnu_profile
324 #endif /* _GLIBCXX_PROFILE_PROFILER_LIST_TO_VECTOR_H__ */
void __trace_list_to_vector_init()
Definition: profiler_list_to_vector.h:252
__stack_t __get_stack()
Definition: profiler_node.h:50
bool __is_on()
Definition: profiler_state.h:57
void __trace_list_to_vector_resize(const void *, std::size_t, std::size_t)
Definition: profiler_list_to_vector.h:314
void __trace_list_to_vector_invalid_operator(const void *)
Definition: profiler_list_to_vector.h:305
void __trace_list_to_vector_iterate(const void *, std::size_t)
Definition: profiler_list_to_vector.h:296
float _M_list_cost
Definition: profiler_list_to_vector.h:147
void __set_invalid()
Definition: profiler_list_to_vector.h:125
void __trace_list_to_vector_insert(const void *, std::size_t, std::size_t)
Definition: profiler_list_to_vector.h:285
float __list_cost(std::size_t __shift, std::size_t __iterate)
Definition: profiler_list_to_vector.h:241
bool __is_valid()
Definition: profiler_list_to_vector.h:121
std::size_t __size(__stack_t __stack)
Definition: profiler_node.h:68
float _M_vector_cost
Definition: profiler_list_to_vector.h:148
__list2vector_info()
Definition: profiler_list_to_vector.h:46
bool _M_valid
Definition: profiler_list_to_vector.h:149
float __magnitude() const
Definition: profiler_list_to_vector.h:83
void __trace_list_to_vector_construct(const void *)
Definition: profiler_list_to_vector.h:267
Data structures to represent profiling traces.
std::size_t _M_iterate
Definition: profiler_list_to_vector.h:145
#define true
Definition: stdbool.h:34
void __trace_list_to_vector_report(FILE *__f, __warning_vector_t &__warnings)
Definition: profiler_list_to_vector.h:256
basic_string< char > string
Definition: string:1153
std::size_t __resize()
Definition: profiler_list_to_vector.h:109
__stack_t __stack() const
Definition: profiler_node.h:141
void __trace_list_to_vector_destruct(const void *)
Definition: profiler_list_to_vector.h:276
std::_GLIBCXX_STD_C::vector< __warning_data > __warning_vector_t
Definition: profiler_trace.h:93
std::size_t _M_max_size
Definition: profiler_list_to_vector.h:150
std::size_t __shift_count()
Definition: profiler_list_to_vector.h:97
Base class for all trace producers.
Definition: profiler_trace.h:183
float __vector_cost(std::size_t __shift, std::size_t __iterate)
Definition: profiler_list_to_vector.h:231
void __opr_insert(const void *__obj, std::size_t __shift, std::size_t __size)
Definition: profiler_list_to_vector.h:199
Interface of the profiling runtime library.
void __opr_iterate(const void *__obj, std::size_t __num)
Definition: profiler_list_to_vector.h:207
void __merge(const __list2vector_info &__o)
Definition: profiler_list_to_vector.h:64
bool __profcxx_init()
This function must be called by each instrumentation point.
Definition: profiler_trace.h:649
__list2vector_info(const __list2vector_info &__o)
Definition: profiler_list_to_vector.h:57
#define _GLIBCXX_PROFILE_DATA(__name)
Definition: profiler.h:48
std::string __advice() const
Definition: profiler_list_to_vector.h:87
void __invalid_operator(const void *__obj)
Definition: profiler_list_to_vector.h:215
void __set_vector_cost(float __vc)
Definition: profiler_list_to_vector.h:117
~__trace_list_to_vector()
Definition: profiler_list_to_vector.h:169
void __write(FILE *__f) const
Definition: profiler_list_to_vector.h:76
__stack_npt * __stack_t
Definition: profiler_node.h:45
const _Tp & max(const _Tp &__a, const _Tp &__b)
Equivalent to std::max.
Definition: base.h:150
std::size_t _M_shift_count
Definition: profiler_list_to_vector.h:144
float __list_cost()
Definition: profiler_list_to_vector.h:105
void __resize(std::size_t __from, std::size_t)
Definition: profiler_list_to_vector.h:140
virtual ~__list2vector_info()
Definition: profiler_list_to_vector.h:55
void __add_object(__object_t object, __list2vector_info__info)
__SIZE_TYPE__ size_t
Definition: stddef.h:212
Definition: profiler_list_to_vector.h:153
Data structures to represent a single profiling event.
__list2vector_info(__stack_t __stack)
Definition: profiler_list_to_vector.h:50
std::size_t _M_resize
Definition: profiler_list_to_vector.h:146
Base class for a line in the object table.
Definition: profiler_node.h:123
Definition: profiler_list_to_vector.h:161
std::size_t __iterate()
Definition: profiler_list_to_vector.h:101
__trace_list_to_vector()
Definition: profiler_list_to_vector.h:165
void __destruct(const void *__obj)
Definition: profiler_list_to_vector.h:178
void __set_list_cost(float __lc)
Definition: profiler_list_to_vector.h:113
void __opr_insert(std::size_t __shift, std::size_t __size)
Definition: profiler_list_to_vector.h:129
__list2vector_info * __find(const void *__obj)
__list2vector_stack_info(const __list2vector_info &__o)
Definition: profiler_list_to_vector.h:157
void __insert(__object_t __obj, __stack_t __stack)
Definition: profiler_list_to_vector.h:173
void __opr_iterate(std::size_t __num)
Definition: profiler_list_to_vector.h:136
void __resize(const void *__obj, std::size_t __from, std::size_t __to)
Definition: profiler_list_to_vector.h:223
const void * __object_t
Definition: profiler_node.h:42
A list-to-vector instrumentation line in the object table.
Definition: profiler_list_to_vector.h:42