AntelopeIO / spring

C++ implementation of the Antelope protocol with Savanna consensus
Other
10 stars 5 forks source link

Add live graphic visualization of memory allocated/freed while nodeos is running #1041

Open greg7mdp opened 5 days ago

greg7mdp commented 5 days ago

Please note that we do not intend to merge this PR, in only exists as documentation of the work done, and as a base for further developments if warranted.

Resolves #974.

This change is mostly done in two separate parts:

Boost interprocess memory occupancy tracking

The Boost interprocess library (which is used to manage memory within the shared memory segment allocated by chainbase) can use multiple memory allocation managers.

Chainbase, and therefore nodeos, use the rbtree_best_fit algorithm which keeps track of free areas using a rbtree (the nodes of the rbtree are intrusively stored in the free areas themselves, so there is no additional memory cost for this tree, besides the fact that it requires a minimum allocation size).

This PR adds a new member in the memory segment header managed by the interprocess library, of the type:

using occupancy_array_t = std::vector<uint8_t>; // one byte describes the occupancy percentage of each page of the segment

and updates this occupancy vector:

As we cannot add these changes in the original boost repo, this PR links to a private repo which includes the changes in the interprocess library. These changes are also included in the following file:

ip.txt

Use the occupancy vector maintained by Boost interprocess to update a texture and visualize it on-screen

The visualization is implemented using OpenGL. This required adding some dependencies to chainbase:

  1. some glad header files describing the OpenGL interface used. These were generated from https://gen.glad.sh/, specifying gl 4.6 and glx 1.4, compat profile, header only, GL_ARB_direct_state_access extension.
  2. the glm library, used as-is
  3. the glfw library, with this trivial change: glfw.txt

The visualization is implemented in the new files mem_visualizer[.hpp, .cpp], and takes place on a separate thread.

Notes

ericpassmore commented 3 days ago

Note:start category: Tooling component: Internal summary: Added openGL tooling to visualize memory allocation in real time. Note:end