diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index dd25e813dff..8b3999abcc0 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -132,6 +132,9 @@ config("dart_config") { defines += [ "DART_USE_TCMALLOC" ] include_dirs += [ "../third_party/tcmalloc/gperftools/src" ] } + if (dart_use_mallinfo2) { + defines += [ "DART_USE_MALLINFO2" ] + } if (dart_use_compressed_pointers) { defines += [ "DART_COMPRESSED_POINTERS" ] diff --git a/runtime/runtime_args.gni b/runtime/runtime_args.gni index ae564bef7eb..8219c5140b9 100644 --- a/runtime/runtime_args.gni +++ b/runtime/runtime_args.gni @@ -46,6 +46,10 @@ declare_args() { # the VM enables this only for Linux builds. dart_use_tcmalloc = false + # Whether to use mallinfo2 instead of mallinfo which is deprecated starting + # with libc 2.33 + dart_use_mallinfo2 = false + # Whether to link Crashpad library for crash handling. Only supported on # Windows for now. dart_use_crashpad = false diff --git a/runtime/vm/malloc_hooks_tcmalloc.cc b/runtime/vm/malloc_hooks_tcmalloc.cc index 438e4772c08..3dc36394852 100644 --- a/runtime/vm/malloc_hooks_tcmalloc.cc +++ b/runtime/vm/malloc_hooks_tcmalloc.cc @@ -341,7 +341,11 @@ bool MallocHooks::Active() { bool MallocHooks::GetStats(intptr_t* used, intptr_t* capacity, const char** implementation) { +#if defined(DART_USE_MALLINFO2) + struct mallinfo2 info = mallinfo2(); +#else struct mallinfo info = mallinfo(); +#endif // defined(DART_USE_MALLINFO2) *used = info.uordblks; *capacity = *used + info.fordblks; *implementation = "tcmalloc"; diff --git a/runtime/vm/malloc_hooks_unsupported.cc b/runtime/vm/malloc_hooks_unsupported.cc index 9650cffc6b6..5b666d177bc 100644 --- a/runtime/vm/malloc_hooks_unsupported.cc +++ b/runtime/vm/malloc_hooks_unsupported.cc @@ -70,7 +70,11 @@ bool MallocHooks::GetStats(intptr_t* used, } #endif #if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID) +#if defined(DART_USE_MALLINFO2) + struct mallinfo2 info = mallinfo2(); +#else struct mallinfo info = mallinfo(); +#endif // defined(DART_USE_MALLINFO2) *used = info.uordblks; *capacity = *used + info.fordblks; *implementation = "unknown"; diff --git a/tools/gn.py b/tools/gn.py index dccae528ef7..fe4718d1111 100755 --- a/tools/gn.py +++ b/tools/gn.py @@ -215,6 +215,9 @@ def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash): (gn_args['target_cpu'] != 'arm') and sanitizer == 'none') + # Use mallinfo2 if specified on the command line + gn_args['dart_use_mallinfo2'] = args.use_mallinfo2 + if gn_args['target_os'] == 'linux': if gn_args['target_cpu'] == 'arm': # Default to -mfloat-abi=hard and -mfpu=neon for arm on Linux as we're @@ -490,6 +493,11 @@ def AddCommonGnOptionArgs(parser): '-s', type=str, help='Comma-separated list of arch=/path/to/sysroot mappings') + parser.add_argument('--use-mallinfo2', + help='Use mallinfo2 to collect malloc stats.', + default=False, + dest='use_mallinfo2', + action='store_true') def AddCommonConfigurationArgs(parser):