3 // Copyright (C) 2009-2014 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_vector_to_list.h
25 * @brief diagnostics for vector to list.
28 // Written by Lixia Liu and Silvius Rus.
30 #ifndef _GLIBCXX_PROFILE_PROFILER_VECTOR_TO_LIST_H
31 #define _GLIBCXX_PROFILE_PROFILER_VECTOR_TO_LIST_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 vector-to-list instrumentation line in the object table. */
40 class __vector2list_info
41 : public __object_info_base
44 __vector2list_info(__stack_t __stack
)
45 : __object_info_base(__stack
), _M_shift_count(0), _M_iterate(0),
46 _M_resize(0), _M_list_cost(0), _M_vector_cost(0)
50 __merge(const __vector2list_info
& __o
)
52 __object_info_base::__merge(__o
);
53 _M_shift_count
+= __o
._M_shift_count
;
54 _M_iterate
+= __o
._M_iterate
;
55 _M_vector_cost
+= __o
._M_vector_cost
;
56 _M_list_cost
+= __o
._M_list_cost
;
57 _M_resize
+= __o
._M_resize
;
61 __write(FILE* __f
) const
63 std::fprintf(__f
, "%Zu %Zu %Zu %.0f %.0f\n", _M_shift_count
,
64 _M_resize
, _M_iterate
, _M_vector_cost
, _M_list_cost
);
69 { return _M_vector_cost
- _M_list_cost
; }
73 { return "change std::vector to std::list"; }
77 { return _M_shift_count
; }
81 { return _M_iterate
; }
85 { return _M_list_cost
; }
92 __set_list_cost(float __lc
)
93 { _M_list_cost
= __lc
; }
96 __set_vector_cost(float __vc
)
97 { _M_vector_cost
= __vc
; }
100 __opr_insert(std::size_t __pos
, std::size_t __num
)
101 { _M_shift_count
+= __num
- __pos
; }
104 __opr_iterate(int __num
)
105 { __gnu_cxx::__atomic_add(&_M_iterate
, __num
); }
108 __resize(std::size_t __from
, std::size_t)
109 { _M_resize
+= __from
; }
112 std::size_t _M_shift_count
;
113 mutable _Atomic_word _M_iterate
;
114 std::size_t _M_resize
;
116 float _M_vector_cost
;
120 /** @brief A vector-to-list instrumentation line in the stack table. */
121 class __vector2list_stack_info
122 : public __vector2list_info
125 __vector2list_stack_info(const __vector2list_info
& __o
)
126 : __vector2list_info(__o
) { }
130 /** @brief Vector-to-list instrumentation producer. */
131 class __trace_vector_to_list
132 : public __trace_base
<__vector2list_info
, __vector2list_stack_info
>
135 __trace_vector_to_list()
136 : __trace_base
<__vector2list_info
, __vector2list_stack_info
>()
137 { __id
= "vector-to-list"; }
139 ~__trace_vector_to_list() { }
141 // Call at destruction/clean to set container final size.
143 __destruct(__vector2list_info
* __obj_info
)
145 float __vc
= __vector_cost(__obj_info
->__shift_count(),
146 __obj_info
->__iterate(),
147 __obj_info
->__resize());
148 float __lc
= __list_cost(__obj_info
->__shift_count(),
149 __obj_info
->__iterate(),
150 __obj_info
->__resize());
151 __obj_info
->__set_vector_cost(__vc
);
152 __obj_info
->__set_list_cost(__lc
);
154 __retire_object(__obj_info
);
157 // Collect cost of operations.
159 __vector_cost(std::size_t __shift
, std::size_t __iterate
,
160 std::size_t __resize
)
163 * _GLIBCXX_PROFILE_DATA(__vector_shift_cost_factor
).__value
165 * _GLIBCXX_PROFILE_DATA(__vector_iterate_cost_factor
).__value
167 * _GLIBCXX_PROFILE_DATA(__vector_resize_cost_factor
).__value
);
171 __list_cost(std::size_t __shift
, std::size_t __iterate
,
172 std::size_t __resize
)
175 * _GLIBCXX_PROFILE_DATA(__list_shift_cost_factor
).__value
177 * _GLIBCXX_PROFILE_DATA(__list_iterate_cost_factor
).__value
179 * _GLIBCXX_PROFILE_DATA(__list_resize_cost_factor
).__value
);
185 __trace_vector_to_list_init()
186 { _GLIBCXX_PROFILE_DATA(_S_vector_to_list
) = new __trace_vector_to_list(); }
189 __trace_vector_to_list_free()
190 { delete _GLIBCXX_PROFILE_DATA(_S_vector_to_list
); }
193 __trace_vector_to_list_report(FILE* __f
, __warning_vector_t
& __warnings
)
194 { __trace_report(_GLIBCXX_PROFILE_DATA(_S_vector_to_list
), __f
, __warnings
); }
196 inline __vector2list_info
*
197 __trace_vector_to_list_construct()
199 if (!__profcxx_init())
202 if (!__reentrance_guard::__get_in())
205 __reentrance_guard __get_out
;
206 return _GLIBCXX_PROFILE_DATA(_S_vector_to_list
)
207 ->__add_object(__get_stack());
211 __trace_vector_to_list_insert(__vector2list_info
* __obj_info
,
218 __obj_info
->__opr_insert(__pos
, __num
);
222 __trace_vector_to_list_iterate(__vector2list_info
* __obj_info
, int)
227 // We only collect if an iteration took place no matter in what side.
228 __obj_info
->__opr_iterate(1);
232 __trace_vector_to_list_invalid_operator(__vector2list_info
* __obj_info
)
237 __obj_info
->__set_invalid();
241 __trace_vector_to_list_resize(__vector2list_info
* __obj_info
,
248 __obj_info
->__resize(__from
, __to
);
252 __trace_vector_to_list_destruct(__vector2list_info
* __obj_info
)
257 _GLIBCXX_PROFILE_DATA(_S_vector_to_list
)->__destruct(__obj_info
);
260 } // namespace __gnu_profile
261 #endif /* _GLIBCXX_PROFILE_PROFILER_VECTOR_TO_LIST_H */