This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcov can't collect data when process is executed by systemctl start but it can when executed by ./process
- From: Xiaoli Feng <xifeng at redhat dot com>
- To: Xi Ruoyao <ryxi at stu dot xidian dot edu dot cn>
- Cc: Mason <slash dot tmp at free dot fr>, GCC help <gcc-help at gcc dot gnu dot org>
- Date: Mon, 31 Jul 2017 22:51:14 -0400 (EDT)
- Subject: Re: gcov can't collect data when process is executed by systemctl start but it can when executed by ./process
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=xifeng at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 60D7813B72C
- References: <809232575.31313906.1501491302667.JavaMail.zimbra@redhat.com> <312354067.31314219.1501491465219.JavaMail.zimbra@redhat.com> <90cc5d01-5747-1aad-1006-cbd1c05e876a@free.fr> <1946892081.31324950.1501495541743.JavaMail.zimbra@redhat.com> <1501499082.2281.1.camel@stu.xidian.edu.cn>
----- Original Message -----
> From: "Xi Ruoyao" <ryxi@stu.xidian.edu.cn>
> To: "Xiaoli Feng" <xifeng@redhat.com>, "Mason" <slash.tmp@free.fr>
> Cc: ryxi@stu.xidian.edu.cn, "GCC help" <gcc-help@gcc.gnu.org>
> Sent: Monday, July 31, 2017 7:04:42 PM
> Subject: Re: gcov can't collect data when process is executed by systemctl start but it can when executed by
> ./process
>
> On 2017-07-31一的 06:05 -0400, Xiaoli Feng wrote:
> >
> > ----- Original Message -----
> > > From: "Mason" <slash.tmp@free.fr>
> > > To: "Xiaoli Feng" <xifeng@redhat.com>
> > > Cc: "GCC help" <gcc-help@gcc.gnu.org>
> > > Sent: Monday, July 31, 2017 5:12:38 PM
> > > Subject: Re: gcov can't collect data when process is executed by
> > > systemctl start but it can when executed by
> > > ./process
> > >
> > > On 31/07/2017 10:57, Xiaoli Feng wrote:
> > > > Hello,
> > > >
> > > > Sorry to noise you. But I don't know how to fixed this issue. The
> > > > gcov
> > > > can
> > > > collect code coverage data if the process is executed in shell. But
> > > > when
> > > > the process is start by systemd service. The *.gcda can't be generated.
> > > > I
> > > > google
> > > > many info. But there is no solution. So I only send mail to ask for
> > > > your
> > > > help.
> > > > Does any one know what's happen? And where to find the gcov error
> > > > message?
>
> By default systemd terminates a service by sending SIGTERM.
> (See systemd.kill(5).) If your service doesn't handle it and will just be
> killed, it won't produce .gcda file.
>
> Your service should handle SIGTERM and terminate cleanly, like:
>
> void handler(int signum)
> {
> /* notify the operator that the service has receive SIGTERM
> and clean up (close file descriptors, etc). */
>
> exit(0);
> }
>
> int main(int argc, char **argv)
> {
> signal(handler, SIGTERM);
>
> /* do service */
> }
>
> By using exit(), the functions registered by atexit() and on_exit() would be
> called. GCC registers one atexit function to produce .gcda file.
>
> Even if without gcov, it's recommended to catch SIGTERM and terminate your
> service cleanly.
Thanks Xi Ruoyao so much. I have a question. Is *.gcda file only created when
process exit? I did a test. Ran the process. Keep it running. Then check if *.gcda
is generated. And it did acturally. So if it is started by systemd. And keep running.
I think it will generate *.gcda. But it doesn't. I check the namespaces of two processes.
They are the same.
>
> > > > If I send the wrong email address. Sorry about that.
>
> This is the correct mail list to request help using GCC. And I think maybe
> we should document this issue somewhere (in 'info gcc' or GCC wiki).
>
> > > Could it be that when the process is run by systemd, it runs
> > > under a different user id, one which is not allowed to write
> > > to the directory?
> >
> > I don't think so. I run "ps -aux". And it shows the process's USER is
> > root.
> > Do you know if there is a method to check the error info when generate
> > *.gcda?
> > And if it is under a different user. How could I change the writing
> > directory
> > location?
>
> If I am correct, there should be no error info available since the process
> was
> killed suddenly and had no chance to print out something.
>
> > Thanks Mason for your reply.
> >
> > >
> > > Regards.
> > >
> --
> Xi Ruoyao <ryxi@stu.xidian.edu.cn>
> School of Aerospace Science and Technology, Xidian University
>