add memory usage info for console runner
This commit is contained in:
parent
2520ddf8f5
commit
e37759b977
|
@ -46,8 +46,8 @@ struct OJProblemCase {
|
|||
QString expectedOutputFileName;
|
||||
ProblemCaseTestState testState; // no persistence
|
||||
QString output; // no persistence
|
||||
size_t runningTime; // no persistence
|
||||
size_t runningMemory; // no persistence;
|
||||
qulonglong runningTime; // no persistence
|
||||
qulonglong runningMemory; // no persistence;
|
||||
int firstDiffLine; // no persistence
|
||||
int outputLineCounts; // no persistence
|
||||
int expectedLineCounts;
|
||||
|
|
|
@ -902,8 +902,8 @@ public:
|
|||
int mCaseEditorFontSize;
|
||||
bool mCaseEditorFontOnlyMonospaced;
|
||||
bool mEnableCaseLimit;
|
||||
size_t mCaseTimeout; //ms
|
||||
size_t mCaseMemoryLimit; //kb
|
||||
qulonglong mCaseTimeout; //ms
|
||||
qulonglong mCaseMemoryLimit; //kb
|
||||
|
||||
protected:
|
||||
void doSave() override;
|
||||
|
|
|
@ -497,6 +497,7 @@ QVariant OJProblemModel::data(const QModelIndex &index, int role) const
|
|||
return "";
|
||||
}
|
||||
break;
|
||||
#ifdef Q_OS_WIN
|
||||
case 2:
|
||||
if (role == Qt::DisplayRole) {
|
||||
POJProblemCase problemCase = mProblem->cases[index.row()];
|
||||
|
@ -507,6 +508,7 @@ QVariant OJProblemModel::data(const QModelIndex &index, int role) const
|
|||
return "";
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
@ -543,7 +545,11 @@ Qt::ItemFlags OJProblemModel::flags(const QModelIndex &idx) const
|
|||
|
||||
int OJProblemModel::columnCount(const QModelIndex &/*parent*/) const
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
return 3;
|
||||
#else
|
||||
return 2;
|
||||
#endif
|
||||
}
|
||||
|
||||
QVariant OJProblemModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
|
@ -554,8 +560,10 @@ QVariant OJProblemModel::headerData(int section, Qt::Orientation orientation, in
|
|||
return tr("Name");
|
||||
case 1:
|
||||
return tr("Time(ms)");
|
||||
#ifdef Q_OS_WIN
|
||||
case 2:
|
||||
return tr("Memory(kb)");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
|
|
|
@ -28,6 +28,8 @@ using std::vector;
|
|||
#include <sys/stat.h> /* For mode constants */
|
||||
#include <fcntl.h> /* For O_* constants */
|
||||
#include <chrono>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/wait.h>
|
||||
#define MAX_COMMAND_LENGTH 32768
|
||||
#define MAX_ERROR_LENGTH 2048
|
||||
|
@ -70,7 +72,7 @@ vector<string> GetCommand(int argc,char** argv,bool &reInp,bool &pauseAfterExit)
|
|||
|
||||
string unescapeSpaces(const string& s) {
|
||||
string result;
|
||||
int i=0;
|
||||
size_t i=0;
|
||||
while(i<s.length()) {
|
||||
if (s[i]=='%' && (i+2)<s.length() && s[i+1]=='2' && s[i+2]=='0') {
|
||||
result.push_back(' ');
|
||||
|
@ -83,7 +85,8 @@ string unescapeSpaces(const string& s) {
|
|||
return result;
|
||||
}
|
||||
|
||||
int ExecuteCommand(vector<string>& command,bool reInp) {
|
||||
int ExecuteCommand(vector<string>& command,bool reInp, long int &peakMemory) {
|
||||
peakMemory = 0;
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
string path_to_command;
|
||||
|
@ -133,11 +136,13 @@ int ExecuteCommand(vector<string>& command,bool reInp) {
|
|||
} else {
|
||||
int status;
|
||||
pid_t w;
|
||||
w = waitpid(pid, &status, WUNTRACED | WCONTINUED);
|
||||
struct rusage usage;
|
||||
w = wait4(pid, &status, WUNTRACED | WCONTINUED, &usage);
|
||||
if (w==-1) {
|
||||
perror("waitpid failed!");
|
||||
perror("wait4 failed!");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
peakMemory = usage.ru_maxrss;
|
||||
if (WIFEXITED(status)) {
|
||||
return WEXITSTATUS(status);
|
||||
} else {
|
||||
|
@ -195,7 +200,8 @@ int main(int argc, char** argv) {
|
|||
auto starttime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// Execute the command
|
||||
int returnvalue = ExecuteCommand(command,reInp);
|
||||
long int peakMemory;
|
||||
int returnvalue = ExecuteCommand(command,reInp, peakMemory);
|
||||
|
||||
// Get ending timestamp
|
||||
auto endtime = std::chrono::high_resolution_clock::now();
|
||||
|
@ -213,7 +219,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
// Done? Print return value of executed program
|
||||
printf("\n--------------------------------");
|
||||
printf("\nProcess exited after %.4g seconds with return value %lu\n",seconds,returnvalue);
|
||||
printf("\nProcess exited after %.4g seconds with return value %lu, %d KB mem used.\n",seconds,returnvalue,peakMemory);
|
||||
if (pauseAfterExit)
|
||||
PauseExit(returnvalue,reInp);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue