mdbx: enable solib profiling with -pg and gprof with GLIBC >= 2.37.

However such profiling requires https://sourceware.org/bugzilla/show_bug.cgi?id=29438 to be fixed.
This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2022-08-04 14:28:35 +03:00
parent a44eb1accb
commit 77635116c6
3 changed files with 37 additions and 2 deletions

View File

@ -1459,7 +1459,8 @@ __cold void mdbx_rthc_global_init(void) {
}
bootid = mdbx_osal_bootid();
#if 0 /* debug */
#if 0 /* debug */
for (unsigned i = 0; i < 65536; ++i) {
size_t pages = pv2pages(i);
unsigned x = pages2pv(pages);
@ -1469,7 +1470,7 @@ __cold void mdbx_rthc_global_init(void) {
assert(pages == xp);
}
fflush(stdout);
#endif
#endif /* #if 0 */
}
/* dtor called for thread, i.e. for all mdbx's environment objects */
@ -1547,6 +1548,7 @@ __cold void mdbx_rthc_thread_dtor(void *rthc) {
#endif
}
MDBX_EXCLUDE_FOR_GPROF
__cold void mdbx_rthc_global_dtor(void) {
mdbx_trace(">> pid %d", mdbx_getpid());
@ -23877,6 +23879,9 @@ __dll_export
#endif /* MDBX_BUILD_TYPE */
,
"MDBX_DEBUG=" MDBX_STRINGIFY(MDBX_DEBUG)
#ifdef ENABLE_GPROF
" ENABLE_GPROF"
#endif /* ENABLE_GPROF */
" MDBX_WORDBITS=" MDBX_STRINGIFY(MDBX_WORDBITS)
" BYTE_ORDER="
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__

View File

@ -195,6 +195,16 @@
#endif
#endif /* -Walignment-reduction-ignored */
#ifndef MDBX_EXCLUDE_FOR_GPROF
#ifdef ENABLE_GPROF
#define MDBX_EXCLUDE_FOR_GPROF \
__attribute__((__no_instrument_function__, \
__no_profile_instrument_function__))
#else
#define MDBX_EXCLUDE_FOR_GPROF
#endif /* ENABLE_GPROF */
#endif /* MDBX_EXCLUDE_FOR_GPROF */
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -32,6 +32,7 @@ uint32_t mdbx_linux_kernel_version;
bool mdbx_RunningOnWSL1;
#endif /* xMDBX_ALLOY */
MDBX_EXCLUDE_FOR_GPROF
__cold static uint8_t probe_for_WSL(const char *tag) {
const char *const WSL = strstr(tag, "WSL");
if (WSL && WSL[3] >= '2' && WSL[3] <= '9')
@ -48,8 +49,22 @@ __cold static uint8_t probe_for_WSL(const char *tag) {
#endif /* Linux */
#ifdef ENABLE_GPROF
extern void _mcleanup(void);
extern void monstartup(unsigned long, unsigned long);
extern void _init(void);
extern void _fini(void);
extern void __gmon_start__(void) __attribute__((__weak__));
#endif /* ENABLE_GPROF */
MDBX_EXCLUDE_FOR_GPROF
__cold static __attribute__((__constructor__)) void
mdbx_global_constructor(void) {
#ifdef ENABLE_GPROF
if (!&__gmon_start__)
monstartup((uintptr_t)&_init, (uintptr_t)&_fini);
#endif /* ENABLE_GPROF */
#if defined(__linux__) || defined(__gnu_linux__)
struct utsname buffer;
if (uname(&buffer) == 0) {
@ -84,9 +99,14 @@ mdbx_global_constructor(void) {
mdbx_rthc_global_init();
}
MDBX_EXCLUDE_FOR_GPROF
__cold static __attribute__((__destructor__)) void
mdbx_global_destructor(void) {
mdbx_rthc_global_dtor();
#ifdef ENABLE_GPROF
if (!&__gmon_start__)
_mcleanup();
#endif /* ENABLE_GPROF */
}
/*----------------------------------------------------------------------------*/