NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/56246: gprof(1) never show call graphs when profiling multi-threaded application
>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: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jun 15 01:25:00 +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@localhost:/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));
Home |
Main Index |
Thread Index |
Old Index