|
From: Nicholas N. <n.n...@gm...> - 2009-06-01 23:01:24
|
On Mon, Jun 1, 2009 at 6:59 PM, Sitos Lin <sit...@gm...> wrote:
> Dear all:
> The valgrind tool can instrument the program at the beginning of
> execution by the command: valgrind .... However, how can I instrument
> the running program? Because I want to skip the initialization phase
> of the program and only profile the main function of the program by
> valgrind tool. I know Pin can instrument the running program with a
> specific pid. Can valgrind do this? Thank you.
There's an entry in the FAQ about this, but it's still only on the SVN
trunk and not in any releases. I've just added it to the 3.4.X branch
so it will be in 3.4.2 if/when that is released.
<qandaentry id="faq.attach">
<question id="q-attach">
<para>Is it possible to attach Valgrind to a program that is already
running?</para>
</question>
<answer id="a-attach">
<para>No. The environment that Valgrind provides for running programs
is significantly different to that for normal programs, e.g. due to
different layout of memory. Therefore Valgrind has to have full control
from the very start.</para>
<para>It is possible to achieve something like this by running your
program without any instrumentation (which involves a slow-down of about
5x, less than that of most tools), and then adding instrumentation once
you get to a point of interest. Support for this must be provided by
the tool, however, and Callgrind is the only tool that currently has
such support. See the instructions on the
<computeroutput>callgrind_control</computeroutput> program for details.
</para>
</answer>
</qandaentry>
Nick
|