I'm teaching a course on C++ 11 and Linux this fall, and wanted to show the students gprof, so I built a little "word count" program with multiple threads; it runs blazingly quickly and mostly spends its time incrementing counters in an std::map<string, int>.
The issue is gprof: A natural thing is to show them how a profiler helps us optimize, but when I run gprof it crashes (surprises me, given the maturity of the tool!). The very long C++-generated method names must be causing some form of buffer overflow. Here's an example (it sort of survives the flat trace and call-graph printouts, but the output is unintelligible, then dies printing the index):
... Flat profile:
Each sample counts as 0.01 seconds. no time accumulated
% cumulative self self total time seconds seconds calls Ts/call Ts/call name 0.00 0.00 0.00 6015772 0.00 0.00 std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> > >::_M_get_insert_hint_unique_pos(std::_Rb_tree_const_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) 0.00 0.00 0.00 151 0.00 0.00 std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> > >::_M_erase(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >*) 0.00 0.00 0.00 9 0.00 0.00 std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> > >::_M_get_insert_unique_pos(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) 0.00 0.00 0.00 1 0.00 0.00 _GLOBAL__sub_I_lock 0.00 0.00 0.00 1 0.00 0.00 std::_Rb_tree<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int>, std::_Select1st<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> >, DefineSortOrder, std::allocator<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> > >::_M_get_insert_unique_pos(std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const&)
... call-graph analysis:
granularity: each sample hit covers 2 byte(s) no time propagated
index % time self children called name 0.00 0.00 6015772/6015772 wcounter(int) [14] [8] 0.0 0.00 0.00 6015772 std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> > >::_M_get_insert_hint_unique_pos(std::_Rb_tree_const_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) [8]
1268806 std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> > >::_M_erase(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> >*) [9]
0.00 0.00 151/151 __tcf_1 [32]
[9] 0.0 0.00 0.00 151+1268806 std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> > >::_M_erase(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >) [9] 1268806 std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> > >::_M_erase(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >) [9]
0.00 0.00 1/9 __tcf_1 [32]
0.00 0.00 8/9 wcounter(int) [14]
[10] 0.0 0.00 0.00 9 std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> > >::_M_get_insert_unique_pos(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) [10]
0.00 0.00 1/1 __libc_csu_init [30]
[11] 0.0 0.00 0.00 1 _GLOBAL__sub_I_lock [11]
0.00 0.00 1/1 std::map<std::pair<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, int, DefineSortOrder, std::allocator<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const, int> > >::operator[](std::pair<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&) [17]
[12] 0.0 0.00 0.00 1 std::_Rb_tree<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int>, std::_Select1st<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> >, DefineSortOrder, std::allocator<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> > >::_M_get_insert_unique_pos(std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const&) [12]
463280 std::_Rb_tree<std::pair<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const, int>, std::_Select1st<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const, int> >, DefineSortOrder, std::allocator<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const, int> > >::_M_erase(std::_Rb_tree_node<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const, int> >*) [24]
[24] 0.0 0.00 0.00 0+463280 std::_Rb_tree<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int>, std::_Select1st<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> >, DefineSortOrder, std::allocator<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> > >::_M_erase(std::_Rb_tree_node<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> >) [24] 463280 std::_Rb_tree<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int>, std::_Select1st<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> >, DefineSortOrder, std::allocator<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> > >::_M_erase(std::_Rb_tree_node<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> >) [24]
This table describes the call tree of the program.... Index by function name
[11] _GLOBAL__sub_I_lock [8] std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> > >::_M_get_insert_hint_unique_pos(std::_Rb_tree_const_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) [12] std::_Rb_tree<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int>, std::_Select1st<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> >, DefineSortOrder, std::allocator<std::pair<std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const, int> > >::_M_get_insert_unique_pos(std::pair<int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > const&) [10] std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> > >::_M_get_insert_unique_pos(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) [9] std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> > >::_M_erase(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> >*) ken@kenM6800:~/fast-wc$
This can't be a "new" problem... what are people using to profile C++ applications these days?
Aucun commentaire:
Enregistrer un commentaire