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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -36,7 +36,7 @@ public:
#else #else
String command = "chmod 777 " + String::DQuotes(path); String command = "chmod 777 " + String::DQuotes(path);
int i=system(command.getCharArray()); 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 #endif
} }
@@ -61,7 +61,7 @@ public:
#else #else
String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst); String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst);
int i = system(command.getCharArray()); 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 #endif
} }
static void CopyDirectory(const String& src, const String& dst) { static void CopyDirectory(const String& src, const String& dst) {
@@ -70,7 +70,7 @@ public:
#else #else
String command = "cp -r " + String::DQuotes(src + "/.") + " " + String::DQuotes(dst); String command = "cp -r " + String::DQuotes(src + "/.") + " " + String::DQuotes(dst);
int i = system(command.getCharArray()); 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 #endif
} }
static time_t getAbsoluteTime() { static time_t getAbsoluteTime() {

View File

@@ -0,0 +1 @@
1