planner_improve #1
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "String.h"
|
||||||
#include "Text.h"
|
#include "Text.h"
|
||||||
|
|
||||||
class File {
|
class File {
|
||||||
FILE* ptr;
|
FILE* ptr;
|
||||||
public:
|
public:
|
||||||
@@ -15,6 +16,9 @@ public:
|
|||||||
fprintf(ptr, "%s\n", text.getCharArray());
|
fprintf(ptr, "%s\n", text.getCharArray());
|
||||||
}
|
}
|
||||||
~File() {
|
~File() {
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
void Close() {
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
fclose(ptr);
|
fclose(ptr);
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
|
|||||||
@@ -3,23 +3,25 @@ using namespace std;
|
|||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201703L
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "CompilationSupervisor.h"
|
#include "CompilationSupervisor.h"
|
||||||
#include "RunSupervisor.h"
|
#include "RunSupervisor.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
//https://ru.wikipedia.org/wiki/%D0%A1%D0%B8%D0%B3%D0%BD%D0%B0%D0%BB_(Unix)
|
//https://ru.wikipedia.org/wiki/%D0%A1%D0%B8%D0%B3%D0%BD%D0%B0%D0%BB_(Unix)
|
||||||
void hdl(int sig)
|
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() {
|
||||||
|
#ifndef _WIN32
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
memset(&act, 0, sizeof(act));
|
memset(&act, 0, sizeof(act));
|
||||||
act.sa_handler = hdl;
|
act.sa_handler = hdl;
|
||||||
@@ -80,7 +82,9 @@ void set_handlers(){
|
|||||||
sigaction(SIGVTALRM, &act, 0);
|
sigaction(SIGVTALRM, &act, 0);
|
||||||
sigaction(SIGXCPU, &act, 0);
|
sigaction(SIGXCPU, &act, 0);
|
||||||
sigaction(SIGXFSZ, &act, 0);
|
sigaction(SIGXFSZ, &act, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char ** argv)
|
int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
//+
|
//+
|
||||||
@@ -104,7 +108,12 @@ int main(int argc, char ** argv)
|
|||||||
userWorkspace.println();
|
userWorkspace.println();
|
||||||
packageWorkspace.println();
|
packageWorkspace.println();
|
||||||
printf("%d\n", maxKernels);
|
printf("%d\n", maxKernels);
|
||||||
|
#ifndef _WIN32
|
||||||
int pid = getpid();
|
int pid = getpid();
|
||||||
|
#else
|
||||||
|
int pid = _getpid();
|
||||||
|
#endif
|
||||||
|
|
||||||
printf("PID=%d\n", pid);
|
printf("PID=%d\n", pid);
|
||||||
File pidFile("PID", String(pid));
|
File pidFile("PID", String(pid));
|
||||||
pidFile.Close();
|
pidFile.Close();
|
||||||
|
|||||||
@@ -22,12 +22,14 @@ public:
|
|||||||
virtual String getStatePrefix() {
|
virtual String getStatePrefix() {
|
||||||
return String("Running");
|
return String("Running");
|
||||||
}
|
}
|
||||||
virtual void Finalize() {
|
|
||||||
|
/*
|
||||||
|
virtual void Finalize(){
|
||||||
this->state = Archivation;
|
this->state = Archivation;
|
||||||
saveState();
|
saveState();
|
||||||
printf("Archivation started\n");
|
printf("Archivation started\n");
|
||||||
Utils::ZipFolder(String("./"), String("archive.zip"));
|
Utils::ZipFolder(String("./"),String("archive.zip"));
|
||||||
printf("Archivation ended\n");
|
printf("Archivation ended\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -74,7 +74,12 @@ public:
|
|||||||
sprintf(body, "%d", s);
|
sprintf(body, "%d", s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String(long s) {
|
String(long s) {
|
||||||
|
String((long long)s);
|
||||||
|
}
|
||||||
|
|
||||||
|
String(long long s) {
|
||||||
length = 0;
|
length = 0;
|
||||||
body = new char[1];
|
body = new char[1];
|
||||||
body[0] = '\0';
|
body[0] = '\0';
|
||||||
@@ -87,7 +92,7 @@ public:
|
|||||||
}
|
}
|
||||||
length = size;
|
length = size;
|
||||||
body = new char[size + 1];
|
body = new char[size + 1];
|
||||||
sprintf(body, "%ld", s);
|
sprintf(body, "%lld", s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
|
#include "Array.h"
|
||||||
|
|
||||||
enum SupervisorState {
|
enum SupervisorState {
|
||||||
WorkspacesCreation, //0
|
WorkspacesCreation, //0
|
||||||
@@ -111,6 +112,7 @@ public:
|
|||||||
case Execution:
|
case Execution:
|
||||||
if (task->getState() == WorkspaceReady) {
|
if (task->getState() == WorkspaceReady) {
|
||||||
activeCount++;
|
activeCount++;
|
||||||
|
task->start_time = Utils::getAbsoluteTime();
|
||||||
task->Start();
|
task->Start();
|
||||||
}
|
}
|
||||||
else if (task->getState() == Running) {
|
else if (task->getState() == Running) {
|
||||||
@@ -130,6 +132,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DoWithSchedule(int maxKernels) {
|
void DoWithSchedule(int maxKernels) {
|
||||||
saveState();
|
saveState();
|
||||||
|
|
||||||
@@ -234,10 +237,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void Finalize() {}
|
virtual void Finalize() {}
|
||||||
|
|
||||||
void saveState() {
|
void saveState() {
|
||||||
Utils::Sleep(1); //чтобы не было одинаковых по дате файлов.
|
Utils::Sleep(1); //чтобы не было одинаковых по дате файлов.
|
||||||
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
|
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
|
||||||
//printf("stateFile=<%s>\n", stateFile.getCharArray());
|
//printf("stateFile=<%s>\n", stateFile.getCharArray());
|
||||||
File tmp(stateFile, Utils::getDate());
|
File(stateFile, Utils::getDate());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -36,13 +36,15 @@ enum TestType {
|
|||||||
class Task {
|
class Task {
|
||||||
protected:
|
protected:
|
||||||
long id;
|
long id;
|
||||||
|
|
||||||
int maxtime;
|
int maxtime;
|
||||||
int kernels; //получение зависит от типа задачи.
|
int kernels; //получение зависит от типа задачи.
|
||||||
String workspace;
|
String workspace;
|
||||||
TaskState state;
|
TaskState state;
|
||||||
public:
|
public:
|
||||||
String printState() {
|
long start_time;
|
||||||
switch (state) {
|
String printState(){
|
||||||
|
switch(state){
|
||||||
case Inactive:
|
case Inactive:
|
||||||
return String("Inactive");
|
return String("Inactive");
|
||||||
case Waiting:
|
case Waiting:
|
||||||
@@ -87,6 +89,7 @@ public:
|
|||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------->>
|
//-------------->>
|
||||||
long getId() { return id; }
|
long getId() { return id; }
|
||||||
long setId(String* id_s) {
|
long setId(String* id_s) {
|
||||||
@@ -146,13 +149,17 @@ public:
|
|||||||
if (Utils::Exists(workspace + "/TIMEOUT")) {
|
if (Utils::Exists(workspace + "/TIMEOUT")) {
|
||||||
state = AbortedByTimeout;
|
state = AbortedByTimeout;
|
||||||
//todo определить по интервалу времени на всякий случай.
|
//todo определить по интервалу времени на всякий случай.
|
||||||
}
|
}else if (Utils::Exists(workspace+"/INTERRUPT")){
|
||||||
else if (Utils::Exists(workspace + "/INTERRUPT")) {
|
state=AbortedByUser;
|
||||||
state = AbortedByUser;
|
} else {
|
||||||
|
long now = Utils::getAbsoluteTime();
|
||||||
|
long delta = now-start_time;
|
||||||
|
if (maxtime<delta){
|
||||||
|
state=AbortedByTimeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (state != Running) {
|
if (state!=Running){
|
||||||
//-
|
//-
|
||||||
busyKernels = Utils::min(busyKernels - kernels, maxKernels);
|
busyKernels = Utils::min(busyKernels - kernels, maxKernels);
|
||||||
freeKernels = Utils::max(0, maxKernels - busyKernels);
|
freeKernels = Utils::max(0, maxKernels - busyKernels);
|
||||||
|
|||||||
Reference in New Issue
Block a user