OSDN Git Service

projects clean up 1
[pinoc/pinoc.git] / test / Standart_startup / lib / include / c++ / 4.5-GNUH8_v10.03 / profile / impl / profiler_list_to_vector.h
1 // -*- C++ -*-
2 //
3 // Copyright (C) 2009, 2010 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 terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
9 // version.
10
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING.  If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
20
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction.  Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License.  This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
30
31 /** @file profile/impl/profiler_list_to_vector.h
32  *  @brief diagnostics for list to vector.
33  */
34
35 // Written by Changhee Jung.
36
37 #ifndef _GLIBCXX_PROFILE_PROFILER_LIST_TO_VECTOR_H
38 #define _GLIBCXX_PROFILE_PROFILER_LIST_TO_VECTOR_H 1
39
40 #ifdef __GXX_EXPERIMENTAL_CXX0X__
41 #include <cstdio>
42 #include <cstdlib>
43 #include <cstring>
44 #else
45 #include <stdio.h>
46 #include <stdint.h>
47 #include <string.h>
48 #endif
49 #include <string>
50 #include <sstream>
51 #include "profile/impl/profiler.h"
52 #include "profile/impl/profiler_node.h"
53 #include "profile/impl/profiler_trace.h"
54
55 namespace __gnu_profile
56 {
57
58 /** @brief A list-to-vector instrumentation line in the object table.  */
59 class __list2vector_info: public __object_info_base
60 {
61  public:
62   __list2vector_info()
63       :_M_shift_count(0), _M_iterate(0), _M_resize(0), _M_list_cost(0),
64        _M_vector_cost(0), _M_valid(true), _M_max_size(0) {}
65   __list2vector_info(__stack_t __stack)
66       : __object_info_base(__stack), _M_shift_count(0), _M_iterate(0),
67         _M_resize(0), _M_list_cost(0), _M_vector_cost(0), _M_valid(true),
68         _M_max_size(0) {}
69   virtual ~__list2vector_info() {}
70   __list2vector_info(const __list2vector_info& __o);
71   void __merge(const __list2vector_info& __o);
72   void __write(FILE* __f) const;
73   float __magnitude() const { return _M_list_cost - _M_vector_cost; }
74   const char* __advice() const;
75   size_t __shift_count() { return _M_shift_count; }
76   size_t __iterate()   { return _M_iterate; }
77   float __list_cost() { return _M_list_cost; }
78   size_t __resize() { return _M_resize; }
79   void __set_list_cost(float __lc) { _M_list_cost = __lc; }
80   void __set_vector_cost(float __vc) { _M_vector_cost = __vc; }
81   bool __is_valid() { return _M_valid; }
82   void __set_invalid() { _M_valid = false; }
83
84   void __opr_insert(size_t __shift, size_t __size);
85   void __opr_iterate(size_t __num) { _M_iterate += __num;}
86
87   void __resize(size_t __from, size_t __to);
88
89 private:
90   size_t _M_shift_count;
91   size_t _M_iterate;
92   size_t _M_resize;
93   float _M_list_cost;
94   float _M_vector_cost;
95   bool  _M_valid;
96   size_t _M_max_size;
97 };
98
99 inline __list2vector_info::__list2vector_info(const __list2vector_info& __o)
100     : __object_info_base(__o)
101 {
102   _M_shift_count  = __o._M_shift_count;
103   _M_iterate      = __o._M_iterate;
104   _M_vector_cost  = __o._M_vector_cost;
105   _M_list_cost    = __o._M_list_cost;
106   _M_valid        = __o._M_valid;
107   _M_resize       = __o._M_resize;
108   _M_max_size     = __o._M_max_size;
109 }
110
111 inline const char* __list2vector_info::__advice() const {
112   std::stringstream __sstream;
113   __sstream 
114       << "change std::list to std::vector and its initial size from 0 to "
115       << _M_max_size;
116   return strdup(__sstream.str().c_str());
117 }
118
119 inline void __list2vector_info::__merge(const __list2vector_info& __o)
120 {
121   _M_shift_count  += __o._M_shift_count;
122   _M_iterate      += __o._M_iterate;
123   _M_vector_cost  += __o._M_vector_cost;
124   _M_list_cost    += __o._M_list_cost;
125   _M_valid        &= __o._M_valid;
126   _M_resize       += __o._M_resize;
127   _M_max_size     = std::max( _M_max_size, __o._M_max_size);
128 }
129
130 inline void __list2vector_info::__opr_insert(size_t __shift, size_t __size) 
131 {
132   _M_shift_count += __shift;
133   _M_max_size = std::max(_M_max_size, __size);
134 }
135
136 inline void __list2vector_info::__resize(size_t __from, size_t __to)
137 {
138   _M_resize += __from;
139 }
140
141 class __list2vector_stack_info: public __list2vector_info {
142  public:
143   __list2vector_stack_info(const __list2vector_info& __o) 
144       : __list2vector_info(__o) {}
145 };
146
147 class __trace_list_to_vector
148     : public __trace_base<__list2vector_info, __list2vector_stack_info> 
149 {
150  public:
151   __trace_list_to_vector();
152   ~__trace_list_to_vector() {}
153
154   // Insert a new node at construct with object, callstack and initial size. 
155   void __insert(__object_t __obj, __stack_t __stack);
156   // Call at destruction/clean to set container final size.
157   void __destruct(const void* __obj);
158
159   // Find the node in the live map.
160   __list2vector_info* __find(const void* __obj);
161
162   // Collect cost of operations.
163   void __opr_insert(const void* __obj, size_t __shift, size_t __size);
164   void __opr_iterate(const void* __obj, size_t __num);
165   void __invalid_operator(const void* __obj);
166   void __resize(const void* __obj, size_t __from, size_t __to);
167   float __vector_cost(size_t __shift, size_t __iterate);
168   float __list_cost(size_t __shift, size_t __iterate);
169 };
170
171 inline __trace_list_to_vector::__trace_list_to_vector()
172     : __trace_base<__list2vector_info, __list2vector_stack_info>()
173 {
174   __id = "list-to-vector";
175 }
176
177 inline void __trace_list_to_vector::__insert(__object_t __obj,
178                                              __stack_t __stack)
179 {
180   __add_object(__obj, __list2vector_info(__stack));
181 }
182
183 inline void __list2vector_info::__write(FILE* __f) const
184 {
185   fprintf(__f, "%Zu %Zu %Zu %.0f %.0f\n",
186           _M_shift_count, _M_resize, _M_iterate, _M_vector_cost, _M_list_cost);
187 }
188
189 inline float __trace_list_to_vector::__vector_cost(size_t __shift, 
190                                                    size_t __iterate)
191 {
192   // The resulting vector will use a 'reserve' method.
193   return __shift * _GLIBCXX_PROFILE_DATA(__vector_shift_cost_factor).__value + 
194       __iterate * _GLIBCXX_PROFILE_DATA(__vector_iterate_cost_factor).__value; 
195 }
196
197 inline float __trace_list_to_vector::__list_cost(size_t __shift, 
198                                                  size_t __iterate)
199 {
200   return __shift * _GLIBCXX_PROFILE_DATA(__list_shift_cost_factor).__value + 
201       __iterate * _GLIBCXX_PROFILE_DATA(__list_iterate_cost_factor).__value; 
202 }
203
204 inline void __trace_list_to_vector::__destruct(const void* __obj)
205 {
206   if (!__is_on())
207     return;
208
209  __list2vector_info* __res = __get_object_info(__obj);
210   if (!__res)
211     return;
212
213   float __vc = __vector_cost(__res->__shift_count(), __res->__iterate());
214   float __lc = __list_cost(__res->__shift_count(), __res->__iterate());
215   __res->__set_vector_cost(__vc);
216   __res->__set_list_cost(__lc);
217   __retire_object(__obj);
218 }
219
220 inline void __trace_list_to_vector::__opr_insert(const void* __obj, 
221                                                  size_t __shift, size_t __size)
222 {
223   __list2vector_info* __res = __get_object_info(__obj);
224   if (__res)
225     __res->__opr_insert(__shift, __size);
226 }
227
228 inline void __trace_list_to_vector::__opr_iterate(const void* __obj,
229                                                   size_t __num)
230 {
231   __list2vector_info* __res = __get_object_info(__obj);
232   if (__res) {
233     __res->__opr_iterate(__num);
234   }
235 }
236
237 inline void __trace_list_to_vector::__invalid_operator(const void* __obj)
238 {
239   __list2vector_info* __res = __get_object_info(__obj);
240   if (__res)
241     __res->__set_invalid();
242 }
243
244 inline void __trace_list_to_vector::__resize(const void* __obj, size_t __from, 
245                                              size_t __to)
246 {
247   __list2vector_info* __res = __get_object_info(__obj);
248   if (__res)
249     __res->__resize(__from, __to);
250 }
251
252 inline void __trace_list_to_vector_init()
253 {
254   _GLIBCXX_PROFILE_DATA(_S_list_to_vector) = new __trace_list_to_vector();
255 }
256
257 inline void __trace_list_to_vector_report(FILE* __f, 
258                                           __warning_vector_t& __warnings)
259 {
260   if (_GLIBCXX_PROFILE_DATA(_S_list_to_vector)) {
261     _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__collect_warnings(__warnings);
262     _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__write(__f);
263   }
264 }
265
266 inline void __trace_list_to_vector_construct(const void* __obj)
267 {
268   if (!__profcxx_init()) return;
269
270   _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__insert(__obj, __get_stack());
271 }
272
273 inline void __trace_list_to_vector_destruct(const void* __obj)
274 {
275   if (!__profcxx_init()) return;
276
277   _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__destruct(__obj);
278 }
279
280 inline void __trace_list_to_vector_insert(const void* __obj, 
281                                           size_t __shift, size_t __size)
282 {
283   if (!__profcxx_init()) return;
284
285   _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__opr_insert(__obj, __shift, 
286                                                          __size);
287 }
288
289
290 inline void __trace_list_to_vector_iterate(const void* __obj, size_t __num = 1)
291 {
292   if (!__profcxx_init()) return;
293
294   _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__opr_iterate(__obj, __num);
295 }
296
297 inline void __trace_list_to_vector_invalid_operator(const void* __obj)
298 {
299   if (!__profcxx_init()) return;
300
301   _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__invalid_operator(__obj);
302 }
303
304 inline void __trace_list_to_vector_resize(const void* __obj, 
305                                           size_t __from, size_t __to)
306 {
307   if (!__profcxx_init()) return;
308
309   _GLIBCXX_PROFILE_DATA(_S_list_to_vector)->__resize(__obj, __from, __to);
310 }
311
312 } // namespace __gnu_profile
313 #endif /* _GLIBCXX_PROFILE_PROFILER_LIST_TO_VECTOR_H__ */