Visualizing AllocatorsΒΆ

The python script is included with Umpire to plot allocations. This script uses series of three arguments: an output file with allocation records, a color, and an alpha (transparency) value 0.0-1.0. Although these could be used to plot records from a single allocator, 3 arguments, it can also be used to overlay multiple allocators, by passing 3n arguments after the script name. In this cookbook we use this feature to visualize a pooled allocator.

The cookbook generates two files, allocator.log and pooled_allocator.log, that contain the allocation records from the underlying allocator and the pool. These can then be plotted using a command similar to the following:

tools/plot_allocations allocator.log gray 0.2 pooled_allocator.log purple 0.8

That script uses Python and Matplotlib to generate the following image


The complete example is included below:

// Copyright (c) 2016-20, Lawrence Livermore National Security, LLC and Umpire
// project contributors. See the COPYRIGHT file for details.
// SPDX-License-Identifier: (MIT)
#include <fstream>

#include "umpire/Allocator.hpp"
#include "umpire/ResourceManager.hpp"
#include "umpire/Umpire.hpp"
#include "umpire/strategy/DynamicPool.hpp"

int main(int, char**)
  auto& rm = umpire::ResourceManager::getInstance();

  auto allocator = rm.getAllocator("HOST");
  auto pooled_allocator = rm.makeAllocator<umpire::strategy::DynamicPool>(
      "HOST_POOL", allocator, 1024 * 16);

  void* a[4];
  for (int i = 0; i < 4; ++i)
    a[i] = pooled_allocator.allocate(1024);

  // Create fragmentation
  a[2] = pooled_allocator.allocate(1024 * 2);

  // Output the records from the underlying host allocator
    std::ofstream out("allocator.log");
    umpire::print_allocator_records(allocator, out);

  // Output the records from the pooled allocator
    std::ofstream out("pooled_allocator.log");
    umpire::print_allocator_records(pooled_allocator, out);

  for (int i = 0; i < 4; ++i)

  // Visualize this using the python script. Example usage:
  // tools/analysis/plot_allocations allocator.log gray 0.2 pooled_allocator.log
  // purple 0.8

  return 0;