| 1 | package Linux::Smaps::Tiny; | ||||||||||||
| 2 | 2 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 2 | $Linux::Smaps::Tiny::AUTHORITY = 'cpan:AVAR'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | { | ||||||||||||
| 6 | 2 | $Linux::Smaps::Tiny::VERSION = '0.10'; | |||||||||||
| 7 | } | ||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 2 | ▶ | use warnings FATAL => "all"; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 2 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
| |||||||||||||
| 12 | 2 | local ($@, $!); | |||||||||||
| 13 | 2 | eval { | |||||||||||
| 14 | 2 | require XSLoader; | |||||||||||
| 15 | 2 | ▶ | XSLoader::load(__PACKAGE__, $Linux::Smaps::Tiny::VERSION || '0.01'); | ||||||||||
|
Condition50%1/2
$Linux::Smaps::Tiny::VERSION || '0.01'
MC/DC0%0/1
$Linux::Smaps::Tiny::VERSION || '0.01'
$Linux::Smaps::Tiny::VERSION
Truth table50%1/2
A
A= $Linux::Smaps::Tiny::VERSION
| |||||||||||||
| 16 | }; | ||||||||||||
| 17 | } | ||||||||||||
| 18 | |||||||||||||
| 19 | 2 | ▶ | use Exporter 'import'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | |||||||||||||
| 21 | 2 | 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<Linux::Smaps> | ||||||||||||
| 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</proc/PID/smaps> files. It was | ||||||||||||
| 43 | written because when we rolled out L<Linux::Smaps> 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<Linux::Smaps> instead. Also note that L<Linux::Smaps> itself L<has | ||||||||||||
| 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<contrib/benchmark.pl> script. As of | ||||||||||||
| 59 | writing this is the speed of L<Linux::Smaps> | ||||||||||||
| 60 | v.s. L<Linux::Smaps::Tiny>, 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<self>) 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 | 2 | ▶ | unless (defined &get_smaps_summary) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | 2 | require Linux::Smaps::Tiny::PP; | |||||||||||
| 97 | 2 | *get_smaps_summary = \&Linux::Smaps::Tiny::PP::__get_smaps_summary; | |||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | =head1 LICENSE AND COPYRIGHT | ||||||||||||
| 101 | |||||||||||||
| 102 | Copyright 2011 Yves Orton <yves@cpan.org> and Ævar Arnfjörð Bjarmason | ||||||||||||
| 103 | <avar@cpan.org> | ||||||||||||
| 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 | 2 | 1; | |||||||||||