File: pmat

package info (click to toggle)
libdevel-mat-perl 0.53-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 908 kB
  • sloc: perl: 6,224; makefile: 3
file content (114 lines) | stat: -rwxr-xr-x 2,314 bytes parent folder | download
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/perl

use v5.14;
use warnings;
use Feature::Compat::Try;

use Devel::MAT::Cmd::Terminal;
use Getopt::Long qw( :config no_permute );
use Commandable::Invocation 0.03; # ->new_from_tokens

use constant CAN_COLOUR => -t STDERR;

GetOptions(
   'quiet|q' => \( my $QUIET ),
   'blib'    => sub { require blib; blib->import },
) or exit 1;

# Some tools might want to draw pretty graphs with line drawing / similar
STDOUT->binmode( ":encoding(UTF-8)" );
STDOUT->autoflush(1);

require Devel::MAT;

my $file = shift @ARGV or die "Need dumpfile\n";

my $progress = ( CAN_COLOUR && !$QUIET ?
   sub { print STDERR "\r\e[K" . ( shift // "" ); } :
   undef
);

my $pmat = Devel::MAT->load( $file,
   progress => $progress,
);

$progress->() if $progress;

my $df = $pmat->dumpfile;

if( !$QUIET ) {
   $pmat->run_command( Commandable::Invocation->new( "summary" ) );
}

if( @ARGV ) {
   $pmat->run_command(
      Commandable::Invocation->new_from_tokens( @ARGV ),
      progress => $progress,
   );

   # Finish the pagination output
   Devel::MAT::Tool::more->run while Devel::MAT::Tool::more->can_more;

   exit
}

require Term::ReadLine;

my $rl = Term::ReadLine->new( 'pmat' );
while( defined( my $line = $rl->readline(
         sprintf 'pmat%s> ', Devel::MAT::Tool::more->can_more ? " [more]" : ""
      ) ) ) {
   my $inv = Commandable::Invocation->new( $line );
   defined $inv->peek_token or
      $inv = Commandable::Invocation->new( "more" ) if Devel::MAT::Tool::more->can_more;

   next unless defined $inv->peek_token; # blank line

   last if $inv->peek_token eq "exit" or $inv->peek_token eq "quit";

   try {
      # We just have to hope nobody catches this one.
      # It would be nice to  next COMMAND  but awkward perl internals reasons
      # mean we can't do that from a signal handler
      local $SIG{INT} = sub { die "\nAborted\n"; };

      $pmat->run_command( $inv,
         progress => $progress,
      );
   }
   catch ($e) {
      print STDERR "$e";
   }

   print "\n";
}

print "\n";

=head1 NAME

pmat - Perl Memory Analysis Tool

=head1 SYNOPSIS

   $ pmat my-file.pmat

=head1 OPTIONS

=over 4

=item --quiet, -q

Don't print progress reports or welcome banner.

=back

=head1 DESCRIPTION

See L<Devel::MAT::UserGuide>.

=head1 AUTHOR

Paul Evans <leonerd@leonerd.org.uk>

=cut