Skip to content

Commit aa374ae

Browse files
committed
Slight reworking of Statisfiable
Now statisfiable won't ping out when it is busy. In addition, now it should be a bit easier to add new graphs. Also, implement a graph requested in issue #94. It is needlesly using rakudo commits for X steps, but that's not a big deal.
1 parent 7fbfd2c commit aa374ae

File tree

1 file changed

+76
-51
lines changed

1 file changed

+76
-51
lines changed

Statisfiable.p6

Lines changed: 76 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -31,81 +31,106 @@ unit class Statisfiable does Whateverable;
3131
constant RANGE = 2014.01..HEAD;
3232
constant STATS-LOCATION = ./stats.IO.absolute;
3333

34+
constant OPTIONS = %(
35+
core => CORE.setting.moarvm file size (MB),
36+
# ‘core.lines’ => ‘Lines in CORE.setting.moarvm file (count)’,
37+
install => Space taken by a full installation (MB),
38+
libmoar => libmoar.so file size (MB),
39+
);
40+
3441
has %stats;
42+
has %stat-locks;
3543

3644
method TWEAK {
3745
mkdir STATS-LOCATION if STATS-LOCATION.IO !~~ :d;
38-
if {STATS-LOCATION}/ {
39-
%stats<core> = from-json slurp {STATS-LOCATION}/core if {STATS-LOCATION}/core.IO.e;
40-
%stats<core> //= %();
41-
%stats<install> = from-json slurp {STATS-LOCATION}/install if {STATS-LOCATION}/install.IO.e;
42-
%stats<install> //= %()
46+
for OPTIONS.keys {
47+
%stat-locks{$_} = Lock.new;
48+
%stats{$_} = {STATS-LOCATION}/$_.IO.e
49+
from-json slurp {STATS-LOCATION}/$_
50+
%()
4351
}
4452
}
4553

4654
method help($) {
47-
Available stats: core (CORE.setting size), install (size of the whole installation).
55+
Available stats: ~ (
56+
core (CORE.setting size),
57+
# ‘core.lines (lines in CORE.setting)’,
58+
install (size of the installation),
59+
libmoar (libmoar.so size),
60+
).join: ,
4861
}
4962

50-
multi method irc-to-me($msg where /:i [ core | install ] /) {
51-
my ($value, %additional-files) = self.process: $msg, $msg.text;
52-
return without $value;
53-
return ($value but $msg) but FileStore(%additional-files)
63+
multi method stat-for-commit(core, $full-hash) {
64+
self.run-smth: $full-hash, {
65+
my $file = $_/share/perl6/runtime/CORE.setting.moarvm.IO;
66+
$file.IO.e$file.IO.s ÷ 10⁶ ‼ Nil
67+
}
5468
}
5569

56-
multi method process($msg, $query) {
57-
$msg.reply: OK! Working on it…;
70+
#multi method stat-for-commit(‘core.lines’, $full-hash) {
71+
# # TODO
72+
#}
73+
74+
multi method stat-for-commit(install, $full-hash) {
75+
self.run-smth: $full-hash, {
76+
# ↓ scary, but works
77+
my $result = Rakudo::Internals.DIR-RECURSE($_).map(*.IO.s).sum ÷ 10⁶;
78+
$result > 10$resultNil
79+
}
80+
}
81+
82+
multi method stat-for-commit(libmoar, $full-hash) {
83+
self.run-smth: $full-hash, {
84+
my $file = $_/lib/libmoar.so.IO;
85+
$file.IO.e$file.IO.s ÷ 10⁶ ‼ Nil
86+
}
87+
}
5888

59-
my $type = $query ~~ /:i core / ⁇ coreinstall;
60-
my $zero = $query ~~ / 0 / ⁇ 0Nil;
61-
my %data := %stats{$type};
89+
multi method irc-to-me($msg where /:i ( <{OPTIONS.keys}> ) (0)? /) {
90+
my $type = ~$0;
91+
my $zeroed = ?$1;
92+
start {
93+
my ($value, %additional-files) = self.process: $msg, $type, $zeroed;
94+
$value.defined
95+
⁇ ($value but $msg) but FileStore(%additional-files)
96+
Nil
97+
}
98+
}
6299

63-
my @git = git, --git-dir, {RAKUDO}/.git, --work-tree, RAKUDO;
64-
my @command = |@git, log, -z, --pretty=%H, RANGE;
100+
multi method process($msg, $type, $zeroed) {
101+
$msg.reply: OK! Working on it…;
65102

66-
my $let's-save = False;
67103
my @results;
68-
for run(:out, |@command).out.split: 0.chr, :skip-empty {
69-
next unless $_;
70-
my $full = $_;
71-
#my $short = self.to-full-commit($_, :short);
72-
73-
my $size;
74-
if %data{$full}:exists {
75-
$size = %data{$full}
76-
} else {
77-
if self.build-exists: $full {
78-
if $type eq core { # core
79-
$size = self.run-smth: $full, {
80-
my $file = $_/share/perl6/runtime/CORE.setting.moarvm.IO;
81-
$file.IO.e$file.IO.s ÷ 10⁶ ‼ Nil
82-
}
83-
} else { # install
84-
$size = self.run-smth: $full, {
85-
# ↓ scary, but works
86-
Rakudo::Internals.DIR-RECURSE($_).map(*.IO.s).sum ÷ 10
87-
}
88-
}
104+
%stat-locks{$type}.protect: {
105+
my %data := %stats{$type};
106+
107+
my $let's-save = False;
108+
109+
my @git = git, --git-dir, {RAKUDO}/.git, --work-tree, RAKUDO;
110+
my @command = |@git, log, -z, --pretty=%H, RANGE;
111+
for run(:out, |@command).out.split: 0.chr, :skip-empty -> $full {
112+
next unless $full;
113+
#my $short = self.to-full-commit($_, :short);
114+
115+
if %data{$full}:!exists and self.build-exists: $full {
116+
%data{$full} = self.stat-for-commit($type, $full);
117+
$let's-save = True
89118
}
90-
%data{$full} = $size;
91-
$let's-save = True
119+
@results.push: ($full, $_) with %data{$full}
92120
}
93-
@results.push: ($full, $size) if $size and ($type eq core or $size > 10)
94-
}
95-
96-
spurt {STATS-LOCATION}/$type, to-json %data if $let's-save;
97121

122+
spurt {STATS-LOCATION}/$type, to-json %data if $let's-save;
123+
}
98124

99125
my $pfilename = plot.svg;
100-
my $title = $type eq coreCORE.setting.moarvm file size (MB)
101-
Installation size (MB);
126+
my $title = OPTIONS{$type};
102127
my @values = @results.reverse»[1];
103128
my @labels = @results.reverse»[0.substr: 0, 8;
104129

105130
my $plot = SVG::Plot.new(
106-
width => 1000,
107-
height => 800,
108-
min-y-axis => $zero,
131+
:1000width,
132+
:800height,
133+
min-y-axis => $zeroed0Nil,
109134
:$title,
110135
values => (@values,),
111136
:@labels,
@@ -115,7 +140,7 @@ multi method process($msg, $query) {
115140

116141
my $msg-response = @results.reverse.map(*.join: ).join: \n;
117142

118-
($msg-response, %graph)
143+
$msg-response, %graph
119144
}
120145

121146
Statisfiable.new.selfrun: statisfiable6, [/stat6?/, fuzzy-nick(statisfiable6, 3) ]

0 commit comments

Comments
 (0)