OpenSDE Framework (without history before r20070)
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.

79 lines
2.2 KiB

  1. #!/bin/perl
  2. #
  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 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  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 ---
  17. use strict;
  18. use English;
  19. my $logdir = $ARGV[0];
  20. my $config = $ARGV[1];
  21. my $id = $ARGV[2];
  22. my $freejobs = $id;
  23. my $runningjobs = 0;
  24. my $now = 0;
  25. my %jobs;
  26. my $qid;
  27. system("mkdir -p $logdir/logs_$id");
  28. open(LOG, "> $logdir/parasim_$id.log") || die $!;
  29. open(DAT, "> $logdir/parasim_$id.new") || die $!;
  30. $|=1; print "Running simulation for $id parallel jobs ...";
  31. while (1) {
  32. printf LOG "%10d: %d jobs currently running (%d idle)\n",
  33. $now, $runningjobs, $freejobs;
  34. printf DAT "%f\t$runningjobs\t%s\n",
  35. $now / 360000, join(" ", keys %jobs);
  36. print ".";
  37. foreach $qid (keys %jobs) {
  38. next if $jobs{$qid} > $now;
  39. printf LOG "%10d: Finished job $qid.\n", $now;
  40. system("rm -f $logdir/logs_$id/$qid.* ; " .
  41. "touch $logdir/logs_$id/$qid.log");
  42. $freejobs++; $runningjobs--; delete $jobs{$qid};
  43. }
  44. open(Q, "./scripts/Create-PkgQueue -cfg $config " .
  45. "-logdir $logdir/logs_$id | sort -r -n -k2 |") || die $!;
  46. while ($_=<Q> and $freejobs > 0) {
  47. @_ = split /\s+/; $qid="$_[0]-$_[5]";
  48. s/^.*\s(\S+)\s*$/$1/; $_++;
  49. printf LOG "%10d: Creating new job $qid " .
  50. "(pri $_[1], tm $_).\n", $now;
  51. system("rm -f $logdir/logs_$id/$qid.* ; " .
  52. "touch $logdir/logs_$id/$qid.out");
  53. $jobs{$qid} = $now + $_;
  54. $freejobs--; $runningjobs++;
  55. }
  56. close(Q);
  57. $_=-1;
  58. foreach $qid (keys %jobs) {
  59. $_=$jobs{$qid} if $_ == -1 or $_ > $jobs{$qid};
  60. }
  61. if ($_ == -1) { last; } else { $now=$_; }
  62. }
  63. printf DAT "%f\t0\n", $now / 360000;
  64. print "\nSimulated build for $id parallel jobs finished.\n\n";
  65. close LOG; close DAT;
  66. system("mv $logdir/parasim_$id.new $logdir/parasim_$id.dat");