Real World Perl: Analyze Chrome's heap

Welcome to Real World Perl, a series that aims to showcase everyday uses of Perl. Got a suggestion for a Real World Perl example? email me.

When ordinary tools fail, many programmers reach for Perl. Matthew Hodgson ran into trouble analyzing the Chrome Browser’s heap dump file: the programs he used kept running out of memory for large (> 2GB) files. So he whipped up a “quick and dirty” Perl script to do it. Instead of parsing the entire heap dump into memory, it saves resources by processing the data one line at a time.

To use the script, you first need a Chrome heap dump file. To get one, launch Chrome, go to Developer tools -> Memory -> Take heap snapshot. Save the file locally.

$ ./heap-analyser.pl /path/to.heapsnapshot > heap-stats.csv

This will save the statistics in a tab separated format in the file heap-stats.csv. From there you can import the file into your favorite spreadsheet software, for further investigation. Matthew has an example of this in the project repo.


Cover image from pixabay

Tags

David Farrell

David is the editor of Perl.com. An organizer of the New York Perl Meetup, he works for ZipRecruiter as a software developer.

Browse their articles

Feedback

Something wrong with this article? Help us out by opening an issue or pull request on GitHub