Gprof and shared libraries
Hi, I've a larger project that consists of several shared libraries. The compilation is done by autoconf and automake. One of the libraries seems to be slow so I would like to profile it. My idea was to use gprof (I'm using gcc 3.4.6). First, I modified the Makefiles so that each library is built with the flags "-g -pg". Next, I've set the variable LD_PROFILE to the library I want to analyze: "LD_PROFILE=/path/to/lirary.so". Then, I ran the program and got the file "gmon.out". However, when I execute "gpof MYEXECUTABLE gmon.out" all the displayed functions have a time of 0 seconds (number of calls is available) and I can't find and references to the function from the library I specified by LD_PROFILE. What am I doing wrong? I was looking in the internet for a solution but could not find any helpful hints. Thank you. Regards, Christian -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
Compiler loop optimizations
Hi, I was curious if there are any gcc compiler optimizations that can improve this code: void foo10( ) { for ( int i = 0; i < 10; ++i ) { [...] if( i == 15 ) { [BLOCK1] } } } void foo100( ) { for ( int i = 0; i < 100; ++i ) { [...] if( i == 15 ) { [BLOCK2] } } } int main( void ) { foo10( ); foo100( ); return 0; } 1) For the function foo10: The if-block following "if( i == 15 )" will be never executed since 'i' will never become 15 here. So, this entire block could be removed without changing the semantics. This would improve the program execution since the if-condition does not need to be evaluated in each loop iteration. Can this code transformation be automatically performed by a compiler? If so, which techniques/analyses and optimizations must be applied? Would gcc simplify this loop? 2) For the function foo100: This code is not optimal as well. The if-condition is just once met but has to be evaluated for all of the 100 loop iterations. An idea I had in mind was to split the loop in two parts: for ( int i = 0; i <= 15; ++i ) {...} BLOCK2 for ( int 16 = 0; i < 100; ++i ) {...} So, here the evaluation of "i==15" is not required any more and we save 100 comparisions. Is this a good idea and always applicable? Or are there better compiler optimzations? Thank you very much for your help. Regards, Chris -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer