| 1 | |||||||||||||||||||||||||||||
| 2 | # Copyright (c) 1999-2017 Rob Fugina <robf@fugina.com> | ||||||||||||||||||||||||||||
| 3 | # Distributed under the terms of the GNU Public License, Version 3.0 | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package X10::Scheduler; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # this package implements a scheduler | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use POSIX; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub new | ||||||||||||||||||||||||||||
| 15 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 0 | my $type = shift; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | my $self = bless { @_ }, $type; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | return undef unless $self->{controller}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $self->{logger} ||= sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 23 | 0 | shift; | |||||||||||||||||||||||||||
| 24 | 0 | printf(@_); | |||||||||||||||||||||||||||
| 25 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | }; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"logger"} ||= sub {
shift();
printf @_;
print "\n";
}
MC/DC0%0/2
$self->{"logger"} ||= sub {
shift();
printf @_;
print "\n";
}
$self->{"logger"}
sub {
shift();
printf @_;
print "\n";
}
Truth table0%0/3
A ||= B
A= $self->{"logger"}B= sub {
shift();
printf @_;
print "\n";
}
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $self->{verbose} = 1 if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # $self->{controller}->register_listener($self->event_callback); | ||||||||||||||||||||||||||||
| 31 | 0 | $self->{schedevents} = []; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($self->{configfile}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $config = eval { require $self->{configfile} } || die $@; | ||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
require $self->{'configfile'}
}
} || die($@)
MC/DC0%0/1
eval {
do {
require $self->{'configfile'}
}
} || die($@)
eval {
do {
require $self->{'configfile'}
}
}
Truth table0%0/2
A
A= eval {
do {
require $self->{'configfile'}
}
}
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | foreach (@$config) | |||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||
| 39 | 0 | $self->add( new X10::SchedEvent( %$_ ) ); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | return $self; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | ### | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub setup | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
setup: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | while (my $key = shift) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | return $self->{schedevents}; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub add | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 65 | 0 | my $se = shift; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return undef unless ($se && $se->isa('X10::SchedEvent')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$se and $se->isa("X10::SchedEvent")
MC/DC0%0/2
$se and $se->isa("X10::SchedEvent")
$se
$se->isa("X10::SchedEvent")
Truth table0%0/3
A and B
A= $seB= $se->isa("X10::SchedEvent")
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | $se->controller($self->{controller}); | |||||||||||||||||||||||||||
| 70 | 0 | $se->{logger} = $self->{logger}; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | $se->{latitude} = $self->{latitude} || 38.74274; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'latitude'} || 38.74274
MC/DC0%0/1
$self->{'latitude'} || 38.74274
$self->{'latitude'}
Truth table0%0/2
A
A= $self->{'latitude'}
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $se->{longitude} = $self->{longitude} || -90.560143; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'longitude'} || -90.560143
MC/DC0%0/1
$self->{'longitude'} || -90.560143
$self->{'longitude'}
Truth table0%0/2
A
A= $self->{'longitude'}
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $self->{logger}->('info', "Queueing %s for %s", | ||||||||||||||||||||||||||
|
Condition0%0/2
$se->description || 'unnamed event'
MC/DC0%0/1
$se->description || 'unnamed event'
$se->description
Truth table0%0/2
A
A= $se->description
| |||||||||||||||||||||||||||||
| 75 | $se->description || 'unnamed event', | ||||||||||||||||||||||||||||
| 76 | strftime("%a %b %e %H:%M %Y", localtime($se->next_time)), | ||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | push @{$self->{schedevents}}, $se; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | @{$self->{schedevents}} = | |||||||||||||||||||||||||||
| 82 | 0 | sort { $a->next_time <=> $b->next_time } | |||||||||||||||||||||||||||
| 83 | 0 | @{$self->{schedevents}}; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | return 1; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | sub next_event_time | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
next_event_time: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return 0 unless (@{$self->{schedevents}} > 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | return $self->{schedevents}->[0]->next_time; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | sub run | ||||||||||||||||||||||||||||
| 98 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | while ( @{$self->{schedevents}} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@{$self->{"schedevents"};} and $self->{"schedevents"}[0]->next_time <= int(time) + 30
MC/DC0%0/2
@{$self->{"schedevents"};} and $self->{"schedevents"}[0]->next_time <= int(time) + 30
@{$self->{"schedevents"};}
$self->{"schedevents"}[0]->next_time <= int(time) + 30
Truth table0%0/3
A and B
A= @{$self->{"schedevents"};}B= $self->{"schedevents"}[0]->next_time <= int(time) + 30
| |||||||||||||||||||||||||||||
| 102 | && $self->{schedevents}->[0]->next_time <= (int(time) + 30) ) | ||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||
| 104 | 0 | my $se = shift @{$self->{schedevents}}; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | $se->run; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($se->reschedule) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||
| 110 | 0 | $self->add($se); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | else | ||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | # nothing to do with events | ||||||||||||||||||||||||||||
| 119 | sub event_callback | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
event_callback: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 121 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | return sub { }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # no fds to deal with | ||||||||||||||||||||||||||||
| 126 | sub select_fds | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
select_fds: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 128 | 0 | return (); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 1 | 1; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||