3 // Copyright (C) 2009, 2010 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 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
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.
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.
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
31 /** @file profile/impl/profiler_list_to_slist.h
32 * @brief Diagnostics for list to slist.
35 // Written by Changhee Jung.
37 #ifndef _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H
38 #define _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H 1
40 #include "profile/impl/profiler.h"
41 #include "profile/impl/profiler_node.h"
42 #include "profile/impl/profiler_trace.h"
44 namespace __gnu_profile
46 class __list2slist_info
47 : public __object_info_base
51 : _M_rewind(false), _M_operations(0) { }
53 __list2slist_info(__stack_t __stack
)
54 : __object_info_base(__stack
), _M_rewind(false), _M_operations(0) { }
56 virtual ~__list2slist_info() { }
58 __list2slist_info(const __list2slist_info
& __o
)
59 : __object_info_base(__o
), _M_rewind(__o
._M_rewind
),
60 _M_operations(__o
._M_operations
) { }
62 // XXX: the magnitude should be multiplied with a constant factor F,
63 // where F is 1 when the malloc size class of list nodes is different
64 // from the malloc size class of slist nodes. When they fall into the same
65 // class, the only slist benefit is from having to set fewer links, so
66 // the factor F should be much smaller, closer to 0 than to 1.
67 // This could be implemented by passing the size classes in the config
68 // file. For now, we always assume F to be 1.
80 __merge(const __list2slist_info
&) { }
83 __write(FILE* __f
) const
84 { std::fprintf(__f
, "%s\n", _M_rewind
? "invalid" : "valid"); }
88 { return "change std::list to std::forward_list"; }
103 { return _M_rewind
; }
107 std::size_t _M_operations
;
110 class __list2slist_stack_info
111 : public __list2slist_info
114 __list2slist_stack_info(const __list2slist_info
& __o
)
115 : __list2slist_info(__o
) { }
118 class __trace_list_to_slist
119 : public __trace_base
<__list2slist_info
, __list2slist_stack_info
>
122 ~__trace_list_to_slist() { }
124 __trace_list_to_slist()
125 : __trace_base
<__list2slist_info
, __list2slist_stack_info
>()
126 { __id
= "list-to-slist"; }
129 __opr_rewind(const void* __obj
)
131 __list2slist_info
* __res
= __get_object_info(__obj
);
133 __res
->__opr_rewind();
137 __record_operation(const void* __obj
)
139 __list2slist_info
* __res
= __get_object_info(__obj
);
141 __res
->__record_operation();
145 __insert(const __object_t __obj
, __stack_t __stack
)
146 { __add_object(__obj
, __list2slist_info(__stack
)); }
149 __destruct(const void* __obj
)
154 __list2slist_info
* __res
= __get_object_info(__obj
);
158 __retire_object(__obj
);
164 __trace_list_to_slist_init()
165 { _GLIBCXX_PROFILE_DATA(_S_list_to_slist
) = new __trace_list_to_slist(); }
168 __trace_list_to_slist_report(FILE* __f
, __warning_vector_t
& __warnings
)
170 if (_GLIBCXX_PROFILE_DATA(_S_list_to_slist
))
172 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->
173 __collect_warnings(__warnings
);
174 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->__write(__f
);
179 __trace_list_to_slist_rewind(const void* __obj
)
181 if (!__profcxx_init())
184 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->__opr_rewind(__obj
);
188 __trace_list_to_slist_operation(const void* __obj
)
190 if (!__profcxx_init())
193 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->__record_operation(__obj
);
197 __trace_list_to_slist_construct(const void* __obj
)
199 if (!__profcxx_init())
202 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->__insert(__obj
, __get_stack());
206 __trace_list_to_slist_destruct(const void* __obj
)
208 if (!__profcxx_init())
211 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->__destruct(__obj
);
214 } // namespace __gnu_profile
215 #endif /* _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H */