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
SOUM Corporation
NetBSD luna.local 9.2 NetBSD 9.2 (GENERIC) #0: Wed May 12 13:15:55 UTC 2021 amd64
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.
Compile a multi-threaded application with -pg option.
Run it and use gprof(1) to show the profiling result.
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)
 		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