There are several ways to view memory on Linux, such as through the ps,top,free, pmap, etc., or through the /proc system. In the utility class, we used Valgrind to find memory problems in Linux programs.

The Nokia Memory Profiler is a Linux Memory Profiler that Nokia has created on Github.

Nokia Memory Profiler is a Memory Profiler for Linux.

 

Characteristics of the

  • It can be used to analyze memory leaks, see exactly where memory consumption is, identify temporary allocations, and investigate excessive memory fragmentation
  • Gather information on each content allocation and release, as well as a complete stack trace
  • Using a custom stack unfurl implementation, the cost performance is significantly better than other similar tools, in some cases by several orders of magnitude
  • You can export the collected data to a variety of different formats; It can export data as JSON (which you can analyze on your own as needed), as Heaptrack (which you can analyze using the excellent Heaptrack GUI), or as a fire chart
  • Has its own Web-based GUI for analysis
  • Analysis data can be streamed dynamically to another machine rather than stored locally, which is useful for analysis on memory-constrained systems
  • Supports AMD64, ARM, AArch64 and MIPS64 architectures

 

Building

1. Update and install Rust and Yarn package managers every night (for building guIs)

2. Establishment:

 $ cargo build --release -p memory-profiler
 $ cargo build --release -p memory-profiler-cli
Copy the code

Target /release/libmemory_profiler.so and target/release/memory-profiler-cli

Basic usage

$ LD_PRELOAD=./libmemory_profiler.so ./your_application
$ ./memory-profiler-cli server memory-profiling_*.dat
Copy the code

Then open a Web browser and point it to http://localhost:8080 to access the GUI.

If you don’t want to use the GUI, you can also use the REST API exposed by the server. Such as:

  • Generate a flame map for leak allocation:
$ curl "http://localhost:8080/data/last/export/flamegraph? lifetime=only_leaked" > flame.svgCopy the code
  • Export the leaked allocation as an ASCII tree:
$ curl "http://localhost:8080/data/last/allocation_ascii_tree? lifetime=only_leaked"Copy the code
  • Export the three maximum allocations issued by the application to JSON
$ curl "http://localhost:8080/data/last/allocations? sort_by=size&order=dsc&count=3"Copy the code
  • Export the three largest calling sites with at least 10 allocations, of which at least 50% are leaked:
$ curl "http://localhost:8080/data/last/allocation_groups? group_allocations_min=10&group_leaked_allocations_min=50%&sort_by=all.size&count=3"Copy the code

Github address: github.com/nokia/memor…