1

I have a "big precompiled program" which calls a Tcl script, which calls another (my) C program. Trying to clarify, the scenario looks like:

Big Precompiled Program (BPP) ----> Tcl script ----> my C program (MCP)

I want to run a profiling only in MCP but it have not the ability to run in a standalone mode (i.e. it has no main function).

I used the -pg option in gcc when I compiled MCP, but when I run the BPP, no gmon.out was created. Should I search a way to compile also BPP with -pg or there is another way?

EDIT:

The BPP should have a main loop inside. BPP call the entire Tcl script prior to the loop for initialization stuff (faster), but then, in each iteration BPP call only one process defined in this script. At the same time, this Tcl process call the main function of my MCP. So, I want to profile only MCP, since the Tcl script don't make any relevant operation, is just like a conector.

alexis
  • 410
  • 4
  • 18
  • 1
    If your MCP does not have a `main()` function, it is not really a 'program'; by definition, programs have a `main()` somewhere. So, that suggests MCP is really a module loaded by Tcl — some sort of shared library. Further, Tcl was originally designed to be embedded in other programs, so there is a possibility that BPP includes a Tcl interpreter, and that Tcl interpreter then loads and runs the code from MCP. You need to clarify what really happens, because you will need profiling in either Tcl or BPP if my analysis is correct. – Jonathan Leffler Sep 03 '14 at 00:14
  • Yes, I think that your interpretation is the correct one. I will edit my question to clarify these points, as you suggest. – alexis Sep 03 '14 at 12:39
  • 1
    Run MCP by itself under GDB and [*do this*](http://stackoverflow.com/a/378024/23771). If it completes in a very short time, add a temporary outer loop to it, so it runs long enough to sample. – Mike Dunlavey Sep 03 '14 at 14:29
  • What do you mean by "run MCP by itself under GDB"? Is it compile MCP with `-g` and run BPP? By the way, really clever way to profiling! However, I need to know why the benchmark goes from 0.5 seconds per iteration to 0.6... Do you think that the Bayesian method will detect the difference? – alexis Sep 03 '14 at 22:58
  • 1
    MCP has a `main` function, right? At the command line type `gdb MCP`. Type `r` to run it. While it's running type ^C to interrupt it, `thread 1` to put it on the main thread, and `bt` to get a backtrace. *Look At It* (sometimes people don't). Do this like 10 times. Any line of code on X percent of the stacks, if you could comment it out, would give you a speedup multiple of 100/(100-X) roughly. Like if the line is on 60% of stacks, commenting it out would give you about 2.5x speedup. I.e. try to avoid making the calls that are costing a large fraction of time. – Mike Dunlavey Sep 04 '14 at 14:53
  • Oh! I caught the idea now. Thanks a lot. – alexis Sep 04 '14 at 15:35

0 Answers0