3 // Copyright (C) 2009-2013 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_list_to_slist.h
25 * @brief Diagnostics for list to slist.
28 // Written by Changhee Jung.
30 #ifndef _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H
31 #define _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_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 class __list2slist_info
40 : public __object_info_base
44 : _M_rewind(false), _M_operations(0) { }
46 __list2slist_info(__stack_t __stack)
47 : __object_info_base(__stack), _M_rewind(false), _M_operations(0) { }
49 virtual ~__list2slist_info() { }
51 __list2slist_info(const __list2slist_info& __o)
52 : __object_info_base(__o), _M_rewind(__o._M_rewind),
53 _M_operations(__o._M_operations) { }
55 // XXX: the magnitude should be multiplied with a constant factor F,
56 // where F is 1 when the malloc size class of list nodes is different
57 // from the malloc size class of slist nodes. When they fall into the same
58 // class, the only slist benefit is from having to set fewer links, so
59 // the factor F should be much smaller, closer to 0 than to 1.
60 // This could be implemented by passing the size classes in the config
61 // file. For now, we always assume F to be 1.
73 __merge(const __list2slist_info&) { }
76 __write(FILE* __f) const
77 { std::fprintf(__f, "%s\n", _M_rewind ? "invalid" : "valid"); }
81 { return "change std::list to std::forward_list"; }
100 std::size_t _M_operations;
103 class __list2slist_stack_info
104 : public __list2slist_info
107 __list2slist_stack_info(const __list2slist_info& __o)
108 : __list2slist_info(__o) { }
111 class __trace_list_to_slist
112 : public __trace_base<__list2slist_info, __list2slist_stack_info>
115 ~__trace_list_to_slist() { }
117 __trace_list_to_slist()
118 : __trace_base<__list2slist_info, __list2slist_stack_info>()
119 { __id = "list-to-slist"; }
122 __opr_rewind(const void* __obj)
124 __list2slist_info* __res = __get_object_info(__obj);
126 __res->__opr_rewind();
130 __record_operation(const void* __obj)
132 __list2slist_info* __res = __get_object_info(__obj);
134 __res->__record_operation();
138 __insert(const __object_t __obj, __stack_t __stack)
139 { __add_object(__obj, __list2slist_info(__stack)); }
142 __destruct(const void* __obj)
147 __list2slist_info* __res = __get_object_info(__obj);
151 __retire_object(__obj);
157 __trace_list_to_slist_init()
158 { _GLIBCXX_PROFILE_DATA(_S_list_to_slist) = new __trace_list_to_slist(); }
161 __trace_list_to_slist_report(FILE* __f, __warning_vector_t& __warnings)
163 if (_GLIBCXX_PROFILE_DATA(_S_list_to_slist))
165 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->
166 __collect_warnings(__warnings);
167 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__write(__f);
172 __trace_list_to_slist_rewind(const void* __obj)
174 if (!__profcxx_init())
177 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__opr_rewind(__obj);
181 __trace_list_to_slist_operation(const void* __obj)
183 if (!__profcxx_init())
186 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__record_operation(__obj);
190 __trace_list_to_slist_construct(const void* __obj)
192 if (!__profcxx_init())
195 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__insert(__obj, __get_stack());
199 __trace_list_to_slist_destruct(const void* __obj)
201 if (!__profcxx_init())
204 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__destruct(__obj);
207 } // namespace __gnu_profile
208 #endif /* _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H */