@@ -61,6 +61,10 @@ limitations under the License. */
61
61
#endif // __APPLE__
62
62
#endif // PADDLE_WITH_CUDA
63
63
64
+ // Note: these headers for simplify demangle type string
65
+ #include " paddle/fluid/framework/type_defs.h"
66
+ #include " paddle/fluid/imperative/type_defs.h"
67
+
64
68
namespace paddle {
65
69
namespace platform {
66
70
@@ -189,6 +193,35 @@ struct BinaryCompareMessageConverter<false> {
189
193
};
190
194
} // namespace details
191
195
196
+ template <typename T>
197
+ inline std::string ReplaceComplexTypeStr (std::string str,
198
+ const std::string& type_name) {
199
+ auto demangle_type_str = demangle (typeid (T).name ());
200
+ size_t start_pos = 0 ;
201
+ while ((start_pos = str.find (demangle_type_str, start_pos)) !=
202
+ std::string::npos) {
203
+ str.replace (start_pos, demangle_type_str.length (), type_name);
204
+ start_pos += type_name.length ();
205
+ }
206
+ return str;
207
+ }
208
+
209
+ #define __REPLACE_COMPLEX_TYPE_STR__ (__TYPENAME, __STR ) \
210
+ do { \
211
+ __STR = paddle::platform::ReplaceComplexTypeStr<__TYPENAME>(__STR, \
212
+ #__TYPENAME); \
213
+ } while (0 )
214
+
215
+ inline std::string SimplifyDemangleStr (std::string str) {
216
+ // the older is important, you have to put complex types in front
217
+ __REPLACE_COMPLEX_TYPE_STR__ (paddle::framework::AttributeMap, str);
218
+ __REPLACE_COMPLEX_TYPE_STR__ (paddle::framework::Attribute, str);
219
+ __REPLACE_COMPLEX_TYPE_STR__ (paddle::imperative::NameVariableWrapperMap, str);
220
+ __REPLACE_COMPLEX_TYPE_STR__ (paddle::imperative::NameVarBaseMap, str);
221
+ __REPLACE_COMPLEX_TYPE_STR__ (std::string, str);
222
+ return str;
223
+ }
224
+
192
225
template <typename StrType>
193
226
inline std::string GetTraceBackString (StrType&& what, const char * file,
194
227
int line) {
@@ -210,7 +243,8 @@ inline std::string GetTraceBackString(StrType&& what, const char* file,
210
243
std::string path (info.dli_fname );
211
244
// C++ traceback info are from core.so
212
245
if (path.substr (path.length () - 3 ).compare (" .so" ) == 0 ) {
213
- sout << string::Sprintf (" %-3d %s\n " , idx++, demangled);
246
+ sout << string::Sprintf (" %-3d %s\n " , idx++,
247
+ SimplifyDemangleStr (demangled));
214
248
}
215
249
}
216
250
}
0 commit comments