перенос кода Planner
This commit is contained in:
16
.idea/workspace.xml
generated
16
.idea/workspace.xml
generated
@@ -6,7 +6,21 @@
|
|||||||
</artifacts-to-build>
|
</artifacts-to-build>
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="" />
|
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/Array.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/Array.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/CompilationSupervisor.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/CompilationSupervisor.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/CompilationTask.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/CompilationTask.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/File.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/File.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/Global.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/Global.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/Planner.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/Planner.cpp" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/RunSupervisor.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/RunSupervisor.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/RunTask.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/RunTask.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/String.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/String.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/Supervisor.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/Supervisor.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/Task.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/Task.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/Text.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/Text.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/files/Planner/Utils.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/Utils.h" afterDir="false" />
|
||||||
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
|||||||
@@ -1,42 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#pragma once
|
#include <vector>
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class Array {
|
class Array {
|
||||||
protected:
|
private:
|
||||||
long length;
|
std::vector<T*> elements;
|
||||||
T** elements;
|
|
||||||
public:
|
public:
|
||||||
Array(){
|
Array() { }
|
||||||
length=0;
|
|
||||||
elements=NULL;
|
virtual ~Array() {
|
||||||
|
for (auto& elem : elements)
|
||||||
|
delete elem;
|
||||||
|
elements.clear();
|
||||||
}
|
}
|
||||||
virtual ~Array(){
|
|
||||||
if (elements !=NULL){
|
void add(T* new_line) {
|
||||||
for (long i=0; i<length; ++i)
|
elements.push_back(new_line);
|
||||||
delete elements[i];
|
|
||||||
delete [] elements;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void add(T * new_line) {
|
|
||||||
T ** buf = new T*[length + 1];
|
long getLength() const {
|
||||||
for (long i = 0; i < length; ++i) {
|
return (long)elements.size();
|
||||||
buf[i] = elements[i];
|
|
||||||
}
|
|
||||||
buf[length] = new_line;
|
|
||||||
length++;
|
|
||||||
delete[] elements;
|
|
||||||
elements = buf;
|
|
||||||
buf = NULL;
|
|
||||||
}
|
}
|
||||||
long getLength(){
|
|
||||||
return length;
|
T* get(long i) {
|
||||||
|
return elements[i];
|
||||||
}
|
}
|
||||||
T * get(long i){
|
|
||||||
return elements[i];
|
const std::vector<T*>& getElements() const {
|
||||||
}
|
|
||||||
T** getElements(){
|
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,20 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "Supervisor.h"
|
#include "Supervisor.h"
|
||||||
#include "CompilationTask.h"
|
#include "CompilationTask.h"
|
||||||
#pragma once
|
|
||||||
class CompilationSupervisor: public Supervisor<CompilationTask> {
|
class CompilationSupervisor : public Supervisor<CompilationTask> {
|
||||||
public:
|
public:
|
||||||
CompilationSupervisor(){
|
CompilationSupervisor() {
|
||||||
this->init("compilationTasks", 4);
|
this->init("compilationTasks", 4);
|
||||||
}
|
}
|
||||||
CompilationTask * getTaskById(long task_id){
|
CompilationTask* getTaskById(long task_id) {
|
||||||
for (long i=0; i< length; ++i){
|
for (long i = 0; i < getLength(); ++i) {
|
||||||
CompilationTask * task = get(i);
|
CompilationTask* task = get(i);
|
||||||
if (task->getId()==task_id)
|
if (task->getId() == task_id)
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
virtual String getStatePrefix(){
|
virtual String getStatePrefix() {
|
||||||
return String("Compilation");
|
return String("Compilation");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,47 +1,51 @@
|
|||||||
#include "Task.h"
|
|
||||||
#pragma once
|
#pragma once
|
||||||
class CompilationTask: public Task {
|
|
||||||
String test_id;
|
#include "Task.h"
|
||||||
String makefile_text;
|
#include "Text.h"
|
||||||
public:
|
|
||||||
void setTestId(String * test_id_in){
|
class CompilationTask : public Task {
|
||||||
test_id = String(test_id_in->getCharArray());
|
String test_id;
|
||||||
}
|
String makefile_text;
|
||||||
void setMakefileText(String * makefile_text_in){
|
public:
|
||||||
makefile_text = String(makefile_text_in->getCharArray(), '|');
|
void setTestId(String* test_id_in) {
|
||||||
}
|
test_id = String(test_id_in->getCharArray());
|
||||||
virtual void print(){
|
}
|
||||||
printf("id=%ld; maxtime=%d; test_id=%s\n", id, maxtime,
|
void setMakefileText(String* makefile_text_in) {
|
||||||
test_id.getCharArray());
|
makefile_text = String(makefile_text_in->getCharArray(), '|');
|
||||||
printf("makefile_text=%s\n", makefile_text.getCharArray());
|
}
|
||||||
}
|
virtual void print() const {
|
||||||
CompilationTask(Text * lines, int offset):Task(lines,offset) {
|
printf("id=%ld; maxtime=%d; test_id=%s\n", id, maxtime,
|
||||||
setTestId(lines->get(offset+2));
|
test_id.getCharArray());
|
||||||
setMakefileText(lines->get(offset+3));
|
printf("makefile_text=%s\n", makefile_text.getCharArray());
|
||||||
setState(Waiting);
|
}
|
||||||
kernels=1;
|
|
||||||
}
|
CompilationTask(Text* lines, int offset) :Task(lines, offset) {
|
||||||
|
setTestId(lines->get(offset + 2));
|
||||||
virtual void prepareWorkspace(){
|
setMakefileText(lines->get(offset + 3));
|
||||||
String makeFilePath = String(id)+"/Makefile";
|
setState(Waiting);
|
||||||
File makeFileFile = File(makeFilePath, this->makefile_text);
|
kernels = 1;
|
||||||
String tests = userWorkspace+"/projects";
|
}
|
||||||
String testPath= tests+"/"+test_id;
|
|
||||||
String copyCommand = "cp -r " + String::DQuotes(testPath + "/.") + " "+ String::DQuotes(workspace);
|
virtual void prepareWorkspace() {
|
||||||
system(copyCommand.getCharArray());
|
String makeFilePath = String(id) + "/Makefile";
|
||||||
}
|
File makeFileFile = File(makeFilePath, this->makefile_text);
|
||||||
virtual String getLaunchScriptText(){
|
String tests = userWorkspace + "/projects";
|
||||||
String modules = userWorkspace+"/modules";
|
String testPath = tests + "/" + test_id;
|
||||||
String starterCall = modules+"/starter";
|
String copyCommand = "cp -r " + String::DQuotes(testPath + "/.") + " " + String::DQuotes(workspace);
|
||||||
String launcherCall = modules+"/launcher";
|
system(copyCommand.getCharArray());
|
||||||
return String::DQuotes(starterCall)+" "+
|
}
|
||||||
String::DQuotes(launcherCall)+" "+
|
virtual String getLaunchScriptText() {
|
||||||
String(maxtime)+" "+
|
String modules = userWorkspace + "/modules";
|
||||||
String::DQuotes("")+" "+
|
String starterCall = modules + "/starter";
|
||||||
"make -j -f Makefile";
|
String launcherCall = modules + "/launcher";
|
||||||
}
|
return String::DQuotes(starterCall) + " " +
|
||||||
virtual void analyseResults(){
|
String::DQuotes(launcherCall) + " " +
|
||||||
String binary = workspace+"/0";
|
String(maxtime) + " " +
|
||||||
state = Utils::Exists(binary)? Done:DoneWithErrors;
|
String::DQuotes("") + " " +
|
||||||
|
"make -j -f Makefile";
|
||||||
|
}
|
||||||
|
virtual void analyseResults() {
|
||||||
|
String binary = workspace + "/0";
|
||||||
|
state = Utils::Exists(binary) ? Done : DoneWithErrors;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,67 +1,70 @@
|
|||||||
#include "Text.h"
|
#pragma once
|
||||||
#pragma once
|
#include "String.h"
|
||||||
class File {
|
#include "Text.h"
|
||||||
FILE* ptr;
|
|
||||||
public:
|
class File {
|
||||||
File(String* name) {
|
FILE* ptr;
|
||||||
ptr = fopen(name->getCharArray(), "r");
|
public:
|
||||||
}
|
File(String* name) {
|
||||||
File(const char * name) {
|
ptr = fopen(name->getCharArray(), "r");
|
||||||
ptr = fopen(name, "r");
|
}
|
||||||
}
|
File(const char* name) {
|
||||||
File(const String& name, const String& text){
|
ptr = fopen(name, "r");
|
||||||
ptr = fopen(name.getCharArray(), "w");
|
}
|
||||||
fprintf(ptr, "%s\n", text.getCharArray());
|
File(const String& name, const String& text) {
|
||||||
}
|
ptr = fopen(name.getCharArray(), "w");
|
||||||
~File() {
|
fprintf(ptr, "%s\n", text.getCharArray());
|
||||||
|
}
|
||||||
|
~File() {
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
void Close(){
|
void Close() {
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
fclose(ptr);
|
fclose(ptr);
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Text* readLines() {
|
||||||
|
Text* lines = new Text();
|
||||||
|
int c;
|
||||||
|
String* line = NULL;
|
||||||
|
bool lineStarted = false;
|
||||||
|
do {
|
||||||
|
c = fgetc(ptr);
|
||||||
|
if (lineStarted) {
|
||||||
|
switch (c) {
|
||||||
|
case '\r':
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
case EOF:
|
||||||
|
lines->add(line);
|
||||||
|
line = NULL;
|
||||||
|
lineStarted = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
line->addChar((char)c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch (c) {
|
||||||
|
case '\r':
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
line = new String();
|
||||||
|
lines->add(line);
|
||||||
|
line = NULL;
|
||||||
|
break;
|
||||||
|
case EOF:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
line = new String();
|
||||||
|
line->addChar((char)c);
|
||||||
|
lineStarted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (c != EOF);
|
||||||
|
return lines;
|
||||||
}
|
}
|
||||||
Text* readLines(){
|
|
||||||
Text* lines = new Text();
|
|
||||||
int c;
|
|
||||||
String * line = NULL;
|
|
||||||
bool lineStarted = false;
|
|
||||||
do {
|
|
||||||
c = fgetc(ptr);
|
|
||||||
if (lineStarted){
|
|
||||||
switch (c) {
|
|
||||||
case '\r':
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
case EOF:
|
|
||||||
lines->add(line);
|
|
||||||
line = NULL;
|
|
||||||
lineStarted = false;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
line->addChar((char)c);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
switch (c){
|
|
||||||
case '\r':
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
line = new String();
|
|
||||||
lines->add(line);
|
|
||||||
line = NULL;
|
|
||||||
break;
|
|
||||||
case EOF:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
line = new String();
|
|
||||||
line->addChar((char)c);
|
|
||||||
lineStarted = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}while (c!=EOF);
|
|
||||||
return lines;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
#pragma once
|
|
||||||
String userWorkspace;
|
String userWorkspace;
|
||||||
#pragma once
|
|
||||||
String packageWorkspace;
|
String packageWorkspace;
|
||||||
#pragma once
|
|
||||||
int maxKernels;
|
int maxKernels;
|
||||||
#pragma once
|
|
||||||
int busyKernels;
|
int busyKernels;
|
||||||
#pragma once
|
|
||||||
int freeKernels;
|
int freeKernels;
|
||||||
#pragma once
|
String dvm_drv;
|
||||||
String dvm_drv;
|
|
||||||
|
|||||||
@@ -1,18 +1,27 @@
|
|||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
#include <filesystem>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#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;
|
||||||
@@ -73,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)
|
||||||
{
|
{
|
||||||
//+
|
//+
|
||||||
@@ -84,14 +95,25 @@ int main(int argc, char ** argv)
|
|||||||
maxKernels = atoi(argv[3]);
|
maxKernels = atoi(argv[3]);
|
||||||
dvm_drv = String(argv[4]);
|
dvm_drv = String(argv[4]);
|
||||||
//--
|
//--
|
||||||
freeKernels = maxKernels;
|
freeKernels = maxKernels;
|
||||||
busyKernels= 0;
|
busyKernels= 0;
|
||||||
//--
|
//--
|
||||||
chdir(packageWorkspace.getCharArray());
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
std::filesystem::current_path(packageWorkspace.getCharArray());
|
||||||
|
#else
|
||||||
|
chdir(packageWorkspace.getCharArray());
|
||||||
|
#endif
|
||||||
|
|
||||||
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();
|
||||||
@@ -107,6 +129,6 @@ int main(int argc, char ** argv)
|
|||||||
RunSupervisor * runSupervisor = new RunSupervisor(compilationSupervisor);
|
RunSupervisor * runSupervisor = new RunSupervisor(compilationSupervisor);
|
||||||
printf("%ld\n", runSupervisor->getLength());
|
printf("%ld\n", runSupervisor->getLength());
|
||||||
runSupervisor->print();
|
runSupervisor->print();
|
||||||
runSupervisor->Do();
|
runSupervisor->DoWithSchedule(maxKernels);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "CompilationSupervisor.h"
|
#include "CompilationSupervisor.h"
|
||||||
#include "RunTask.h"
|
#include "RunTask.h"
|
||||||
#pragma once
|
|
||||||
class RunSupervisor: public Supervisor<RunTask> {
|
class RunSupervisor : public Supervisor<RunTask> {
|
||||||
public:
|
public:
|
||||||
RunSupervisor(CompilationSupervisor * compilationSupervisor){
|
RunSupervisor(CompilationSupervisor* compilationSupervisor) {
|
||||||
this->init("runTasks", 8);
|
this->init("runTasks", 8);
|
||||||
//проверить отмененные задачи.
|
//проверить отмененные задачи.
|
||||||
for (long i=0; i< this->length; ++i){
|
for (long i = 0; i < getLength(); ++i) {
|
||||||
RunTask * task = this->get(i);
|
RunTask* task = this->get(i);
|
||||||
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",
|
printf("id=%ld; parent_id = %ld; state=%s\n",
|
||||||
task->getId(),
|
task->getId(),
|
||||||
task->getParent()->getId(),
|
task->getParent()->getId(),
|
||||||
task->printState().getCharArray());
|
task->printState().getCharArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual String getStatePrefix(){
|
virtual String getStatePrefix() {
|
||||||
return String("Running");
|
return String("Running");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
virtual void Finalize(){
|
virtual void Finalize(){
|
||||||
this->state = Archivation;
|
this->state = Archivation;
|
||||||
@@ -29,4 +32,4 @@ public:
|
|||||||
printf("Archivation ended\n");
|
printf("Archivation ended\n");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,94 +1,96 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "CompilationTask.h"
|
#include "CompilationTask.h"
|
||||||
#pragma once
|
|
||||||
class RunTask : public Task {
|
class RunTask : public Task {
|
||||||
long testcompilationtask_id;
|
long testcompilationtask_id;
|
||||||
String binary_name;
|
String binary_name;
|
||||||
String matrix;
|
String matrix;
|
||||||
String environments;
|
String environments;
|
||||||
String usr_par;
|
String usr_par;
|
||||||
String args;
|
String args;
|
||||||
CompilationTask* parent;
|
CompilationTask* parent;
|
||||||
public:
|
public:
|
||||||
virtual void print(){
|
virtual void print() const {
|
||||||
printf("id=%ld; maxtime=%d; testcompilationtask_id=%ld; matrix=%s; environments=%s; usr_par=%s; args=%s kernels=%d\n",
|
printf("id=%ld; maxtime=%d; testcompilationtask_id=%ld; matrix=%s; environments=%s; usr_par=%s; args=%s kernels=%d\n",
|
||||||
id,
|
id,
|
||||||
maxtime,
|
maxtime,
|
||||||
testcompilationtask_id,
|
testcompilationtask_id,
|
||||||
matrix.getCharArray(),
|
matrix.getCharArray(),
|
||||||
environments.getCharArray(),
|
environments.getCharArray(),
|
||||||
usr_par.getCharArray(),
|
usr_par.getCharArray(),
|
||||||
args.getCharArray(),
|
args.getCharArray(),
|
||||||
kernels
|
kernels
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
int setKernels(String * kernels_s){
|
int setKernels(String* kernels_s) {
|
||||||
return kernels = atoi(kernels_s->getCharArray());
|
return kernels = atoi(kernels_s->getCharArray());
|
||||||
}
|
|
||||||
long setTestCompilationTaskId(String * id_s){
|
|
||||||
return testcompilationtask_id=strtol(id_s->getCharArray(), NULL, 10);
|
|
||||||
}
|
|
||||||
long getTestCompilationTaskId(){
|
|
||||||
return testcompilationtask_id;
|
|
||||||
}
|
|
||||||
void setMatrix(String * matrix_in){
|
|
||||||
matrix= String (matrix_in->getCharArray());
|
|
||||||
}
|
|
||||||
void setEnvironments(String * environments_in){
|
|
||||||
environments= String(environments_in->getCharArray());
|
|
||||||
}
|
|
||||||
void setUsrPar(String * usr_par_in){
|
|
||||||
usr_par= String(usr_par_in->getCharArray(),'|');
|
|
||||||
}
|
|
||||||
void setArgs(String * args_in){
|
|
||||||
args= String(args_in->getCharArray());
|
|
||||||
}
|
}
|
||||||
void setParent(CompilationTask * parent_in){
|
long setTestCompilationTaskId(String* id_s) {
|
||||||
parent = parent_in;
|
return testcompilationtask_id = strtol(id_s->getCharArray(), NULL, 10);
|
||||||
binary_name = "spf_"+ String(id)+"_"+matrix.Replace(' ','_');
|
}
|
||||||
}
|
long getTestCompilationTaskId() {
|
||||||
CompilationTask * getParent(){
|
return testcompilationtask_id;
|
||||||
return parent;
|
}
|
||||||
}
|
void setMatrix(String* matrix_in) {
|
||||||
RunTask(Text * lines, int offset):Task(lines,offset) {
|
matrix = String(matrix_in->getCharArray());
|
||||||
setTestCompilationTaskId(lines->get(offset+2));
|
}
|
||||||
setMatrix(lines->get(offset+3));
|
void setEnvironments(String* environments_in) {
|
||||||
setEnvironments(lines->get(offset+4));
|
environments = String(environments_in->getCharArray());
|
||||||
setUsrPar(lines->get(offset+5));
|
}
|
||||||
setArgs(lines->get(offset+6));
|
void setUsrPar(String* usr_par_in) {
|
||||||
setKernels(lines->get(offset+7));
|
usr_par = String(usr_par_in->getCharArray(), '|');
|
||||||
}
|
}
|
||||||
|
void setArgs(String* args_in) {
|
||||||
virtual String getLaunchScriptText(){
|
args = String(args_in->getCharArray());
|
||||||
String modules = userWorkspace+"/modules";
|
}
|
||||||
String starterCall = modules+"/starter";
|
void setParent(CompilationTask* parent_in) {
|
||||||
String launcherCall = modules+"/launcher";
|
parent = parent_in;
|
||||||
|
binary_name = "spf_" + String(id) + "_" + matrix.Replace(' ', '_');
|
||||||
|
}
|
||||||
|
CompilationTask* getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
RunTask(Text* lines, int offset) :Task(lines, offset) {
|
||||||
|
setTestCompilationTaskId(lines->get(offset + 2));
|
||||||
|
setMatrix(lines->get(offset + 3));
|
||||||
|
setEnvironments(lines->get(offset + 4));
|
||||||
|
setUsrPar(lines->get(offset + 5));
|
||||||
|
setArgs(lines->get(offset + 6));
|
||||||
|
setKernels(lines->get(offset + 7));
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual String getLaunchScriptText() {
|
||||||
|
String modules = userWorkspace + "/modules";
|
||||||
|
String starterCall = modules + "/starter";
|
||||||
|
String launcherCall = modules + "/launcher";
|
||||||
//-
|
//-
|
||||||
String dvm_start = String::DQuotes(dvm_drv) + " run ";
|
String dvm_start = String::DQuotes(dvm_drv) + " run ";
|
||||||
if (!matrix.isEmpty())
|
if (!matrix.isEmpty())
|
||||||
dvm_start = dvm_start+matrix + " ";
|
dvm_start = dvm_start + matrix + " ";
|
||||||
dvm_start = dvm_start+ String::DQuotes("./" + binary_name);
|
dvm_start = dvm_start + String::DQuotes("./" + binary_name);
|
||||||
if (!args.isEmpty())
|
if (!args.isEmpty())
|
||||||
dvm_start = dvm_start+ " " + args;
|
dvm_start = dvm_start + " " + args;
|
||||||
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) + " " +
|
||||||
dvm_start;
|
dvm_start;
|
||||||
}
|
|
||||||
virtual void prepareWorkspace(){
|
|
||||||
String binary_src = parent->getWorkspace()+"/0";
|
|
||||||
String binary_dst = workspace+"/"+binary_name;
|
|
||||||
Utils::Copy(binary_src, binary_dst);
|
|
||||||
if (!usr_par.isEmpty()){
|
|
||||||
String parPath = String(id)+"/usr.par";
|
|
||||||
File parFile = File(parPath, usr_par);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual String getStartCommand(){
|
|
||||||
String res = workspace+"/run";
|
|
||||||
if (!environments.isEmpty())
|
|
||||||
res = environments+" "+res;
|
|
||||||
printf("START %ld: %s\n", id, res.getCharArray());
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
};
|
virtual void prepareWorkspace() {
|
||||||
|
String binary_src = parent->getWorkspace() + "/0";
|
||||||
|
String binary_dst = workspace + "/" + binary_name;
|
||||||
|
Utils::Copy(binary_src, binary_dst);
|
||||||
|
if (!usr_par.isEmpty()) {
|
||||||
|
String parPath = String(id) + "/usr.par";
|
||||||
|
File parFile = File(parPath, usr_par);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
virtual String getStartCommand() {
|
||||||
|
String res = workspace + "/run";
|
||||||
|
if (!environments.isEmpty())
|
||||||
|
res = environments + " " + res;
|
||||||
|
printf("START %ld: %s\n", id, res.getCharArray());
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,220 +1,226 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#pragma once
|
|
||||||
class String {
|
class String {
|
||||||
friend String operator+(const String& a, const String& b);
|
friend String operator+(const String& a, const String& b);
|
||||||
long length;
|
long length;
|
||||||
char* body;
|
char* body;
|
||||||
public:
|
public:
|
||||||
String() {
|
String() {
|
||||||
length = 0;
|
length = 0;
|
||||||
body = new char[1];
|
body = new char[1];
|
||||||
body[0] = '\0';
|
body[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
String(const char* s) {
|
String(const char* s) {
|
||||||
length = strlen(s);
|
length = (long)strlen(s);
|
||||||
body = new char[length + 1];
|
body = new char[length + 1];
|
||||||
for (long i = 0; i < length; ++i)
|
for (long i = 0; i < length; ++i)
|
||||||
body[i] = s[i];
|
body[i] = s[i];
|
||||||
body[length]='\0';
|
body[length] = '\0';
|
||||||
}
|
}
|
||||||
String(const char* s, char ps) {
|
String(const char* s, char ps) {
|
||||||
length = strlen(s);
|
length = (long)strlen(s);
|
||||||
body = new char[length + 1];
|
body = new char[length + 1];
|
||||||
for (long i = 0; i < length; ++i){
|
for (long i = 0; i < length; ++i) {
|
||||||
body[i] = (s[i]==ps)? '\n': s[i];
|
body[i] = (s[i] == ps) ? '\n' : s[i];
|
||||||
}
|
}
|
||||||
body[length]='\0';
|
body[length] = '\0';
|
||||||
}
|
}
|
||||||
~String() {
|
~String() {
|
||||||
if (body != NULL) {
|
if (body != NULL) {
|
||||||
delete[] body;
|
delete[] body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void println() const{
|
void println() const {
|
||||||
printf("[%s]\n", body);
|
printf("[%s]\n", body);
|
||||||
}
|
}
|
||||||
void addChar(char c) {
|
void addChar(char c) {
|
||||||
char* buf = new char[length + 2];
|
char* buf = new char[length + 2];
|
||||||
for (long i = 0; i < length; ++i) {
|
for (long i = 0; i < length; ++i) {
|
||||||
buf[i] = body[i];
|
buf[i] = body[i];
|
||||||
}
|
}
|
||||||
buf[length] = c;
|
buf[length] = c;
|
||||||
|
|
||||||
length++;
|
length++;
|
||||||
//--
|
//--
|
||||||
buf[length] = '\0';
|
buf[length] = '\0';
|
||||||
delete[] body;
|
delete[] body;
|
||||||
body = buf;
|
body = buf;
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
}
|
}
|
||||||
char * getCharArray() const{
|
char* getCharArray() const {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String (int s){
|
String(int s) {
|
||||||
length = 0;
|
length = 0;
|
||||||
body = new char[1];
|
body = new char[1];
|
||||||
body[0] = '\0';
|
body[0] = '\0';
|
||||||
if (s>=0){
|
if (s >= 0) {
|
||||||
int s_ = s;
|
int s_ = s;
|
||||||
int size = 1;
|
int size = 1;
|
||||||
while (s_>=10){
|
while (s_ >= 10) {
|
||||||
s_ = s_/10;
|
s_ = s_ / 10;
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
length = size;
|
length = size;
|
||||||
body = new char [size+1];
|
body = new char[size + 1];
|
||||||
sprintf(body, "%d", s);
|
sprintf(body, "%d", s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String (long s){
|
|
||||||
length = 0;
|
String(long s) : String((long long)s) { }
|
||||||
body = new char[1];
|
|
||||||
body[0] = '\0';
|
String(long long s) {
|
||||||
if (s>=0){
|
length = 0;
|
||||||
long s_ = s;
|
body = new char[1];
|
||||||
long size = 1;
|
body[0] = '\0';
|
||||||
while (s_>=10){
|
if (s >= 0) {
|
||||||
s_ = s_/10;
|
long long s_ = s;
|
||||||
size++;
|
long size = 1;
|
||||||
}
|
while (s_ >= 10) {
|
||||||
length = size;
|
s_ = s_ / 10;
|
||||||
body = new char [size+1];
|
size++;
|
||||||
sprintf(body, "%ld", s);
|
}
|
||||||
}
|
length = size;
|
||||||
}
|
body = new char[size + 1];
|
||||||
|
sprintf(body, "%lld", s);
|
||||||
const String& operator=(const String& s){
|
}
|
||||||
if (body != NULL)
|
}
|
||||||
delete[] body;
|
|
||||||
length = s.length;
|
const String& operator=(const String& s) {
|
||||||
body = new char[length+1];
|
if (body != NULL)
|
||||||
for (long i=0; i<length; ++i)
|
delete[] body;
|
||||||
body[i]=s.body[i];
|
length = s.length;
|
||||||
body[length]='\0';
|
body = new char[length + 1];
|
||||||
return *this;
|
for (long i = 0; i < length; ++i)
|
||||||
}
|
body[i] = s.body[i];
|
||||||
|
body[length] = '\0';
|
||||||
static String DQuotes(const String& s){
|
return *this;
|
||||||
String res;
|
}
|
||||||
res.length = s.length+2;
|
|
||||||
res.body=new char[res.length+1];
|
static String DQuotes(const String& s) {
|
||||||
res.body[0] = '"';
|
|
||||||
res.body[res.length-1] = '"';
|
|
||||||
res.body[res.length] = '\0';
|
|
||||||
for (long i=0; i< s.length; ++i)
|
|
||||||
res.body[i+1]=s.body[i];
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
String Replace(char f, char t){
|
|
||||||
String res;
|
|
||||||
res.length = length;
|
|
||||||
res.body = new char[length];
|
|
||||||
res.body[length]='\0';
|
|
||||||
for (long i = 0; i < length; ++i)
|
|
||||||
res.body[i]= (body[i]==f)? t: body[i];
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
String Remove(char f){
|
|
||||||
String res;
|
String res;
|
||||||
for (long i=0; i<length; ++i){
|
res.length = s.length + 2;
|
||||||
if (body[i]!=f)
|
res.body = new char[res.length + 1];
|
||||||
|
res.body[0] = '"';
|
||||||
|
res.body[res.length - 1] = '"';
|
||||||
|
res.body[res.length] = '\0';
|
||||||
|
for (long i = 0; i < s.length; ++i)
|
||||||
|
res.body[i + 1] = s.body[i];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
String Replace(char f, char t) {
|
||||||
|
String res;
|
||||||
|
res.length = length;
|
||||||
|
res.body = new char[length];
|
||||||
|
res.body[length] = '\0';
|
||||||
|
for (long i = 0; i < length; ++i)
|
||||||
|
res.body[i] = (body[i] == f) ? t : body[i];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
String Remove(char f) {
|
||||||
|
String res;
|
||||||
|
for (long i = 0; i < length; ++i) {
|
||||||
|
if (body[i] != f)
|
||||||
res.addChar(body[i]);
|
res.addChar(body[i]);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
bool isEmpty() const{
|
bool isEmpty() const {
|
||||||
return length==0;
|
return length == 0;
|
||||||
}
|
}
|
||||||
bool contains(const String& s) const{
|
bool contains(const String& s) const {
|
||||||
bool res = false;
|
bool res = false;
|
||||||
bool search_on=false;
|
bool search_on = false;
|
||||||
if (s.isEmpty()) return true;
|
if (s.isEmpty()) return true;
|
||||||
if (s.length>length) return false;
|
if (s.length > length) return false;
|
||||||
long k=0;
|
long k = 0;
|
||||||
long start=-1;
|
long start = -1;
|
||||||
for (long i=0; i<length; ++i){
|
for (long i = 0; i < length; ++i) {
|
||||||
if (search_on){
|
if (search_on) {
|
||||||
if (k<s.length){
|
if (k < s.length) {
|
||||||
if (body[i]==s.body[k]){
|
if (body[i] == s.body[k]) {
|
||||||
k++;
|
k++;
|
||||||
}else {
|
}
|
||||||
|
else {
|
||||||
//обрыв поиска.
|
//обрыв поиска.
|
||||||
search_on =false;
|
search_on = false;
|
||||||
k=0;
|
k = 0;
|
||||||
start=-1;
|
start = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//printf("starts with %ld", start);
|
//printf("starts with %ld", start);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}else {
|
}
|
||||||
if (body[i]== s.body[0]){
|
else {
|
||||||
k=1;
|
if (body[i] == s.body[0]) {
|
||||||
start=i;
|
k = 1;
|
||||||
search_on=true;
|
start = i;
|
||||||
|
search_on = true;
|
||||||
//printf("search started %d\n", start);
|
//printf("search started %d\n", start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (search_on) {
|
if (search_on) {
|
||||||
//printf("starts with %ld\n", start);
|
//printf("starts with %ld\n", start);
|
||||||
res=true;
|
res = true;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
String toUpper(){
|
String toUpper() {
|
||||||
String res = String(this->getCharArray());
|
String res = String(this->getCharArray());
|
||||||
for (long i=0; i<length; ++i)
|
for (long i = 0; i < length; ++i)
|
||||||
res.body[i]= toupper(body[i]);
|
res.body[i] = toupper(body[i]);
|
||||||
res.println();
|
res.println();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
long getLength(){
|
long getLength() {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
bool operator==(const String&s) const {
|
bool operator==(const String& s) const {
|
||||||
if (length!=s.length) return false;
|
if (length != s.length) return false;
|
||||||
for (long i=0; i<length; ++i){
|
for (long i = 0; i < length; ++i) {
|
||||||
if (body[i]!=s.body[i]) return false;
|
if (body[i] != s.body[i]) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/* регистр.
|
/* регистр.
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
FILE * f;
|
FILE * f;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
if ( ! ( f = fopen("file.txt", "r") ) )
|
if ( ! ( f = fopen("file.txt", "r") ) )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while ( ( c = fgetc(f) ) != EOF )
|
while ( ( c = fgetc(f) ) != EOF )
|
||||||
putchar( isupper(c) ? tolower(c) : toupper(c) );
|
putchar( isupper(c) ? tolower(c) : toupper(c) );
|
||||||
|
|
||||||
return ( fclose(f) );
|
return ( fclose(f) );
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
};
|
||||||
};
|
|
||||||
|
|
||||||
String operator+(const String& a, const String& b){
|
String operator+(const String& a, const String& b) {
|
||||||
String res = String();
|
String res = String();
|
||||||
res.length =a.length+b.length;
|
res.length = a.length + b.length;
|
||||||
res.body = new char[res.length+1];
|
res.body = new char[res.length + 1];
|
||||||
for (long i=0; i<a.length; ++i)
|
for (long i = 0; i < a.length; ++i)
|
||||||
res.body[i]=a.body[i];
|
res.body[i] = a.body[i];
|
||||||
for (long i=0; i<b.length; ++i)
|
for (long i = 0; i < b.length; ++i)
|
||||||
res.body[i+a.length]=b.body[i];
|
res.body[i + a.length] = b.body[i];
|
||||||
res.body[res.length]='\0';
|
res.body[res.length] = '\0';
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -1,130 +1,246 @@
|
|||||||
#include "File.h"
|
#pragma once
|
||||||
#include "Task.h"
|
|
||||||
#include <unistd.h>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
#include "File.h"
|
||||||
|
#include "Task.h"
|
||||||
|
#include "Array.h"
|
||||||
|
|
||||||
#pragma once
|
|
||||||
enum SupervisorState {
|
enum SupervisorState {
|
||||||
WorkspacesCreation, //0
|
WorkspacesCreation, //0
|
||||||
Preparation, //1
|
Preparation, //1
|
||||||
Execution, //2
|
Execution, //2
|
||||||
Archivation, //3
|
Archivation, //3
|
||||||
End //4
|
End //4
|
||||||
};
|
};
|
||||||
#pragma once
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class Supervisor : public Array <T> {
|
class Supervisor : public Array <T> {
|
||||||
protected:
|
protected:
|
||||||
SupervisorState state;
|
SupervisorState state;
|
||||||
public:
|
public:
|
||||||
virtual String getStatePrefix(){
|
virtual String getStatePrefix() {
|
||||||
return String("");
|
return String("");
|
||||||
}
|
}
|
||||||
String printState(){
|
String printState() {
|
||||||
switch(state){
|
switch (state) {
|
||||||
case WorkspacesCreation:
|
case WorkspacesCreation:
|
||||||
return String("WorkspacesCreation");
|
return String("WorkspacesCreation");
|
||||||
case Preparation:
|
case Preparation:
|
||||||
return String("Preparation");
|
return String("Preparation");
|
||||||
case Execution:
|
case Execution:
|
||||||
return String("Execution");
|
return String("Execution");
|
||||||
case Archivation:
|
case Archivation:
|
||||||
return String("Archivation");
|
return String("Archivation");
|
||||||
case End:
|
case End:
|
||||||
return String("End");
|
return String("End");
|
||||||
default:
|
default:
|
||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//-
|
//-
|
||||||
void print(){
|
void print() {
|
||||||
for (long i=0; i< this->length; ++i)
|
for (auto& elem : this->getElements())
|
||||||
this->elements[i]->print();
|
elem->print();
|
||||||
}
|
}
|
||||||
void init(const char * fileName, int recordSize){
|
|
||||||
state = WorkspacesCreation;
|
void init(const char* fileName, int recordSize) {
|
||||||
File * packedTasks = new File(fileName);
|
state = WorkspacesCreation;
|
||||||
Text * lines = packedTasks->readLines();
|
File* packedTasks = new File(fileName);
|
||||||
this->length = lines->getLength()/recordSize;
|
Text* lines = packedTasks->readLines();
|
||||||
this->elements = new T* [this->length];
|
|
||||||
int offset=0;
|
const long length = lines->getLength() / recordSize;
|
||||||
for (int i=0; i< this->length; ++i){
|
int offset = 0;
|
||||||
this->elements[i]= new T(lines, offset);
|
for (int i = 0; i < length; ++i) {
|
||||||
offset+=recordSize;
|
this->add(new T(lines, offset));
|
||||||
}
|
offset += recordSize;
|
||||||
delete packedTasks;
|
}
|
||||||
delete lines;
|
delete packedTasks;
|
||||||
}
|
delete lines;
|
||||||
void Do(){
|
}
|
||||||
saveState();
|
|
||||||
long activeCount=0;
|
void changeState() {
|
||||||
//todo обязательно убрать отладочную печать.
|
switch (this->state) {
|
||||||
printf("tasks count = %ld\n", this->length);
|
case WorkspacesCreation:
|
||||||
while (this->state!= End){
|
this->state = Preparation;
|
||||||
// printf("state=%d\n", this->state);
|
saveState();
|
||||||
// printf("max=%d; busy=%d; free=%d\n", maxKernels, busyKernels, freeKernels);
|
break;
|
||||||
activeCount=0;
|
case Preparation:
|
||||||
for (long i=0; i<this->length; ++i){
|
this->state = Execution;
|
||||||
T * task = this->elements[i];
|
saveState();
|
||||||
switch (this->state){
|
break;
|
||||||
case WorkspacesCreation:
|
case Execution:
|
||||||
if (task->getState()==Waiting){
|
Finalize();
|
||||||
activeCount++;
|
this->state = End;
|
||||||
task->createWorkspace();
|
saveState();
|
||||||
task->setState(WorkspaceCreated);
|
break;
|
||||||
}
|
default:
|
||||||
break;
|
this->state = End;
|
||||||
case Preparation:
|
break;
|
||||||
if (task->getState()==WorkspaceCreated){
|
}
|
||||||
activeCount++;
|
}
|
||||||
task->prepareWorkspace();
|
|
||||||
task->createLaunchScript();
|
void Do() {
|
||||||
task->setState(WorkspaceReady);
|
saveState();
|
||||||
}
|
long activeCount = 0;
|
||||||
break;
|
//todo обязательно убрать отладочную печать.
|
||||||
case Execution:
|
printf("tasks count = %ld\n", this->getLength());
|
||||||
if (task->getState()==WorkspaceReady){
|
while (this->state != End) {
|
||||||
activeCount++;
|
// printf("state=%d\n", this->state);
|
||||||
task->start_time=Utils::getAbsoluteTime();
|
// printf("max=%d; busy=%d; free=%d\n", maxKernels, busyKernels, freeKernels);
|
||||||
task->Start();
|
activeCount = 0;
|
||||||
}else if (task->getState()==Running){
|
for (long i = 0; i < this->getLength(); ++i) {
|
||||||
activeCount++;
|
T* task = this->get(i);
|
||||||
task->Check();
|
switch (this->state) {
|
||||||
}
|
case WorkspacesCreation:
|
||||||
break;
|
if (task->getState() == Waiting) {
|
||||||
default:
|
activeCount++;
|
||||||
// printf("id = %ld; state = %d\n", task->getId(), task->getState());
|
task->createWorkspace();
|
||||||
break;
|
task->setState(WorkspaceCreated);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
// printf("active count = %d\n", activeCount);
|
case Preparation:
|
||||||
if (activeCount==0){
|
if (task->getState() == WorkspaceCreated) {
|
||||||
switch (this->state){
|
activeCount++;
|
||||||
case WorkspacesCreation:
|
task->prepareWorkspace();
|
||||||
this->state = Preparation;
|
task->createLaunchScript();
|
||||||
saveState();
|
task->setState(WorkspaceReady);
|
||||||
break;
|
}
|
||||||
case Preparation:
|
break;
|
||||||
this->state = Execution;
|
case Execution:
|
||||||
saveState();
|
if (task->getState() == WorkspaceReady) {
|
||||||
break;
|
activeCount++;
|
||||||
case Execution:
|
task->Start();
|
||||||
Finalize();
|
}
|
||||||
this->state = End;
|
else if (task->getState() == Running) {
|
||||||
saveState();
|
activeCount++;
|
||||||
break;
|
task->Check();
|
||||||
default:
|
}
|
||||||
this->state = End;
|
break;
|
||||||
break;
|
default:
|
||||||
}
|
// printf("id = %ld; state = %d\n", task->getId(), task->getState());
|
||||||
}
|
break;
|
||||||
Utils::Sleep(2);
|
}
|
||||||
}
|
}
|
||||||
}
|
// printf("active count = %d\n", activeCount);
|
||||||
virtual void Finalize(){}
|
if (activeCount == 0)
|
||||||
void saveState(){
|
changeState();
|
||||||
Utils::Sleep(1); //чтобы не было одинаковых по дате файлов.
|
Utils::Sleep(2);
|
||||||
String stateFile = packageWorkspace+"/state/"+getStatePrefix()+printState();
|
}
|
||||||
//printf("stateFile=<%s>\n", stateFile.getCharArray());
|
}
|
||||||
File(stateFile, Utils::getDate());
|
|
||||||
}
|
|
||||||
|
void DoWithSchedule(int maxKernels) {
|
||||||
|
saveState();
|
||||||
|
|
||||||
|
// подготовка тестов
|
||||||
|
while (this->state != Execution) {
|
||||||
|
for (auto& task : this->getElements()) {
|
||||||
|
switch (this->state) {
|
||||||
|
case WorkspacesCreation:
|
||||||
|
if (task->getState() == Waiting) {
|
||||||
|
task->createWorkspace();
|
||||||
|
task->setState(WorkspaceCreated);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Preparation:
|
||||||
|
if (task->getState() == WorkspaceCreated) {
|
||||||
|
task->prepareWorkspace();
|
||||||
|
task->createLaunchScript();
|
||||||
|
task->setState(WorkspaceReady);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//printf("id = %ld; state = %d\n", task->getId(), task->getState());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
changeState();
|
||||||
|
}
|
||||||
|
|
||||||
|
map<int, queue<T*>, std::greater<int>> sortedByKernelNeeds;
|
||||||
|
|
||||||
|
long activeTasks = 0;
|
||||||
|
long done = 0;
|
||||||
|
for (auto& task : this->getElements()) {
|
||||||
|
if (task->getState() == WorkspaceReady) {
|
||||||
|
activeTasks++;
|
||||||
|
sortedByKernelNeeds[task->getKernels()].push(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("total tasks count = %ld, active task count %ld, maxkernels %d\n", this->getLength(), activeTasks, maxKernels);
|
||||||
|
|
||||||
|
int busyKernels = 0;
|
||||||
|
set<T*> activeTaskSet;
|
||||||
|
bool ignoreCheck = true;
|
||||||
|
|
||||||
|
while (activeTasks) {
|
||||||
|
long oldActiveTasks = activeTasks;
|
||||||
|
vector<int> emptyKeys;
|
||||||
|
|
||||||
|
//ставим задачи от больших к меньшему по ядрам
|
||||||
|
for (auto& elem : sortedByKernelNeeds) {
|
||||||
|
int freeKernels = maxKernels - busyKernels;
|
||||||
|
int kernelsNeeded = elem.first;
|
||||||
|
|
||||||
|
while (kernelsNeeded <= freeKernels && elem.second.size()) {
|
||||||
|
T* task = elem.second.front();
|
||||||
|
elem.second.pop();
|
||||||
|
|
||||||
|
activeTaskSet.insert(task);
|
||||||
|
task->Start(ignoreCheck);
|
||||||
|
printf("start task with %d kernels and id %ld\n", task->getKernels(), task->getId());
|
||||||
|
|
||||||
|
busyKernels += task->getKernels();
|
||||||
|
freeKernels = maxKernels - busyKernels;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elem.second.size() == 0)
|
||||||
|
emptyKeys.push_back(kernelsNeeded);
|
||||||
|
|
||||||
|
//если ядер не осталось, то нет смысла дальше смотреть
|
||||||
|
if (freeKernels == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// очищаем от пустых ключей
|
||||||
|
for (auto& empty : emptyKeys)
|
||||||
|
sortedByKernelNeeds.erase(empty);
|
||||||
|
|
||||||
|
// проверяем нет ли завершившихся задач
|
||||||
|
for (auto it = activeTaskSet.begin(); it != activeTaskSet.end(); )
|
||||||
|
{
|
||||||
|
T* task = *(it);
|
||||||
|
|
||||||
|
if (task->Check()) {
|
||||||
|
it++;
|
||||||
|
activeTaskSet.erase(task);
|
||||||
|
activeTasks--;
|
||||||
|
done++;
|
||||||
|
busyKernels -= task->getKernels();
|
||||||
|
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldActiveTasks != activeTasks)
|
||||||
|
printf("done %ld / %ld\n", done, this->getLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
changeState();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Finalize() {}
|
||||||
|
|
||||||
|
void saveState() {
|
||||||
|
Utils::Sleep(1); //чтобы не было одинаковых по дате файлов.
|
||||||
|
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
|
||||||
|
//printf("stateFile=<%s>\n", stateFile.getCharArray());
|
||||||
|
File(stateFile, Utils::getDate());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#pragma once
|
enum TaskState {
|
||||||
enum TaskState {
|
|
||||||
Inactive, //0
|
Inactive, //0
|
||||||
Waiting, //1
|
Waiting, //1
|
||||||
WorkspaceCreated, //2
|
WorkspaceCreated, //2
|
||||||
@@ -24,148 +27,165 @@ enum TaskState {
|
|||||||
NoSuchTask, //17
|
NoSuchTask, //17
|
||||||
FailedToQueue, //18
|
FailedToQueue, //18
|
||||||
AbortingByUser //19
|
AbortingByUser //19
|
||||||
};
|
};
|
||||||
#pragma once
|
|
||||||
enum TestType{
|
enum TestType {
|
||||||
Default, //0
|
Default, //0
|
||||||
Correctness, //1
|
Correctness, //1
|
||||||
Performance, //2
|
Performance, //2
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma once
|
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;
|
||||||
|
std::chrono::system_clock::time_point start_time;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
long start_time;
|
String printState() {
|
||||||
String printState(){
|
switch (state) {
|
||||||
switch(state){
|
case Inactive:
|
||||||
case Inactive:
|
return String("Inactive");
|
||||||
return String("Inactive");
|
case Waiting:
|
||||||
case Waiting:
|
return String("Waiting");
|
||||||
return String("Waiting");
|
case WorkspaceCreated:
|
||||||
case WorkspaceCreated:
|
return String("WorkspaceCreated");
|
||||||
return String("WorkspaceCreated");
|
case WorkspaceReady:
|
||||||
case WorkspaceReady:
|
return String("WorkspaceReady");
|
||||||
return String("WorkspaceReady");
|
case Running:
|
||||||
case Running:
|
return String("Running");
|
||||||
return String("Running");
|
case Canceled:
|
||||||
case Canceled:
|
return String("Canceled");
|
||||||
return String("Canceled");
|
case Finished:
|
||||||
case Finished:
|
return String("Finished");
|
||||||
return String("Finished");
|
case FinishedAbortedByTimeout:
|
||||||
case FinishedAbortedByTimeout:
|
return String("FinishedAbortedByTimeout");
|
||||||
return String("FinishedAbortedByTimeout");
|
case FinishedAbortedByUser:
|
||||||
case FinishedAbortedByUser:
|
return String("FinishedAbortedByUser");
|
||||||
return String("FinishedAbortedByUser");
|
case Done:
|
||||||
case Done:
|
return String("Done");
|
||||||
return String("Done");
|
case DoneWithErrors:
|
||||||
case DoneWithErrors:
|
return String("DoneWithErrors");
|
||||||
return String("DoneWithErrors");
|
case AbortedByTimeout:
|
||||||
case AbortedByTimeout:
|
return String("AbortedByTimeout");
|
||||||
return String("AbortedByTimeout");
|
case AbortedByUser:
|
||||||
case AbortedByUser:
|
return String("AbortedByUser");
|
||||||
return String("AbortedByUser");
|
case Crushed:
|
||||||
case Crushed:
|
return String("Crushed");
|
||||||
return String("Crushed");
|
case WrongTestFormat:
|
||||||
case WrongTestFormat:
|
return String("WrongTestFormat");
|
||||||
return String("WrongTestFormat");
|
case InternalError:
|
||||||
case InternalError:
|
return String("InternalError");
|
||||||
return String("InternalError");
|
case Queued:
|
||||||
case Queued:
|
return String("Queued");
|
||||||
return String("Queued");
|
case NoSuchTask:
|
||||||
case NoSuchTask:
|
return String("NoSuchTask");
|
||||||
return String("NoSuchTask");
|
case FailedToQueue:
|
||||||
case FailedToQueue:
|
return String("FailedToQueue");
|
||||||
return String("FailedToQueue");
|
case AbortingByUser:
|
||||||
case AbortingByUser:
|
return String("AbortingByUser");
|
||||||
return String("AbortingByUser");
|
default:
|
||||||
default:
|
return "?";
|
||||||
return "?";
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
//-------------->>
|
|
||||||
long getId(){return id;}
|
|
||||||
long setId(String * id_s){
|
|
||||||
return id=strtol(id_s->getCharArray(), NULL, 10);
|
|
||||||
}
|
|
||||||
int getMaxtime(){return maxtime;}
|
|
||||||
int setMaxtime(String * maxtime_s){
|
|
||||||
return maxtime=atoi(maxtime_s->getCharArray());
|
|
||||||
}
|
|
||||||
const String& getWorkspace(){return workspace;}
|
|
||||||
TaskState getState(){return state;}
|
|
||||||
TaskState setState(TaskState state_in){return state=state_in;}
|
|
||||||
Task(Text * lines, int offset){
|
|
||||||
setId(lines->get(offset));
|
|
||||||
setMaxtime(lines->get(offset+1));
|
|
||||||
workspace = packageWorkspace+"/"+String(id);
|
|
||||||
}
|
|
||||||
virtual void print()=0;
|
|
||||||
//-
|
|
||||||
virtual void prepareWorkspace(){}
|
|
||||||
virtual String getLaunchScriptText()=0;
|
|
||||||
virtual String getStartCommand(){
|
|
||||||
return workspace+"/run";
|
|
||||||
}
|
|
||||||
|
|
||||||
void createWorkspace(){
|
|
||||||
Utils::Mkdir(workspace);
|
|
||||||
}
|
|
||||||
void createLaunchScript(){
|
|
||||||
String launchScriptPath = workspace+"/run";
|
|
||||||
String launchScriptText =
|
|
||||||
String("cd ")+String::DQuotes(workspace)+"\n"+
|
|
||||||
getLaunchScriptText();
|
|
||||||
File launchScriptFile = File(launchScriptPath, launchScriptText);
|
|
||||||
Utils::Chmod(launchScriptPath);
|
|
||||||
}
|
|
||||||
virtual void Start(){
|
|
||||||
|
|
||||||
if (kernels<=freeKernels){
|
|
||||||
system(getStartCommand().getCharArray());
|
|
||||||
state=Running;
|
|
||||||
//-
|
|
||||||
busyKernels= Utils::min(busyKernels+kernels, maxKernels);
|
|
||||||
freeKernels= Utils::max(0, maxKernels-busyKernels);
|
|
||||||
//-
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual void analyseResults(){
|
|
||||||
state=Finished;
|
|
||||||
}
|
}
|
||||||
virtual void Check(){
|
|
||||||
if (Utils::Exists(workspace+"/DONE")){
|
//-------------->>
|
||||||
|
void setStart() { start_time = std::chrono::system_clock::now(); }
|
||||||
|
|
||||||
|
long getId() { return id; }
|
||||||
|
long setId(String* id_s) {
|
||||||
|
return id = strtol(id_s->getCharArray(), NULL, 10);
|
||||||
|
}
|
||||||
|
int getMaxtime() { return maxtime; }
|
||||||
|
int setMaxtime(String* maxtime_s) {
|
||||||
|
return maxtime = atoi(maxtime_s->getCharArray());
|
||||||
|
}
|
||||||
|
const String& getWorkspace() { return workspace; }
|
||||||
|
TaskState getState() { return state; }
|
||||||
|
TaskState setState(TaskState state_in) { return state = state_in; }
|
||||||
|
Task(Text* lines, int offset) {
|
||||||
|
setId(lines->get(offset));
|
||||||
|
setMaxtime(lines->get(offset + 1));
|
||||||
|
workspace = packageWorkspace + "/" + String(id);
|
||||||
|
}
|
||||||
|
virtual void print() const = 0;
|
||||||
|
//-
|
||||||
|
virtual void prepareWorkspace() {}
|
||||||
|
virtual String getLaunchScriptText() = 0;
|
||||||
|
virtual String getStartCommand() {
|
||||||
|
return workspace + "/run";
|
||||||
|
}
|
||||||
|
|
||||||
|
void createWorkspace() {
|
||||||
|
Utils::Mkdir(workspace);
|
||||||
|
}
|
||||||
|
void createLaunchScript() {
|
||||||
|
String launchScriptPath = workspace + "/run";
|
||||||
|
String launchScriptText =
|
||||||
|
String("cd ") + String::DQuotes(workspace) + "\n" +
|
||||||
|
getLaunchScriptText();
|
||||||
|
File launchScriptFile = File(launchScriptPath, launchScriptText);
|
||||||
|
Utils::Chmod(launchScriptPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getKernels() const { return kernels; }
|
||||||
|
|
||||||
|
void Start(bool dontCheck = false) {
|
||||||
|
if (kernels <= freeKernels || dontCheck) {
|
||||||
|
setStart();
|
||||||
|
system(getStartCommand().getCharArray());
|
||||||
|
state = Running;
|
||||||
|
//-
|
||||||
|
busyKernels = Utils::min(busyKernels + kernels, maxKernels);
|
||||||
|
freeKernels = Utils::max(0, maxKernels - busyKernels);
|
||||||
|
//-
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//return 'true' if done, 'false' - if running
|
||||||
|
virtual bool Check() {
|
||||||
|
if (Utils::Exists(workspace + "/DONE"))
|
||||||
analyseResults();
|
analyseResults();
|
||||||
}else {
|
else {
|
||||||
if (Utils::Exists(workspace+"/TIMEOUT")){
|
if (Utils::Exists(workspace + "/TIMEOUT")) {
|
||||||
state=AbortedByTimeout;
|
state = AbortedByTimeout;
|
||||||
//todo определить по интервалу времени на всякий случай.
|
//todo определить по интервалу времени на всякий случай.
|
||||||
}else if (Utils::Exists(workspace+"/INTERRUPT")){
|
|
||||||
state=AbortedByUser;
|
|
||||||
} else {
|
|
||||||
long now = Utils::getAbsoluteTime();
|
|
||||||
long delta = now-start_time;
|
|
||||||
if (maxtime<delta){
|
|
||||||
state=AbortedByTimeout;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
else if (Utils::Exists(workspace + "/INTERRUPT")) {
|
||||||
if (state!=Running){
|
state = AbortedByUser;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto end_time = std::chrono::system_clock::now();
|
||||||
|
std::chrono::duration<double> diff_time = end_time - start_time;
|
||||||
|
|
||||||
|
if (maxtime * 1.1 < diff_time.count()) {
|
||||||
|
printf("SET STATUS ABORTED by timer to %ld with time %f sec / %f sec", id, diff_time.count(), maxtime * 1.1);
|
||||||
|
state = AbortedByTimeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
//-
|
//-
|
||||||
saveState(); //не нужно. только для отладки. анализ будет делаться архивом.
|
saveState();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
virtual void saveState(){
|
return (state != Running);
|
||||||
String stateFile = workspace+"/TaskState";
|
}
|
||||||
File(stateFile, printState());
|
|
||||||
}
|
virtual void analyseResults() {
|
||||||
};
|
state = Finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void saveState() {
|
||||||
|
String stateFile = workspace + "/TaskState";
|
||||||
|
File tmp(stateFile, printState());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,25 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
#include "Array.h"
|
#include "Array.h"
|
||||||
#pragma once
|
|
||||||
class Text: public Array<String> {
|
class Text : public Array<String> {
|
||||||
public:
|
public:
|
||||||
void Print(){
|
void Print() const {
|
||||||
printf("text length=%ld\n", length);
|
printf("text length=%ld\n", this->getLength());
|
||||||
|
|
||||||
for (long i=0; i<length; ++i){
|
auto elems = this->getElements();
|
||||||
printf("i=%ld; [%s]\n",i, elements[i]->getCharArray());
|
for (long i = 0; i < elems.size(); ++i) {
|
||||||
// elements[i]->println();
|
printf("i=%ld; [%s]\n", i, elems[i]->getCharArray());
|
||||||
|
// elements[i]->println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasMatch(const String& s) const {
|
||||||
|
|
||||||
|
for (auto& elem : this->getElements()) {
|
||||||
|
if (s.contains(*elem)) {
|
||||||
|
//printf("match: [%s]\n", elements[i]->getCharArray());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
bool hasMatch(const String& s){
|
|
||||||
|
|
||||||
for (long i=0; i<length; ++i){
|
|
||||||
if (s.contains(*elements[i])){
|
|
||||||
//printf("match: [%s]\n", elements[i]->getCharArray());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//printf("no matches for [%s]\n", s.getCharArray());
|
//printf("no matches for [%s]\n", s.getCharArray());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,49 +1,65 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
#include <filesystem>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
#pragma once
|
|
||||||
class Utils {
|
class Utils {
|
||||||
public:
|
public:
|
||||||
static int max(int a, int b){
|
static int max(int a, int b) {
|
||||||
return (a > b)? a:b;
|
return (a > b) ? a : b;
|
||||||
}
|
|
||||||
static int min(int a, int b){
|
|
||||||
return (a > b)? b:a;
|
|
||||||
}
|
}
|
||||||
static void Mkdir(const String& path){
|
static int min(int a, int b) {
|
||||||
|
return (a > b) ? b : a;
|
||||||
|
}
|
||||||
|
static void Mkdir(const String& path) {
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
std::filesystem::create_directory(path.getCharArray());
|
||||||
|
#else
|
||||||
mkdir(path.getCharArray(), 0777);
|
mkdir(path.getCharArray(), 0777);
|
||||||
}
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
//https://stackoverflow.com/questions/4568681/using-chmod-in-a-c-program
|
//https://stackoverflow.com/questions/4568681/using-chmod-in-a-c-program
|
||||||
static void Chmod(const String& path){
|
static void Chmod(const String& path) {
|
||||||
String command = "chmod 777 "+String::DQuotes(path);
|
String command = "chmod 777 " + String::DQuotes(path);
|
||||||
system(command.getCharArray());
|
system(command.getCharArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
//https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c
|
//https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c
|
||||||
static bool Exists(const String& path){
|
static bool Exists(const String& path) {
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
return (stat (path.getCharArray(), &buffer) == 0);
|
return (stat(path.getCharArray(), &buffer) == 0);
|
||||||
}
|
}
|
||||||
static void Sleep(int s){
|
|
||||||
usleep(s* 1000000);
|
//in seconds
|
||||||
}
|
static void Sleep(int s) {
|
||||||
static void Copy(const String& src, const String& dst){
|
std::chrono::seconds timespan(s);
|
||||||
String command = "cp "+String::DQuotes(src)+" "+String::DQuotes(dst);
|
std::this_thread::sleep_for(timespan);
|
||||||
system(command.getCharArray());
|
|
||||||
}
|
}
|
||||||
static long getAbsoluteTime(){
|
static void Copy(const String& src, const String& dst) {
|
||||||
return time (NULL);
|
String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst);
|
||||||
}
|
|
||||||
static String getDate(){
|
|
||||||
long int ttime;
|
|
||||||
ttime = time (NULL);
|
|
||||||
String res(ctime (&ttime));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
static void ZipFolder(const String& src, const String& dst){
|
|
||||||
String command = "zip -r "+String::DQuotes(dst)+" "+String::DQuotes(src);
|
|
||||||
system(command.getCharArray());
|
system(command.getCharArray());
|
||||||
}
|
}
|
||||||
};
|
static time_t getAbsoluteTime() {
|
||||||
|
return time(NULL);
|
||||||
|
}
|
||||||
|
static String getDate() {
|
||||||
|
auto ttime = time(NULL);
|
||||||
|
String res(ctime(&ttime));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
static void ZipFolder(const String& src, const String& dst) {
|
||||||
|
String command = "zip -r " + String::DQuotes(dst) + " " + String::DQuotes(src);
|
||||||
|
system(command.getCharArray());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user