/usr/bin/pmap_dirty is in hxtools 20170430-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #!/usr/bin/perl -w
#
# pmap_dirty
# written by Jan Engelhardt, 2006-2007
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the WTF Public License version 2 or
# (at your option) any later version.
#
# Usage: pmap_dirty [pid...]
#
# Ex: pmap_dirty
# pmap_dirty $$
# pmap_dirty `pidof init` `pidof java`
#
use Getopt::Long;
use strict;
my $Use_pid_sort;
&Getopt::Long::Configure(qw(bundling));
&GetOptions("p" => \$Use_pid_sort);
my %total_counter;
if (scalar(@ARGV) == 0) {
@ARGV = sort { $a <=> $b } map {
$_ = ($_ =~ m{^/proc/(\d+)$})[0];
(!defined($_) || $_ eq "") ? () : $_
} glob("/proc/*");
}
&print_one();
foreach my $pid (@ARGV) {
my $proc_name;
my $fh;
open($fh, "< /proc/$pid/smaps");
my %counter = (
Private_Dirty => 0,
Referenced => 0,
);
my $shared_dirty = 0;
while (defined(my $line = <$fh>)) {
if ($line =~ /^(\w+):\s+(\d+)/i) {
$counter{$1} += $2;
$total_counter{$1} += $2;
}
}
close $fh;
if (open($fh, "</proc/$pid/stat")) {
($proc_name) = (<$fh> =~ /^.*?\((.*)\)/);
close $fh;
}
&print_one("$pid($proc_name)", \%counter);
}
&print_one("Total", \%total_counter);
sub print_one
{
my($text, $counter) = @_;
if (!defined($counter)) {
if (!$Use_pid_sort) {
printf "%-10s %-10s %s\n", "PRIV_DIRT", "REFERENCD", "PROCESS";
}
return;
}
my $pd = $counter->{Private_Dirty}."K";
my $re = $counter->{Referenced}."K";
# Pv_Dirty Referenced
if ($Use_pid_sort) {
printf "$text: $pd (ref $re)\n";
} else {
printf "%-10s %-10s %s\n", $pd, $re, $text;
}
}
|