planner #5

Merged
M merged 2 commits from planner into main 2023-12-10 22:23:52 +00:00
9 changed files with 59 additions and 23 deletions

View File

@@ -10,12 +10,13 @@ public:
void setTestId(String* test_id_in) {
test_id = String(test_id_in->getCharArray());
}
void setMakefileText(String* makefile_text_in) {
makefile_text = String(makefile_text_in->getCharArray(), '|');
}
virtual void print() const {
printf("id=%ld; maxtime=%d; test_id=%s\n", id, maxtime,
test_id.getCharArray());
printf("id=%ld; maxtime=%d; test_id=%s\n", id, maxtime, test_id.getCharArray());
printf("makefile_text=%s\n", makefile_text.getCharArray());
}

View File

@@ -17,7 +17,7 @@ void hdl(int sig)
{
String file_name = "GOT_SIGNAL_AT_"+ String(Utils::getAbsoluteTime());
FILE * res = fopen(file_name.getCharArray(),"w");
fprintf(res,"%d\n", sig);
fprintf(res, "%d\n", sig);
fclose(res);
}
void set_handlers() {
@@ -105,30 +105,41 @@ int main(int argc, char ** argv)
chdir(packageWorkspace.getCharArray());
#endif
userWorkspace.println();
packageWorkspace.println();
#if DEB
userWorkspace.println();
packageWorkspace.println();
printf("%d\n", maxKernels);
#endif
#ifndef _WIN32
int pid = getpid();
#else
int pid = _getpid();
#endif
#if DEB
printf("PID=%d\n", pid);
#endif
File pidFile("PID", String(pid)+"\n");
pidFile.Close();
//---
File startFile("STARTED", "+");
startFile.Close();
//---
#if DEB
printf(">>>>\n");
CompilationSupervisor * compilationSupervisor = new CompilationSupervisor();
#endif
CompilationSupervisor * compilationSupervisor = new CompilationSupervisor();
#if DEB
printf("%ld\n", compilationSupervisor->getLength());
#endif
compilationSupervisor->DoWithSchedule(maxKernels);
RunSupervisor * runSupervisor = new RunSupervisor(compilationSupervisor);
printf("%ld\n", runSupervisor->getLength());
runSupervisor->print();
#if DEB
printf("%ld\n", runSupervisor->getLength());
runSupervisor->print();
#endif
runSupervisor->DoWithSchedule(maxKernels);
return 0;
}

View File

@@ -13,10 +13,9 @@ public:
CompilationTask* parent = compilationSupervisor->getTaskById(task->getTestCompilationTaskId());
task->setState((parent->getState() == Done) ? Waiting : Canceled);
task->setParent(parent);
printf("id=%ld; parent_id = %ld; state=%s\n",
task->getId(),
task->getParent()->getId(),
task->printState().getCharArray());
#if DEB
printf("id=%ld; parent_id = %ld; state=%s\n", task->getId(), task->getParent()->getId(), task->printState().getCharArray());
#endif
}
}

View File

@@ -74,7 +74,7 @@ public:
return String::DQuotes(starterCall) + " " +
String::DQuotes(launcherCall) + " " +
String(maxtime) + " " +
String::DQuotes("killall -SIGKILL " + binary_name) + " " +
String::DQuotes("killall -SIGKILL " + binary_name + " 1>/dev/null 2>/dev/null") + " " +
dvm_start;
}
@@ -92,7 +92,9 @@ public:
String res = workspace + "/run";
if (!environments.isEmpty())
res = environments + " " + res;
#if DEB
printf("START %ld: %s\n", id, res.getCharArray());
#endif
return res;
}

View File

@@ -61,7 +61,9 @@ public:
String res = String(this->getCharArray());
for (auto i = 0; i < getLength(); ++i)
res.body[i] = toupper(body[i]);
#if DEB
res.println();
#endif
return res;
}
};

View File

@@ -104,9 +104,8 @@ public:
}
map<int, queue<T*>, std::greater<int>> sortedByKernelNeeds;
long activeTasks = 0;
long done = 0;
size_t activeTasks = 0;
for (auto& task : this->getElements()) {
if (task->getState() == WorkspaceReady) {
activeTasks++;
@@ -126,6 +125,10 @@ public:
vector<int> emptyKeys;
vector<T*> toDel;
size_t done = 0;
size_t step = activeTasks * 0.01; // step == 1%
const double total = activeTasks;
while (activeTasks) {
long oldActiveTasks = activeTasks;
@@ -143,8 +146,9 @@ public:
activeTaskSet.insert(task);
task->Start(ignoreCheck);
#if DEB
printf("start task with %d kernels and id %ld\n", task->getKernels(), task->getId());
#endif
busyKernels += task->getKernels();
freeKernels = maxKernels - busyKernels;
}
@@ -169,8 +173,9 @@ public:
activeTasks--;
done++;
busyKernels -= task->getKernels();
#if DEB
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
#endif
buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n";
task->copyResults(pathRes);
}
@@ -180,8 +185,19 @@ public:
for (auto& del : toDel)
activeTaskSet.erase(del);
if (oldActiveTasks != activeTasks)
printf("done %ld / %ld\n", done, this->getLength());
if (oldActiveTasks != activeTasks) {
#if DEB
printf("done %ld / %d\n", done, this->getLength());
#endif
if ((done % step) == 0) {
size_t persentDone = (done / total) * 100.0;
FILE *f = fopen("progress", "w");
if (f) {
fprintf(f, "%lld\n", persentDone);
fclose(f);
}
}
}
}
changeState();

View File

@@ -168,7 +168,9 @@ public:
std::chrono::duration<double> diff_time = end_time - start_time;
if (maxtime * 1.1 < diff_time.count()) {
#if DEB
printf("SET STATUS ABORTED by timer to %ld with time %f sec / %f sec", id, diff_time.count(), maxtime * 1.1);
#endif
state = AbortedByTimeout;
}
}
@@ -184,7 +186,9 @@ public:
auto end_time = std::chrono::system_clock::now();
std::chrono::duration<double> diff_time = end_time - start_time;
total_time = diff_time.count();
#if DEB
printf("%ld done with time %f\n", id, total_time);
#endif
state = Finished;
}
virtual String copyResults(const String& pathRes) {

View File

@@ -36,7 +36,7 @@ public:
#else
String command = "chmod 777 " + String::DQuotes(path);
int i=system(command.getCharArray());
printf("chmod 777 '%s' return code = %d\n", path.getCharArray(), i);
//printf("chmod 777 '%s' return code = %d\n", path.getCharArray(), i);
#endif
}
@@ -61,7 +61,7 @@ public:
#else
String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst);
int i = system(command.getCharArray());
printf("cp '%s' return code = %d\n",src.getCharArray(), i);
//printf("cp '%s' return code = %d\n",src.getCharArray(), i);
#endif
}
static void CopyDirectory(const String& src, const String& dst) {
@@ -70,7 +70,7 @@ public:
#else
String command = "cp -r " + String::DQuotes(src + "/.") + " " + String::DQuotes(dst);
int i = system(command.getCharArray());
printf("cp -r '%s' return code = %d\n",src.getCharArray(),i);
//printf("cp -r '%s' return code = %d\n",src.getCharArray(),i);
#endif
}
static time_t getAbsoluteTime() {

View File

@@ -0,0 +1 @@
1