public void showMemoryUsage() {
        logger.info("Memory used in task " + taskAttemptId);
        synchronized (this) {
            long memoryAccountedForByConsumers = 0;
            for (MemoryConsumer c : consumers) {
                long totalMemUsage = c.getUsed();
                memoryAccountedForByConsumers += totalMemUsage;
                if (totalMemUsage > 0) {
                    logger.info("Acquired by " + c + ": " + Utils.bytesToString(totalMemUsage));
                }
            }
            long memoryNotAccountedFor =
                    memoryManager.getMemoryUsageForTask(taskAttemptId) - memoryAccountedForByConsumers;
            logger.info(
                    "{} bytes of memory were used by task {} but are not associated with specific consumers",
                    memoryNotAccountedFor, taskAttemptId);
            logger.info(
                    "{} bytes of memory are used for execution.",
                    memoryManager.getMemoryUsageForTask(taskAttemptId));
        }
    }
Dump the memory usage of all consumers.
indexr-query-opt/src/main/java/org/apache/spark/memory/TaskMemoryManager.java