-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbenchmark_them_all.pl
137 lines (120 loc) · 5.17 KB
/
benchmark_them_all.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program comes with ABSOLUTELY NO WARRANTY;
use Modern::Perl;
use File::Basename qw( dirname );
use Cwd 'abs_path';
use IPC::Cmd qw( run );
my $iterations = 5;
my @versions = qw( 3.14 3.16 3.18 3.20 3.22 16.05 16.11 );
our $koha_root = q|/home/vagrant/kohaclone|;
my $git_remote = q|Joubu|;
our $verbose = 0;
our $kohadev = q|kohadev|;
our $output_dir = q|/tmp|;
our ( $cmd, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf );
our $PERL5LIB = $ENV{PERL5LIB};
chdir $koha_root;
for my $version ( @versions ) {
msg("Version $version", 5);
my $branch_name = qq|perf_${version}.x|;
$cmd = "git rev-parse --verify $branch_name";
( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => 0 );
$cmd = $success
? "git checkout $branch_name"
: "git checkout -b $branch_name $git_remote/$branch_name";
( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => $verbose );
die "Fail to create a local branch ($branch_name) from repo '$git_remote'. Make sure it exists" unless $success;
if ( -f $koha_root . '/debian/templates/plack.psgi' ) {
my @output = do_all_iterations( "with_plack" );
write_output( $version . '_plack', @output );
}
my @output = do_all_iterations();
write_output( $version, @output );
}
sub reset_my_db {
$cmd = qq|mysql -u koha_$kohadev -ppassword -e"DROP DATABASE koha_$kohadev"|;
( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => $verbose );
$cmd = qq|mysql -u koha_$kohadev -ppassword -e"CREATE DATABASE koha_$kohadev"|;
( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => $verbose );
$cmd = q|perl /home/vagrant/koha-misc4dev/do_all_you_can_do.pl|;
( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => $verbose );
}
sub restart_memcached {
$cmd = q|sudo service memcached restart|;
run( command => $cmd, verbose => $verbose );
}
sub restart_plack {
$cmd = qq|sudo koha-plack --restart $kohadev|;
run( command => $cmd, verbose => $verbose );
}
sub restart_apache {
$cmd = qq|sudo service apache2 restart|;
run( command => $cmd, verbose => $verbose );
}
sub enable_plack {
$cmd = qq|sudo cp $koha_root/debian/templates/plack.psgi /etc/koha/sites/kohadev/plack.psgi|;
( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => $verbose );
`sudo perl -p -i -e s#/usr/share/koha/intranet/cgi-bin#/home/vagrant/kohaclone# /etc/koha/sites/kohadev/plack.psgi`;
`sudo perl -p -i -e s#/usr/share/koha/lib#/home/vagrant/kohaclone# /etc/koha/sites/kohadev/plack.psgi`;
`sudo perl -p -i -e s#/usr/share/koha/opac/cgi-bin/opac#/home/vagrant/kohaclone/opac# /etc/koha/sites/kohadev/plack.psgi`;
$cmd = qq|sudo koha-plack --enable kohadev|;
( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => $verbose );
restart_plack();
restart_apache();
}
sub disable_plack {
$cmd = qq|sudo koha-plack --disable kohadev|;
( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => $verbose );
restart_apache();
}
sub do_all_iterations {
my ( $with_plack ) = @_;
msg( ( $with_plack ? "With Plack" : "Without Plack" ), 4);
msg("Reset the database", 3);
reset_my_db();
msg("Restart memcached", 3);
restart_memcached();
msg( ( $with_plack ? "Enable Plack" : "Disable Plack" ), 3);
$with_plack ? enable_plack() : disable_plack();
my ( @output, $output );
msg("First shoot to populate caches", 3);
do_one_iteration();
for my $i ( 1 .. $iterations ) {
msg("Processing Iteration $i/$iterations" . ( $with_plack ? " (plack)" : "" ), 3);
$output = do_one_iteration();
push @output, @$output;
}
return @output;
}
sub do_one_iteration {
$cmd = qq|sudo koha-shell $kohadev -p -c "PERL5LIB=$PERL5LIB perl t/db_dependent/selenium/basic_workflow.t"|;
( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run( command => $cmd, verbose => $verbose );
return $stderr_buf;
}
sub msg {
my ( $msg, $level ) = @_;
$level //= 1;
say "=" x $level
. " $msg "
. "=" x $level;
}
sub write_output {
my ( $filename, @output ) = @_;
my $filepath = "$output_dir/$filename.txt";
open my $fh, '>', $filepath or die "Cannot write output to $filepath ($!)";
print $fh join "", @output;
close $fh;
}
exit(0);