blib/lib/Linux/IO_Prio.pm

filter: Statementstmt 86.7% 59 / 68 Branchbran 42.8% 6 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 89.4% 17 / 19 Podpod 100% 8 / 8 totaltotal 79.8% 91 / 114 CC 8 SCAR 6.0
CC
8
Cov
78%
ionice
3.5
_load_syscall
2.5
ioprio_get
2.1
CRAP 1.8
↑ Summary
1 package Linux::IO_Prio;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 require Exporter;
7 2 ▶use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use POSIX qw(ENOSYS);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 $VERSION = '0.03';
12 2 @ISA = qw(Exporter);
13 2 %EXPORT_TAGS = (ionice => [qw(&ionice &ionice_class &ionice_data)],
14 c_api => [qw(&ioprio_set &ioprio_get)],
15 macros => [qw(IOPRIO_PRIO_VALUE IOPRIO_PRIO_CLASS IOPRIO_PRIO_DATA)],
16 who => [qw(IOPRIO_WHO_PROCESS IOPRIO_WHO_PGRP IOPRIO_WHO_USE)],
17 class => [qw(IOPRIO_CLASS_NONE IOPRIO_CLASS_RT IOPRIO_CLASS_BE IOPRIO_CLASS_IDLE)]
18 );
19 # The tag lists are exclusive at the moment, so don't worry about duplicates.
20 2 push @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} foreach keys %EXPORT_TAGS;
21 2 Exporter::export_ok_tags($_) foreach keys %EXPORT_TAGS;
22  
23 2 ▶use constant IOPRIO_CLASS_SHIFT => 13;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use constant IOPRIO_PRIO_MASK => ((1 << IOPRIO_CLASS_SHIFT) - 1);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 IOPRIO_WHO_PROCESS => 1,
27 IOPRIO_WHO_PGRP => 2,
28 IOPRIO_WHO_USER => 3
29 2 };
30 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 IOPRIO_CLASS_NONE => 0,
32 IOPRIO_CLASS_RT => 1,
33 IOPRIO_CLASS_BE => 2,
34 IOPRIO_CLASS_IDLE => 3
35 2 };
36  
37 2 ▶if ($^O eq 'linux') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'linux') { } 2 0 2
38 2 _load_syscall();
39 }
40 else {
41 0 warn "Linux::IO_Prio: unsupported operating system -- $^O\n";
42 }
43  
44 # Load syscall.ph
45 3 ▶sub _load_syscall {
Subroutine _load_syscall: called CC=2 SCAR=9.2
46 3 ▶ return eval{require('syscall.ph') || require('sys/syscall.ph')};
Branch: 1 branch
BranchTrueFalseTotal
require "syscall.ph" or require "sys/syscall.ph" 0 0 0
47 }
48  
49 # C API functions
50 # int ioprio_get(int which, int who);
51 3 ▶sub ioprio_get {
Subroutine ioprio_get: called CC=2 SCAR=7.6
Pod documented
52 3 my ($which, $who) = @_;
53 3 ▶ if (defined &SYS_ioprio_get) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Linux::IO_Prio::SYS_ioprio_get) { } 0 3 3
54 0 return syscall(SYS_ioprio_get(), $which, $who);
55 }
56 else {
57 3 return _not_implemented();
58 }
59 }
60  
61 # int ioprio_set(int which, int who, int ioprio);
62 2 ▶sub ioprio_set {
Subroutine ioprio_set: called CC=2 SCAR=7.6
Pod documented
63 2 my ($which, $who, $ioprio) = @_;
64 2 ▶ if (defined &SYS_ioprio_set) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Linux::IO_Prio::SYS_ioprio_set) { } 0 2 2
65 0 return syscall(SYS_ioprio_set(), $which, $who, $ioprio);
66 }
67 else {
68 2 return _not_implemented();
69 }
70 }
71  
72 # C API Macros
73 2 ▶sub IOPRIO_PRIO_VALUE {
Subroutine IOPRIO_PRIO_VALUE: called CC=1 SCAR=0.0
Pod documented
74 2 my ($class, $data) = @_;
75 2 return ($class << IOPRIO_CLASS_SHIFT) | $data;
76 }
77  
78 0 ▶sub IOPRIO_PRIO_CLASS {
Subroutine IOPRIO_PRIO_CLASS: not called CC=1 SCAR=6.9
Pod documented
79 0 my ($mask) = @_;
80 0 return ($mask >> IOPRIO_CLASS_SHIFT);
81 }
82  
83 0 ▶sub IOPRIO_PRIO_DATA {
Subroutine IOPRIO_PRIO_DATA: not called CC=1 SCAR=6.9
Pod documented
84 0 my ($mask) = @_;
85 0 return ($mask & IOPRIO_PRIO_MASK);
86 }
87  
88 # Wrapper functions
89 1 ▶sub ionice {
Subroutine ionice: called CC=3 SCAR=12.5
Pod documented
90 1 my ($which, $who, $class, $data) = @_;
91 1 ▶ carp "Data not permitted for class IOPRIO_CLASS_IDLE" if $class == IOPRIO_CLASS_IDLE && $data;
Branch: 1 branch
BranchTrueFalseTotal
if $class == 3 and $data 0 1 1
Condition33%1/3
$class == 3 and $data
!ll&&!rl&&r
010
MC/DC0%0/2
$class == 3 and $data
$class == 3 $data
Truth table33%1/3
A and B
A= $class == 3B= $data
ABresult
0X0
100
111
92 1 return ioprio_set($which, $who, IOPRIO_PRIO_VALUE($class, $data));
93 }
94  
95 1 ▶sub ionice_class {
Subroutine ionice_class: called CC=2 SCAR=7.6
Pod documented
96 1 my ($which, $who) = @_;
97 1 ▶ if((my $priority = ioprio_get($which, $who)) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $priority = ioprio_get($which, $who)) < 0) { } 1 0 1
98 1 return $priority;
99 }
100 else {
101 0 return IOPRIO_PRIO_CLASS($priority);
102 }
103 }
104  
105 1 ▶sub ionice_data {
Subroutine ionice_data: called CC=2 SCAR=7.6
Pod documented
106 1 my ($which, $who) = @_;
107 1 ▶ if((my $priority = ioprio_get($which, $who)) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $priority = ioprio_get($which, $who)) < 0) { } 1 0 1
108 1 return $priority;
109 }
110 else {
111 0 return IOPRIO_PRIO_DATA($priority);
112 }
113 }
114  
115 # Stub for not implemented
116 5 ▶sub _not_implemented {
Subroutine _not_implemented: called CC=1 SCAR=0.0
117 5 $! = ENOSYS;
118 5 return -1;
119 }
120  
121 2 1;
122 __END__
↑ Summary