public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Help with -finstrument-functions
@ 2005-11-12  7:19 thulasidhar
  0 siblings, 0 replies; 4+ messages in thread
From: thulasidhar @ 2005-11-12  7:19 UTC (permalink / raw)
  To: gcc-help


Hi,
I am facing a strange problem when I tried to profile the call trace of my application using -finstrument-functions switch in gcc.

We have our application built as a shared library and we use python scripting language to test all the interfaces provided by this shared library.
It is the call trace of this shared library that I want to print.

When I create an executable by linking this shared library to a main.o (as follows), I get the call trace.
$ gcc main.o libtest_app.so -o app
$ app

This main.o contains only a main function that calls one of the interfaces present in libtest_app.so.

But when I import this shared library (libtest_app.so) into python, I do not get the call trace.

I analyzed the scenario in detail and these are my observations.
I have defined the functions __cyg_profile_func_enter and __cyg_profile_func_exit in my application, and I can see them in nm output.

$ nm libtest_app.so | grep __cyg
00177518 T __cyg_profile_func_enter
001775c4 T __cyg_profile_func_exit

Case 1: When I debug my application, built as an exe (app) I see that whenever it enters any function, it jumps to these above defined functions in libtest_app.so

Case 2: But when I debug my application, imported as an module in python, I see that whenever it enters any function it jumps to some symbol of the same name (__cyg_profile_func_enter) in glibc (source filename is displayed as noophooks.c).

The library is the same in both cases. What I don't understand is that if the shared library is built and linked, why should a reference to one function (__cyg_profile_func_enter) result in different jumps in different situations. Ideally all jumps to __cyg_profile_func_enter should have been resolved to refer to the symbol defined in my library, when I build the shared library (as follows),
$ gcc -shared -L/usr/lib/python2.2/config -lpython2.2 -o test/lib/libtest_app.so -lapp.a -lpthread -lrt -lm -ldl -lutil

Why doesn't this happen in the second case? Am I missing something here?

GCC version 3.3.1


Warm regards,
Thulasidhar J.K 






The information contained in this e-mail message and in any annexure is
confidential to the  recipient and may contain privileged information. If you are not
the intended recipient, please notify the sender and delete the message along with
any annexure. You should not disclose, copy or otherwise use the information contained
in the message or any annexure. Any views expressed in this e-mail are those of the
individual sender except where the sender specifically states them to be the views of
SoCrates Software India Pvt Ltd., Bangalore.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: help with -finstrument-functions
  2021-04-04  8:29 help " Akshit Sharma
  2021-04-04 20:58 ` Thomas Bleher
@ 2021-04-05  9:21 ` Jonathan Wakely
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2021-04-05  9:21 UTC (permalink / raw)
  To: Akshit Sharma; +Cc: gcc-help

On Sun, 4 Apr 2021, 09:31 Akshit Sharma via Gcc-help, <gcc-help@gcc.gnu.org>
wrote:

> I am trying to profile the program with gcc. I am inserting the data into
> an array which is later used to generate a file.
>
> I am having a problem using template class (std::atomic<int>). Program is
> multithreaded. So, I need to use atomics.
> Right now, the __cyg_profile_func_enter is called for
> std::__atomic_base<int>::operator++ as well.
>
> I even tried setting the compile parameters to ignore it with:
> -finstrument-functions
>
> "-finstrument-functions-exclude-function-list=std::__atomic_base<int>::operator++>"
>

Looks like you have a stray '>' here, but I would expect that you have to
use the mangled name for C++ functions.



> But I am unable to make the compiler ignore the function.
> Is there a way for the compiler to make ignore a predefined function?
>


N.B. this function is not "predefined", it's defined in the C++ Standard
Library.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: help with -finstrument-functions
  2021-04-04  8:29 help " Akshit Sharma
@ 2021-04-04 20:58 ` Thomas Bleher
  2021-04-05  9:21 ` Jonathan Wakely
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas Bleher @ 2021-04-04 20:58 UTC (permalink / raw)
  To: gcc-help

* Akshit Sharma via Gcc-help <gcc-help@gcc.gnu.org> [2021-04-04 10:30]:
> I am trying to profile the program with gcc. I am inserting the data into
> an array which is later used to generate a file.
>
> I am having a problem using template class (std::atomic<int>). Program is
> multithreaded. So, I need to use atomics.

Depending on how you manage your threads, you might be able to avoid
atomics in __cyg_profile_func_* by using thread-local variables.

E.g. collect all data per-thread in thread-local variables. Then disable
profiling (you can't disable the calls to __cyg_profile_func_*, but you
can exit immediately at the top of the function if a flag is set), and
copy the data to global storage. This can work if you have control over
all your threads.

Hope this helps you.
Thomas


^ permalink raw reply	[flat|nested] 4+ messages in thread

* help with -finstrument-functions
@ 2021-04-04  8:29 Akshit Sharma
  2021-04-04 20:58 ` Thomas Bleher
  2021-04-05  9:21 ` Jonathan Wakely
  0 siblings, 2 replies; 4+ messages in thread
From: Akshit Sharma @ 2021-04-04  8:29 UTC (permalink / raw)
  To: gcc-help

I am trying to profile the program with gcc. I am inserting the data into
an array which is later used to generate a file.

I am having a problem using template class (std::atomic<int>). Program is
multithreaded. So, I need to use atomics.
Right now, the __cyg_profile_func_enter is called for
std::__atomic_base<int>::operator++ as well.

I even tried setting the compile parameters to ignore it with:
-finstrument-functions
"-finstrument-functions-exclude-function-list=std::__atomic_base<int>::operator++>"

But I am unable to make the compiler ignore the function.
Is there a way for the compiler to make ignore a predefined function?

Any pointers about using the __cyg_profile_func_* functionality will be
helpful.

Thanks,
- Akshit

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-05  9:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-12  7:19 Help with -finstrument-functions thulasidhar
2021-04-04  8:29 help " Akshit Sharma
2021-04-04 20:58 ` Thomas Bleher
2021-04-05  9:21 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).