NetBSD Problem Report #56246
From www@netbsd.org Tue Jun 15 01:22:06 2021
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 1977D1A921F
for <gnats-bugs@gnats.NetBSD.org>; Tue, 15 Jun 2021 01:22:06 +0000 (UTC)
Message-Id: <20210615012204.7F13E1A923B@mollari.NetBSD.org>
Date: Tue, 15 Jun 2021 01:22:04 +0000 (UTC)
From: naito.yuichiro@gmail.com
Reply-To: naito.yuichiro@gmail.com
To: gnats-bugs@NetBSD.org
Subject: gprof(1) never show call graphs when profiling multi-threaded application
X-Send-Pr-Version: www-1.0
>Number: 56246
>Category: lib
>Synopsis: gprof(1) never show call graphs when profiling multi-threaded application
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: lib-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jun 15 01:25:00 +0000 2021
>Closed-Date: Sat Jul 03 14:09:32 +0000 2021
>Last-Modified: Sat Jul 03 14:10:02 +0000 2021
>Originator: Yuichiro Naito
>Release: NetBSD 9.2
>Organization:
SOUM Corporation
>Environment:
NetBSD luna.local 9.2 NetBSD 9.2 (GENERIC) #0: Wed May 12 13:15:55 UTC 2021 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
When an application is compiled with -pg option for profiling the performance,
'_mcount' function is called at the beginning of each functions.
If the application is running in multi-thread,
'_mcount' function allocates gmonparam buffer for each individual thread.
While allocating the buffer, the original buffer '_gmonparam' state is changed
to 'BUSY', and the state always copied to the new buffer.
The 'BUSY' state prevents counting number of calls in '_mcount' function.
As a result, '_mcount' never count up number of function calls.
>How-To-Repeat:
Compile a multi-threaded application with -pg option.
Run it and use gprof(1) to show the profiling result.
>Fix:
The solution is quite simple.
Changing the state of new buffer to 'GMON_PROF_ON'.
Here is a patch for it.
diff --git a/lib/libc/gmon/gmon.c b/lib/libc/gmon/gmon.c
index 7ca410ed3615..0ffa07ff53bc 100644
--- a/lib/libc/gmon/gmon.c
+++ b/lib/libc/gmon/gmon.c
@@ -231,6 +231,7 @@ _m_gmon_alloc(void)
PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, (off_t)0);
p = (void *)cp;
*p = _gmonparam;
+ p->state = GMON_PROF_ON;
p->kcount = NULL;
cp += sizeof (struct gmonparam);
memset(cp, 0, (size_t)(p->fromssize + p->tossize));
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: christos@NetBSD.org
State-Changed-When: Sat, 03 Jul 2021 10:09:32 -0400
State-Changed-Why:
committed, thanks!
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/56246 CVS commit: src/lib/libc/gmon
Date: Sat, 3 Jul 2021 10:08:55 -0400
Module Name: src
Committed By: christos
Date: Sat Jul 3 14:08:55 UTC 2021
Modified Files:
src/lib/libc/gmon: gmon.c
Log Message:
PR/56246: Yuichiro Naito: gprof(1) never show call graphs when profiling
multi-threaded application
To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/lib/libc/gmon/gmon.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.