• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版5710f97d5774deca5e27d7d0ff26f61b3f6bee9c (tree)
时间2020-07-15 03:09:19
作者Alexander Larin
CommiterAlexander Larin

Log Message

Implement i_process for rp_linux

更改概述

差异

diff -r a45178f8de08 -r 5710f97d5774 libs/checklib/details/rp_linux.cpp
--- a/libs/checklib/details/rp_linux.cpp Tue Jul 14 14:08:31 2020 +0300
+++ b/libs/checklib/details/rp_linux.cpp Tue Jul 14 21:09:19 2020 +0300
@@ -74,6 +74,13 @@
7474 return mIsRunning.load();
7575 }
7676
77+bool checklib::details::RestrictedProcessImpl::end_process(ProcessStatus status)
78+{
79+ // This is a blank implementation, will be changed soon
80+ terminate();
81+ return true;
82+}
83+
7784 // Запуск процесса
7885 void checklib::details::RestrictedProcessImpl::start()
7986 {
@@ -305,7 +312,8 @@
305312 // Сколько процессорного времени израсходовал процесс
306313 int checklib::details::RestrictedProcessImpl::cpu_time()
307314 {
308- return mCPUTime.load();
315+ if (is_running()) return cpu_time_impl();
316+ return m_cpu_time;
309317 }
310318
311319 checklib::Limits checklib::details::RestrictedProcessImpl::getLimits() const
@@ -387,7 +395,7 @@
387395 mErrorPipe.reset();
388396
389397 mPeakMemoryUsage.store(0);
390- mCPUTime.store(0);
398+ m_cpu_time.store(0);
391399 mIsRunning.store(false);
392400 mProcessStatus.store(psNotRunning);
393401 }
@@ -428,7 +436,7 @@
428436 cminflt >> majflt >> cmajflt >> utime >> stime;
429437
430438 int currentCPUTime = (utime + stime) / mTicks * 1000;
431- mCPUTime.store(currentCPUTime);
439+ m_cpu_time.store(currentCPUTime);
432440 if (mLimits.useTimeLimit && mLimits.timeLimit < currentCPUTime)
433441 {
434442 mProcessStatus.store(psTimeLimitExceeded);
@@ -533,3 +541,19 @@
533541 }
534542 return false;
535543 }
544+
545+int checklib::details::RestrictedProcessImpl::cpu_time_impl() const
546+{
547+ std::ostringstream name;
548+ name << mChildPid;
549+ std::ifstream is("/proc/" + name.str() + "/stat");
550+
551+ // Получение времени работы процесса. Интересуют нас только последние два числа
552+ std::string pid, comm, state, ppid, pgrp, session, tty_nr;
553+ std::string tpgid, flags, minflt, cminflt, majflt, cmajflt;
554+ long long int utime, stime;
555+ is >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr >> tpgid >> flags >> minflt >>
556+ cminflt >> majflt >> cmajflt >> utime >> stime;
557+
558+ return (utime + stime) / mTicks * 1000;
559+}
\ No newline at end of file
diff -r a45178f8de08 -r 5710f97d5774 libs/checklib/details/rp_linux.h
--- a/libs/checklib/details/rp_linux.h Tue Jul 14 14:08:31 2020 +0300
+++ b/libs/checklib/details/rp_linux.h Tue Jul 14 21:09:19 2020 +0300
@@ -2,6 +2,7 @@
22
33 #include "../rp_types.h"
44
5+#include "i_process.hpp"
56 #include <atomic>
67 #include <boost/asio.hpp>
78 #include <boost/signals2.hpp>
@@ -9,9 +10,7 @@
910 #include <boost/thread/thread.hpp>
1011 #include <memory>
1112
12-namespace checklib
13-{
14-namespace details
13+namespace checklib::details
1514 {
1615
1716 class Pipe
@@ -38,7 +37,7 @@
3837 void reset() { p.reset(); }
3938 };
4039
41-class RestrictedProcessImpl
40+class RestrictedProcessImpl : public checklib::details::IProcess
4241 {
4342 public:
4443 RestrictedProcessImpl();
@@ -53,12 +52,14 @@
5352 std::string currentDirectory() const;
5453 void setCurrentDirectory(const std::string &directory);
5554
56- bool is_running() const;
55+ bool is_running() const override;
56+
57+ bool end_process(ProcessStatus status) override;
5758
5859 void start();
5960 void terminate();
6061 void wait();
61- bool wait(int milliseconds);
62+ bool wait(int milliseconds) override;
6263
6364 // Код возврата.
6465 int exit_code() const;
@@ -67,10 +68,10 @@
6768 ProcessStatus processStatus() const;
6869
6970 // Пиковое значение потребляемой памяти
70- int peak_memory_usage();
71+ int peak_memory_usage() override;
7172
7273 // Сколько процессорного времени израсходовал процесс
73- int cpu_time();
74+ int cpu_time() override;
7475
7576 void reset();
7677
@@ -118,7 +119,7 @@
118119 int mUnchangedTicks;
119120 int mOldCPUTime;
120121
121- mutable std::atomic<int> mCPUTime, mPeakMemoryUsage;
122+ mutable std::atomic<int> m_cpu_time, mPeakMemoryUsage;
122123 std::atomic<bool> mIsRunning;
123124
124125 Pipe mInputPipe, mOutputPipe, mErrorPipe;
@@ -137,8 +138,7 @@
137138
138139 int peakMemoryUsageS() const;
139140
140- int CPUTimeS() const;
141+ int cpu_time_impl() const;
141142 };
142143
143-} // namespace details
144-} // namespace checklib
144+} // namespace checklib::details