mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.6 KiB

  1. #!/bin/perl
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/scripts/parasim2.pl
  11. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. use strict;
  25. use English;
  26. my $logdir = $ARGV[0];
  27. my $config = $ARGV[1];
  28. my $id = $ARGV[2];
  29. my $freejobs = $id;
  30. my $runningjobs = 0;
  31. my $now = 0;
  32. my %jobs;
  33. my $qid;
  34. system("mkdir -p $logdir/logs_$id");
  35. open(LOG, "> $logdir/parasim_$id.log") || die $!;
  36. open(DAT, "> $logdir/parasim_$id.new") || die $!;
  37. $|=1; print "Running simulation for $id parallel jobs ...";
  38. while (1) {
  39. printf LOG "%10d: %d jobs currently running (%d idle)\n",
  40. $now, $runningjobs, $freejobs;
  41. printf DAT "%f\t$runningjobs\t%s\n",
  42. $now / 360000, join(" ", keys %jobs);
  43. print ".";
  44. foreach $qid (keys %jobs) {
  45. next if $jobs{$qid} > $now;
  46. printf LOG "%10d: Finished job $qid.\n", $now;
  47. system("rm -f $logdir/logs_$id/$qid.* ; " .
  48. "touch $logdir/logs_$id/$qid.log");
  49. $freejobs++; $runningjobs--; delete $jobs{$qid};
  50. }
  51. open(Q, "./scripts/Create-PkgQueue -cfg $config " .
  52. "-logdir $logdir/logs_$id | sort -r -n -k2 |") || die $!;
  53. while ($_=<Q> and $freejobs > 0) {
  54. @_ = split /\s+/; $qid="$_[0]-$_[5]";
  55. s/^.*\s(\S+)\s*$/$1/; $_++;
  56. printf LOG "%10d: Creating new job $qid " .
  57. "(pri $_[1], tm $_).\n", $now;
  58. system("rm -f $logdir/logs_$id/$qid.* ; " .
  59. "touch $logdir/logs_$id/$qid.out");
  60. $jobs{$qid} = $now + $_;
  61. $freejobs--; $runningjobs++;
  62. }
  63. close(Q);
  64. $_=-1;
  65. foreach $qid (keys %jobs) {
  66. $_=$jobs{$qid} if $_ == -1 or $_ > $jobs{$qid};
  67. }
  68. if ($_ == -1) { last; } else { $now=$_; }
  69. }
  70. printf DAT "%f\t0\n", $now / 360000;
  71. print "\nSimulated build for $id parallel jobs finished.\n\n";
  72. close LOG; close DAT;
  73. system("mv $logdir/parasim_$id.new $logdir/parasim_$id.dat");