Visualizing AllocatorsΒΆ
The python script plot_allocations.py 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 pooled_allocator.log which contains the allocation records from the underlying allocator and the pool (QuickPool in this case). These can then be plotted using a command similar to the following:
tools/plot_allocations 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-23, 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/QuickPool.hpp"
int main(int, char**)
{
auto& rm = umpire::ResourceManager::getInstance();
auto allocator = rm.getAllocator("HOST");
auto pooled_allocator = rm.makeAllocator<umpire::strategy::QuickPool>("HOST_POOL", allocator, 1024 * 16);
void* a[4];
for (int i = 0; i < 4; ++i)
a[i] = pooled_allocator.allocate(1024);
// Create fragmentation
pooled_allocator.deallocate(a[2]);
a[2] = pooled_allocator.allocate(1024 * 2);
// Output the records from the pooled allocator
{
std::ofstream out("pooled_allocator.log");
umpire::print_allocator_records(pooled_allocator, out);
out.close();
}
for (int i = 0; i < 4; ++i)
pooled_allocator.deallocate(a[i]);
// Visualize this using the python script. Example usage:
// tools/analysis/plot_allocations pooled_allocator.log purple 0.8
return 0;
}