* updated pyxdg (0.19 -> 0.28)
[t2sde.git] / scripts / parasim2.pl
blob04a06236dadb386e87062dee2681822f46e5be93
1 #!/bin/perl
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # This copyright note is auto-generated by scripts/Create-CopyPatch.
5 #
6 # T2 SDE: scripts/parasim2.pl
7 # Copyright (C) 2004 - 2020 The T2 SDE Project
8 # Copyright (C) 1998 - 2003 ROCK Linux Project
9 #
10 # More information can be found in the files COPYING and README.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; version 2 of the License. A copy of the
15 # GNU General Public License can be found in the file COPYING.
16 # --- T2-COPYRIGHT-NOTE-END ---
18 use strict;
19 use English;
21 my $logdir = $ARGV[0];
22 my $config = $ARGV[1];
23 my $id = $ARGV[2];
25 my $freejobs = $id;
26 my $runningjobs = 0;
27 my $now = 0;
29 my %jobs;
30 my $qid;
32 system("mkdir -p $logdir/logs_$id");
34 open(LOG, "> $logdir/parasim_$id.log") || die $!;
35 open(DAT, "> $logdir/parasim_$id.new") || die $!;
37 $|=1; print "Running simulation for $id parallel jobs ...";
39 while (1) {
40 printf LOG "%10d: %d jobs currently running (%d idle)\n",
41 $now, $runningjobs, $freejobs;
42 printf DAT "%f\t$runningjobs\t%s\n",
43 $now / 360000, join(" ", keys %jobs);
44 print ".";
46 foreach $qid (keys %jobs) {
47 next if $jobs{$qid} > $now;
48 printf LOG "%10d: Finished job $qid.\n", $now;
49 system("rm -f $logdir/logs_$id/$qid.*; " .
50 "touch $logdir/logs_$id/$qid.log");
51 $freejobs++; $runningjobs--; delete $jobs{$qid};
54 open(Q, "scripts/Create-PkgQueue -cfg $config " .
55 "-logdir $logdir/logs_$id | sort -r -n -k2 |") || die $!;
56 while ($_=<Q> and $freejobs > 0) {
57 @_ = split /\s+/; $qid="$_[0]-$_[5]";
58 s/^.*\s(\S+)\s*$/$1/; $_++;
59 printf LOG "%10d: Creating new job $qid " .
60 "(pri $_[1], tm $_).\n", $now;
61 system("rm -f $logdir/logs_$id/$qid.*; " .
62 "touch $logdir/logs_$id/$qid.out");
63 $jobs{$qid} = $now + $_;
64 $freejobs--; $runningjobs++;
66 close(Q);
68 $_=-1;
69 foreach $qid (keys %jobs) {
70 $_=$jobs{$qid} if $_ == -1 or $_ > $jobs{$qid};
72 if ($_ == -1) { last; } else { $now=$_; }
75 printf DAT "%f\t0\n", $now / 360000;
76 print "\nSimulated build for $id parallel jobs finished.\n\n";
78 close LOG; close DAT;
79 system("mv $logdir/parasim_$id.new $logdir/parasim_$id.dat");