improved planner

This commit is contained in:
ALEXks
2025-02-05 19:18:05 +03:00
parent e259a3c2a9
commit 68c21c6955
4 changed files with 45 additions and 7 deletions

View File

@@ -9,6 +9,13 @@
#include "File.h"
#include "Task.h"
#include "Array.h"
#include "Utils.h"
#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
#endif
#include <time.h>
enum SupervisorState {
WorkspacesCreation, //0
@@ -16,11 +23,12 @@ enum SupervisorState {
Execution, //2
End //3
};
template <class T>
class Supervisor : public Array <T> {
protected:
SupervisorState state;
public:
virtual String getStatePrefix() {
return String("");
@@ -108,11 +116,13 @@ public:
map<int, queue<T*>, std::greater<int>> sortedByKernelNeeds;
size_t activeTasks = 0;
size_t totalProcessTasks = 0;
int maxNeededKernels = 0;
for (auto& task : this->getElements()) {
if (task->getState() == WorkspaceReady) {
activeTasks++;
totalProcessTasks += task->getKernels();
sortedByKernelNeeds[task->getKernels()].push(task);
if (maxNeededKernels < task->getKernels())
maxNeededKernels = task->getKernels();
@@ -145,9 +155,10 @@ public:
vector<T*> toDel;
size_t done = 0;
size_t step = ceil(activeTasks * 0.01); // step == 1%
const double total = activeTasks;
size_t step = ceil(totalProcessTasks * 0.01); // step == 1%
const double total = totalProcessTasks;
auto timer_start = Utils::getAbsoluteTime();
while (activeTasks) {
long oldActiveTasks = activeTasks;
emptyKeys.clear();
@@ -189,7 +200,7 @@ public:
if (task->Check()) {
toDel.push_back(task);
activeTasks--;
done++;
done += task->getKernels();
busyKernels -= task->getKernels();
#if DEB
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
@@ -212,6 +223,16 @@ public:
saveProgress(persentDone);
}
}
// прошло больше 10 секунд, проверяем паузу
if (Utils::getAbsoluteTime() - timer_start > 30) {
printf("stoped\n");
while (checkPause()) {
Utils::Sleep(10);
}
timer_start = Utils::getAbsoluteTime();
printf("resume\n");
}
}
changeState();
@@ -219,10 +240,12 @@ public:
String outFile(pathRes + "/" + getStatePrefix() + "Info.txt");
File tmp(outFile, String(buf.c_str()));
}
void saveState() {
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
File tmp(stateFile, Utils::getDate());
}
void saveProgress(long long persentDone) {
FILE *f = fopen("progress", "w");
if (f) {
@@ -230,4 +253,13 @@ public:
fclose(f);
}
}
bool checkPause() {
FILE* f = fopen("pause", "w");
if (f) {
fclose(f);
return true;
}
return false;
}
};

View File

@@ -55,6 +55,7 @@ public:
std::chrono::seconds timespan(s);
std::this_thread::sleep_for(timespan);
}
static void Copy(const String& src, const String& dst) {
#if __cplusplus >= 201703L
std::filesystem::copy(src.getCharArray(), dst.getCharArray());
@@ -73,9 +74,11 @@ public:
//printf("cp -r '%s' return code = %d\n",src.getCharArray(),i);
#endif
}
static time_t getAbsoluteTime() {
return time(NULL);
}
static String getDate() {
auto ttime = time(NULL);
String res(ctime(&ttime));

View File

@@ -3,14 +3,17 @@ using namespace std;
#if __cplusplus >= 201703L
#include <filesystem>
#else
#include <unistd.h>
#endif
#include "CompilationSupervisor.h"
#include "RunSupervisor.h"
#include "Global.h"
#include <signal.h>
#ifndef _WIN32
#include <unistd.h>
#else
#endif
//https://ru.wikipedia.org/wiki/%D0%A1%D0%B8%D0%B3%D0%BD%D0%B0%D0%BB_(Unix)
void hdl(int sig)

View File

@@ -1 +1 @@
3
4