3 // Copyright (C) 2009 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 #ifdef __GXX_EXPERIMENTAL_CXX0X__
49 #include "profile/impl/profiler.h"
50 #include "profile/impl/profiler_node.h"
51 #include "profile/impl/profiler_trace.h"
53 namespace __gnu_profile
56 class __list2slist_info
: public __object_info_base
59 __list2slist_info() : _M_rewind(false), _M_operations(0) {}
60 __list2slist_info(__stack_t __stack
)
61 : _M_rewind(false), _M_operations(0),__object_info_base(__stack
) {}
62 virtual ~__list2slist_info() {}
63 __list2slist_info(const __list2slist_info
& __o
) : __object_info_base(__o
)
64 { _M_rewind
= __o
._M_rewind
; _M_operations
= __o
._M_operations
; }
65 // XXX: the magnitude should be multiplied with a constant factor F,
66 // where F is 1 when the malloc size class of list nodes is different
67 // from the malloc size class of slist nodes. When they fall into the same
68 // class, the only slist benefit is from having to set fewer links, so
69 // the factor F should be much smaller, closer to 0 than to 1.
70 // This could be implemented by passing the size classes in the config file.
71 // For now, we always assume F to be 1.
72 float __magnitude() const
73 { if (!_M_rewind
) return _M_operations
; else return 0; }
74 void __merge(const __list2slist_info
& __o
) {};
75 void __write(FILE* __f
) const;
76 const char* __advice() const
77 { return strdup("change std::list to std::forward_list"); }
78 void __opr_rewind() { _M_rewind
= true; _M_valid
= false;}
79 void __record_operation() { _M_operations
++; }
80 bool __has_rewind() { return _M_rewind
; }
87 class __list2slist_stack_info
: public __list2slist_info
{
89 __list2slist_stack_info(const __list2slist_info
& __o
)
90 : __list2slist_info(__o
) {}
93 class __trace_list_to_slist
94 : public __trace_base
<__list2slist_info
, __list2slist_stack_info
>
97 ~__trace_list_to_slist() {}
98 __trace_list_to_slist()
99 : __trace_base
<__list2slist_info
, __list2slist_stack_info
>()
100 { __id
= "list-to-slist"; }
101 void __opr_rewind(const void* __obj
);
102 void __record_operation(const void* __obj
);
103 void __insert(const __object_t __obj
, __stack_t __stack
)
104 { __add_object(__obj
, __list2slist_info(__stack
)); }
105 void __destruct(const void* __obj
);
108 inline void __list2slist_info::__write(FILE* __f
) const
110 fprintf(__f
, "%s\n", _M_rewind
? "invalid" : "valid");
113 inline void __trace_list_to_slist::__destruct(const void* __obj
)
118 __list2slist_info
* __res
= __get_object_info(__obj
);
122 __retire_object(__obj
);
125 inline void __trace_list_to_slist_init()
127 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
) = new __trace_list_to_slist();
130 inline void __trace_list_to_slist_report(FILE* __f
,
131 __warning_vector_t
& __warnings
)
133 if (_GLIBCXX_PROFILE_DATA(_S_list_to_slist
)) {
134 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->__collect_warnings(__warnings
);
135 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->__write(__f
);
139 inline void __trace_list_to_slist::__opr_rewind(const void* __obj
)
141 __list2slist_info
* __res
= __get_object_info(__obj
);
143 __res
->__opr_rewind();
146 inline void __trace_list_to_slist::__record_operation(const void* __obj
)
148 __list2slist_info
* __res
= __get_object_info(__obj
);
150 __res
->__record_operation();
153 inline void __trace_list_to_slist_rewind(const void* __obj
)
155 if (!__profcxx_init()) return;
157 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->__opr_rewind(__obj
);
160 inline void __trace_list_to_slist_operation(const void* __obj
)
162 if (!__profcxx_init()) return;
164 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->__record_operation(__obj
);
167 inline void __trace_list_to_slist_construct(const void* __obj
)
169 if (!__profcxx_init()) return;
171 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->__insert(__obj
, __get_stack());
174 inline void __trace_list_to_slist_destruct(const void* __obj
)
176 if (!__profcxx_init()) return;
178 _GLIBCXX_PROFILE_DATA(_S_list_to_slist
)->__destruct(__obj
);
181 } // namespace __gnu_profile
182 #endif /* _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H */