File Coverage

blib/lib/Linux/Smaps/Tiny.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition 1 2 50.0
subroutine 5 5 100.0
pod n/a
total 20 21 95.2


line stmt bran cond sub pod time code
1             package Linux::Smaps::Tiny;
2             BEGIN {
3 1     1   998 $Linux::Smaps::Tiny::AUTHORITY = 'cpan:AVAR';
4             }
5             {
6             $Linux::Smaps::Tiny::VERSION = '0.09';
7             }
8 1     1   11 use strict;
  1         2  
  1         45  
9 1     1   7 use warnings FATAL => "all";
  1         2  
  1         102  
10              
11             BEGIN {
12 1     1   6 local ($@, $!);
13 1         3 eval {
14 1         6 require XSLoader;
15 1   50     717 XSLoader::load(__PACKAGE__, $Linux::Smaps::Tiny::VERSION || '0.01');
16             };
17             }
18              
19 1     1   10 use Exporter 'import';
  1         3  
  1         268  
20              
21             our @EXPORT_OK = qw(get_smaps_summary);
22              
23             =encoding utf8
24              
25             =head1 NAME
26              
27             Linux::Smaps::Tiny - A minimal and fast alternative to L
28              
29             =head1 SYNOPSIS
30              
31             use Linux::Smaps::Tiny qw(get_smaps_summary);
32              
33             my $summary = get_smaps_summary();
34             my $size = $summary->{Size};
35             my $shared_clean = $summary->{Shared_Clean};
36             my $shared_dirty = $summary->{Shared_Dirty};
37              
38             print "Size / Clean / Dirty = $size / $shared_clean / $shared_dirty\n";
39              
40             =head1 DESCRIPTION
41              
42             This module is a tiny interface to F files. It was
43             written because when we rolled out L in some critical
44             code at a Big Internet Company we experienced slowdowns that were
45             solved by writing a more minimal version.
46              
47             This module will try to use XS code to parse the smaps file, and if
48             that doesn't work it'll fall back on a pure-Perl version.
49              
50             If something like that isn't your use case you should probably use
51             L instead. Also note that L itself L
52             been
53             optimized|http://mail-archives.apache.org/mod_mbox/perl-modperl/201103.mbox/browser>
54             since this module was initially written.
55              
56             =head2 SPEED
57              
58             The distribution comes with a F script. As of
59             writing this is the speed of L
60             v.s. L, both the XS and PP versions:
61              
62             Rate Linux::Smaps Linux::Smaps::Tiny::PP Linux::Smaps::Tiny
63             Linux::Smaps 810/s -- -22% -61%
64             Linux::Smaps::Tiny::PP 1033/s 28% -- -51%
65             Linux::Smaps::Tiny 2101/s 159% 103% --
66              
67             =head1 FUNCTIONS
68              
69             =head2 get_smaps_summary
70              
71             Takes an optional process id (defaults to C) returns a summary
72             of the smaps data for the given process. Dies if the process does not
73             exist.
74              
75             Returns a hashref like this:
76              
77             {
78             'MMUPageSize' => '184',
79             'Private_Clean' => '976',
80             'Swap' => '0',
81             'KernelPageSize' => '184',
82             'Pss' => '1755',
83             'Private_Dirty' => '772',
84             'Referenced' => '2492',
85             'Size' => '5456',
86             'Shared_Clean' => '744',
87             'Shared_Dirty' => '0',
88             'Rss' => '2492'
89             };
90              
91             Values are in kB.
92              
93             =cut
94              
95             unless (defined &get_smaps_summary) {
96             require Linux::Smaps::Tiny::PP;
97             *get_smaps_summary = \&Linux::Smaps::Tiny::PP::__get_smaps_summary;
98             }
99              
100             =head1 LICENSE AND COPYRIGHT
101              
102             Copyright 2011 Yves Orton and Ævar Arnfjörð Bjarmason
103            
104              
105             This program is free software, you can redistribute it and/or modify
106             it under the same terms as Perl itself.
107              
108             =cut
109              
110             1;