Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 253d7562

Von Sven Schöling vor mehr als 5 Jahren hinzugefügt

  • ID 253d756269c58fc019073c2d8da597f9f9b65e48
  • Vorgänger bc2b5fe6
  • Nachfolger afdd12ed

memory_usage_is_too_high von Dispatcher nach System::Process verschoben

(cherry picked from commit c0e3364a21b2da1c61564ddb8d9afa5ab6489f9c)

Unterschiede anzeigen:

SL/System/Process.pm
25 25
  return $cached_exe_dir;
26 26
}
27 27

  
28
sub _parse_number_with_unit {
29
  my ($number) = @_;
30

  
31
  return undef   unless defined $number;
32
  return $number unless $number =~ m{^ \s* (\d+) \s* ([kmg])b \s* $}xi;
33

  
34
  my %factors = (K => 1024, M => 1024 * 1024, G => 1024 * 1024 * 1024);
35

  
36
  return $1 * $factors{uc $2};
37
}
38

  
39
sub memory_usage_is_too_high {
40
  return undef unless $::lx_office_conf{system};
41

  
42
  my %limits = (
43
    rss  => _parse_number_with_unit($::lx_office_conf{system}->{memory_limit_rss}),
44
    size => _parse_number_with_unit($::lx_office_conf{system}->{memory_limit_vsz}),
45
  );
46

  
47
  # $::lxdebug->dump(0, "limits", \%limits);
48

  
49
  return undef unless $limits{rss} || $limits{vsz};
50

  
51
  my %usage;
52

  
53
  my $in = IO::File->new("/proc/$$/status", "r") or return undef;
54

  
55
  while (<$in>) {
56
    chomp;
57
    $usage{lc $1} = _parse_number_with_unit($2) if m{^ vm(rss|size): \s* (\d+ \s* [kmg]b) \s* $}ix;
58
  }
59

  
60
  $in->close;
61

  
62
  # $::lxdebug->dump(0, "usage", \%usage);
63

  
64
  foreach my $type (keys %limits) {
65
    next if !$limits{$type};
66
    next if $limits{$type} >= ($usage{$type} // 0);
67

  
68
    {
69
      no warnings 'once';
70
      $::lxdebug->message(LXDebug::WARN(), "Exiting due to memory size limit reached for type '${type}': limit " . $limits{$type} . " bytes, usage " . $usage{$type} . " bytes");
71
    }
72

  
73
    return 1;
74
  }
75

  
76
  return 0;
77
}
78

  
28 79
1;
29 80
__END__
30 81

  
......
51 102
(C<login.pl> etc.) and modules (sub-directory C<SL/> etc.) are located
52 103
in.
53 104

  
105
=item C<memory_usage_is_too_high>
106

  
107
Returns true if the current process uses more memory than the configured
108
limits.
109

  
54 110
=back
55 111

  
56 112
=head1 BUGS

Auch abrufbar als: Unified diff