File Coverage

lib/Mojo/IOLoop/ReadWriteProcess/CGroup/v2.pm
Criterion Covered Total %
statement 47 47 100.0
branch n/a
condition n/a
subroutine 25 25 100.0
pod 0 14 0.0
total 72 86 83.7


line stmt bran cond sub pod time code
1             package Mojo::IOLoop::ReadWriteProcess::CGroup::v2;
2              
3             # Refer to https://www.kernel.org/doc/Documentation/cgroup-v2.txt for details
4              
5 15     15   117 use Mojo::Base 'Mojo::IOLoop::ReadWriteProcess::CGroup';
  15         20  
  15         89  
6 15     15   2714 use Mojo::File 'path';
  15         49  
  15         874  
7 15     15   116 use Mojo::Collection 'c';
  15         28  
  15         1121  
8              
9             our @EXPORT_OK = qw(cgroup);
10 15     15   117 use Exporter 'import';
  15         17  
  15         947  
11              
12             use constant {
13 15         1945 PROCS_INTERFACE => 'cgroup.procs',
14             TYPE_INTERFACE => 'cgroup.type',
15             THREADS_INTERFACE => 'cgroup.threads',
16             EVENTS_INTERFACE => 'cgroup.events',
17             CONTROLLERS_INTERFACE => 'cgroup.controllers',
18             SUBTREE_CONTROL_INTERFACE => 'cgroup.subtree_control',
19             MAX_DESCENDANT_INTERFACE => 'cgroup.max.descendants',
20             MAX_DEPTH_INTERFACE => 'cgroup.max.depth',
21             STAT_INTERFACE => 'cgroup.stat',
22 15     15   103 };
  15         18  
23              
24 15     15   118 use Scalar::Util ();
  15         568  
  15         382  
25 15     15   6343 use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::IO;
  15         46  
  15         80  
26 15     15   6559 use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::CPU;
  15         42  
  15         89  
27 15     15   6737 use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::Memory;
  15         54  
  15         77  
28 15     15   6392 use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::PID;
  15         43  
  15         101  
29 15     15   524 use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::RDMA;
  15         30  
  15         122  
30              
31             has io => sub {
32             my $io = Mojo::IOLoop::ReadWriteProcess::CGroup::v2::IO->new(cgroup => shift);
33             Scalar::Util::weaken $io->{cgroup};
34             return $io;
35             };
36              
37             has cpu => sub {
38             my $cpu
39             = Mojo::IOLoop::ReadWriteProcess::CGroup::v2::CPU->new(cgroup => shift);
40             Scalar::Util::weaken $cpu->{cgroup};
41             return $cpu;
42             };
43              
44             has memory => sub {
45             my $memory
46             = Mojo::IOLoop::ReadWriteProcess::CGroup::v2::Memory->new(cgroup => shift);
47             Scalar::Util::weaken $memory->{cgroup};
48             return $memory;
49             };
50              
51             has pid => sub {
52             my $pid
53             = Mojo::IOLoop::ReadWriteProcess::CGroup::v2::PID->new(cgroup => shift);
54             Scalar::Util::weaken $pid->{cgroup};
55             return $pid;
56             };
57              
58             has rdma => sub {
59             my $rdma
60             = Mojo::IOLoop::ReadWriteProcess::CGroup::v2::RDMA->new(cgroup => shift);
61             Scalar::Util::weaken $rdma->{cgroup};
62             return $rdma;
63             };
64              
65             # CGroups process interface
66 4     4 0 30 sub add_process { shift->_appendln(+PROCS_INTERFACE() => pop) }
67              
68 2     2 0 22 sub process_list { shift->_list(PROCS_INTERFACE) }
69 2     2 0 1539 sub processes { c(shift->_listarray(PROCS_INTERFACE)) }
70              
71 8     8 0 1594 sub contains_process { shift->_contains(+PROCS_INTERFACE() => pop) }
72              
73             # CGroups thread interface
74 2     2 0 15 sub add_thread { shift->_appendln(+THREADS_INTERFACE() => pop) }
75              
76 1     1 0 12 sub thread_list { shift->_list(THREADS_INTERFACE) }
77              
78 4     4 0 730 sub contains_thread { shift->_contains(+THREADS_INTERFACE() => pop) }
79              
80             # CGroups event interface
81 1     1 0 5 sub populated { shift->_list(EVENTS_INTERFACE) }
82              
83             # CGroups type interface
84 2     2 0 15 sub type { shift->_setget(+TYPE_INTERFACE() => pop) }
85              
86             # CGroups controllers Interface
87 2     2 0 889 sub controllers { shift->_setget(+CONTROLLERS_INTERFACE() => pop) }
88              
89             # CGroups subtree_control Interface
90 2     2 0 9 sub subtree_control { shift->_setget(+SUBTREE_CONTROL_INTERFACE() => pop) }
91              
92             # CGroups max.descendants Interface
93 2     2 0 955 sub max_descendants { shift->_setget(+MAX_DESCENDANT_INTERFACE() => pop) }
94              
95             # CGroups max.depth Interface
96 2     2 0 969 sub max_depths { shift->_setget(+MAX_DEPTH_INTERFACE() => pop) }
97              
98             # CGroups stat Interface
99 1     1 0 231 sub stat { shift->_list(+STAT_INTERFACE()) }
100              
101             *IO = \&io;
102             *CPU = \&cpu;
103             *MEMORY = \&memory;
104             *PID = \&pid;
105             *RDMA = \&rdma;
106              
107             1;
108              
109             =encoding utf-8
110              
111             =head1 NAME
112              
113             Mojo::IOLoop::ReadWriteProcess::CGroup::v2 - CGroups v2 implementation.
114              
115             =head1 SYNOPSIS
116              
117             use Mojo::IOLoop::ReadWriteProcess::CGroup::v2;
118              
119             my $cgroup = Mojo::IOLoop::ReadWriteProcess::CGroup::v2->new( name => "test" );
120              
121             $cgroup->create;
122             $cgroup->exists;
123             my $child = $cgroup->child('bar');
124              
125             =head1 DESCRIPTION
126              
127             This module uses features that are only available on Linux,
128             and requires cgroups and capability for unshare syscalls to achieve pid isolation.
129              
130             =head1 METHODS
131              
132             L inherits all methods from L and implements
133             the following new ones.
134              
135             =head1 LICENSE
136              
137             Copyright (C) Ettore Di Giacinto.
138              
139             This library is free software; you can redistribute it and/or modify
140             it under the same terms as Perl itself.
141              
142             =head1 AUTHOR
143              
144             Ettore Di Giacinto Eedigiacinto@suse.comE
145              
146             =cut