def METHOD_NAME(heap_config, default_heap_sample_size=1024 * 1024):
    # type: (ProfilingConfig.Heap, int) -> int
    heap_sample_size = heap_config._sample_size
    if heap_sample_size is not None:
        return heap_sample_size
    if not heap_config.enabled:
        return 0
    try:
        from ddtrace.vendor import psutil
        total_mem = psutil.swap_memory().total + psutil.virtual_memory().total
    except Exception:
        logger.warning(
            "Unable to get total memory available, using default value of %d KB",
            default_heap_sample_size / 1024,
            exc_info=True,
        )
        return default_heap_sample_size
    # This is TRACEBACK_ARRAY_MAX_COUNT
    max_samples = 2 ** 16
    return int(max(math.ceil(total_mem / max_samples), default_heap_sample_size))