libstdc++
|
00001 // -*- C++ -*- 00002 // 00003 // Copyright (C) 2009, 2010 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License along 00021 // with this library; see the file COPYING3. If not see 00022 // <http://www.gnu.org/licenses/>. 00023 00024 /** @file profile/impl/profiler_list_to_slist.h 00025 * @brief Diagnostics for list to slist. 00026 */ 00027 00028 // Written by Changhee Jung. 00029 00030 #ifndef _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H 00031 #define _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H 1 00032 00033 #include "profile/impl/profiler.h" 00034 #include "profile/impl/profiler_node.h" 00035 #include "profile/impl/profiler_trace.h" 00036 00037 namespace __gnu_profile 00038 { 00039 class __list2slist_info 00040 : public __object_info_base 00041 { 00042 public: 00043 __list2slist_info() 00044 : _M_rewind(false), _M_operations(0) { } 00045 00046 __list2slist_info(__stack_t __stack) 00047 : __object_info_base(__stack), _M_rewind(false), _M_operations(0) { } 00048 00049 virtual ~__list2slist_info() { } 00050 00051 __list2slist_info(const __list2slist_info& __o) 00052 : __object_info_base(__o), _M_rewind(__o._M_rewind), 00053 _M_operations(__o._M_operations) { } 00054 00055 // XXX: the magnitude should be multiplied with a constant factor F, 00056 // where F is 1 when the malloc size class of list nodes is different 00057 // from the malloc size class of slist nodes. When they fall into the same 00058 // class, the only slist benefit is from having to set fewer links, so 00059 // the factor F should be much smaller, closer to 0 than to 1. 00060 // This could be implemented by passing the size classes in the config 00061 // file. For now, we always assume F to be 1. 00062 00063 float 00064 __magnitude() const 00065 { 00066 if (!_M_rewind) 00067 return _M_operations; 00068 else 00069 return 0; 00070 } 00071 00072 void 00073 __merge(const __list2slist_info&) { } 00074 00075 void 00076 __write(FILE* __f) const 00077 { std::fprintf(__f, "%s\n", _M_rewind ? "invalid" : "valid"); } 00078 00079 std::string 00080 __advice() const 00081 { return "change std::list to std::forward_list"; } 00082 00083 void 00084 __opr_rewind() 00085 { 00086 _M_rewind = true; 00087 _M_valid = false; 00088 } 00089 00090 void 00091 __record_operation() 00092 { ++_M_operations; } 00093 00094 bool 00095 __has_rewind() 00096 { return _M_rewind; } 00097 00098 private: 00099 bool _M_rewind; 00100 std::size_t _M_operations; 00101 }; 00102 00103 class __list2slist_stack_info 00104 : public __list2slist_info 00105 { 00106 public: 00107 __list2slist_stack_info(const __list2slist_info& __o) 00108 : __list2slist_info(__o) { } 00109 }; 00110 00111 class __trace_list_to_slist 00112 : public __trace_base<__list2slist_info, __list2slist_stack_info> 00113 { 00114 public: 00115 ~__trace_list_to_slist() { } 00116 00117 __trace_list_to_slist() 00118 : __trace_base<__list2slist_info, __list2slist_stack_info>() 00119 { __id = "list-to-slist"; } 00120 00121 void 00122 __opr_rewind(const void* __obj) 00123 { 00124 __list2slist_info* __res = __get_object_info(__obj); 00125 if (__res) 00126 __res->__opr_rewind(); 00127 } 00128 00129 void 00130 __record_operation(const void* __obj) 00131 { 00132 __list2slist_info* __res = __get_object_info(__obj); 00133 if (__res) 00134 __res->__record_operation(); 00135 } 00136 00137 void 00138 __insert(const __object_t __obj, __stack_t __stack) 00139 { __add_object(__obj, __list2slist_info(__stack)); } 00140 00141 void 00142 __destruct(const void* __obj) 00143 { 00144 if (!__is_on()) 00145 return; 00146 00147 __list2slist_info* __res = __get_object_info(__obj); 00148 if (!__res) 00149 return; 00150 00151 __retire_object(__obj); 00152 } 00153 }; 00154 00155 00156 inline void 00157 __trace_list_to_slist_init() 00158 { _GLIBCXX_PROFILE_DATA(_S_list_to_slist) = new __trace_list_to_slist(); } 00159 00160 inline void 00161 __trace_list_to_slist_report(FILE* __f, __warning_vector_t& __warnings) 00162 { 00163 if (_GLIBCXX_PROFILE_DATA(_S_list_to_slist)) 00164 { 00165 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)-> 00166 __collect_warnings(__warnings); 00167 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__write(__f); 00168 } 00169 } 00170 00171 inline void 00172 __trace_list_to_slist_rewind(const void* __obj) 00173 { 00174 if (!__profcxx_init()) 00175 return; 00176 00177 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__opr_rewind(__obj); 00178 } 00179 00180 inline void 00181 __trace_list_to_slist_operation(const void* __obj) 00182 { 00183 if (!__profcxx_init()) 00184 return; 00185 00186 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__record_operation(__obj); 00187 } 00188 00189 inline void 00190 __trace_list_to_slist_construct(const void* __obj) 00191 { 00192 if (!__profcxx_init()) 00193 return; 00194 00195 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__insert(__obj, __get_stack()); 00196 } 00197 00198 inline void 00199 __trace_list_to_slist_destruct(const void* __obj) 00200 { 00201 if (!__profcxx_init()) 00202 return; 00203 00204 _GLIBCXX_PROFILE_DATA(_S_list_to_slist)->__destruct(__obj); 00205 } 00206 00207 } // namespace __gnu_profile 00208 #endif /* _GLIBCXX_PROFILE_PROFILER_LIST_TO_SLIST_H */