Skip to content

Instantly share code, notes, and snippets.

@avar
Created March 31, 2011 08:24
Show Gist options
  • Save avar/896026 to your computer and use it in GitHub Desktop.
Save avar/896026 to your computer and use it in GitHub Desktop.
A small C utility to parse /proc/*/smaps
#!/usr/bin/env/perl
use strict;
use warnings;
use Linux::Smaps;
use Linux::Smaps::Tiny;
use Benchmark qw/:all :hireswallclock/;
cmpthese(1000, {
"Linux::Smaps" => sub {
Linux::Smaps->new->all;
return;
},
"Linux::Smaps::Tiny" => sub {
Linux::Smaps::Tiny::get_smaps_summary;
return;
},
});
@elboulangero
Copy link

Hi, thanks for that piece of code. However, in the sscanf line, the %n only retrieve the number of characters consumed, that's to say 3 if "Rss" was found, 10 for "Referenced", and so on. The correct line is more something like :
if (sscanf(line, "%31[^:]: %d", substr, &n) == 2)
Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment