summaryrefslogtreecommitdiffstats
path: root/bin/tails-persistence-setup
blob: 3cf0326f5825e9982e844f2432c65c5f36a36437 (plain)
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
#!/usr/bin/perl

=head1 NAME

tails-persistence-setup - setup Tails persistent storage

=head1 VERSION

Version 2.1.0

=cut

use strictures 2;
use 5.10.1;

our $VERSION = '2.1.0';

use FindBin;
use lib "$FindBin::Bin/../lib";

my $mu;
sub record_memory_usage { 1 }
sub report_memory_usage { 1 }

my @options;

BEGIN {
    if (exists $ENV{REPORT_MEMORY_USAGE}
            && defined $ENV{REPORT_MEMORY_USAGE}
            && $ENV{REPORT_MEMORY_USAGE}) {
        require Memory::Usage;
        $mu = Memory::Usage->new();
        no warnings 'redefine';
        *record_memory_usage = sub { $mu->record(shift) };
        *report_memory_usage = sub { $mu->dump() };
        push @options, ('memory_usage' => $mu);
        say STDERR "Enabled memory usage reporting";
    }
}

$SIG{'INT'}  = $SIG{'TERM'} = sub { report_memory_usage(); exit(0); };
$SIG{'USR1'} = sub { report_memory_usage(); };

record_memory_usage('before loading Tails::Persistence::Setup');
use Tails::Persistence::Setup;
record_memory_usage('after loading Tails::Persistence::Setup');

Tails::Persistence::Setup->new_with_options()->run;
record_memory_usage('after Tails::Persistence::Setup->run is done');

report_memory_usage();