diff --git a/.gitignore b/.gitignore index ee9f1fa..da070cb 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ CMakeCache.txt *.cmake *.a + +# for task3 +counter.txt \ No newline at end of file diff --git a/task_3/counter.txt b/task_3/counter.txt index f937f7e..368f89c 100644 --- a/task_3/counter.txt +++ b/task_3/counter.txt @@ -1 +1 @@ -233 \ No newline at end of file +28 \ No newline at end of file diff --git a/task_3/counter_manager.h b/task_3/counter_manager.h index ff5cd8c..98833df 100644 --- a/task_3/counter_manager.h +++ b/task_3/counter_manager.h @@ -1,7 +1,5 @@ #include -#include #include -#include class CounterManager { diff --git a/task_3/log_writer.cpp b/task_3/log_writer.cpp index 94268f8..f2295f0 100644 --- a/task_3/log_writer.cpp +++ b/task_3/log_writer.cpp @@ -20,18 +20,22 @@ int LogWriter::write_log(const std::string& log_line) { std::string LogWriter::get_current_time() { - time_t current_time = std::time(nullptr); - return ctime(¤t_time); + time_t rawtime; + struct tm * timeinfo; + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + std::string res = asctime (timeinfo); + res.pop_back(); + return res; } int LogWriter::log_start_line(){ - std::string current_time = "00:00:00"; std::string log_line = ( "start programm with pid " + std::to_string(getpid()) + " at " + - current_time + get_current_time() ); write_log(log_line); return 0; @@ -39,10 +43,9 @@ int LogWriter::log_start_line(){ int LogWriter::log_counter(long long int counter){ - std::string current_time = "00:00:00"; std::string log_line = ( "counter at " + - current_time + + get_current_time() + " in process with pid " + std::to_string(getpid()) + " is " + @@ -54,11 +57,10 @@ int LogWriter::log_counter(long long int counter){ int LogWriter::log_copy_start(std::string copy_name) { - std::string current_time = "00:00:00"; std::string log_line = ( copy_name + " is started at " + - current_time + + get_current_time() + " with pid " + std::to_string(getpid()) ); @@ -67,11 +69,10 @@ int LogWriter::log_copy_start(std::string copy_name) { } int LogWriter::log_copy_finish(std::string copy_name) { - std::string current_time = "00:00:00"; std::string log_line = ( copy_name + " is finished at " + - current_time + get_current_time() ); write_log(log_line); } diff --git a/task_3/log_writer.h b/task_3/log_writer.h index d5f5d96..3df721c 100644 --- a/task_3/log_writer.h +++ b/task_3/log_writer.h @@ -1,9 +1,7 @@ #include #include #include -#include - -#include +#include class LogWriter { diff --git a/task_3/main.cpp b/task_3/main.cpp index 7dfa1e0..c4a94ff 100644 --- a/task_3/main.cpp +++ b/task_3/main.cpp @@ -1,8 +1,9 @@ #include "process_launcher.h" #include "log_writer.h" #include "counter_manager.h" -#include // for ms in timestamp -#include // for debugging + +#include + struct two_pid { int pid_1, pid_2; @@ -32,8 +33,11 @@ struct two_pid { uint64_t get_timestamp_ms() { - using namespace std::chrono; - return duration_cast(system_clock::now().time_since_epoch()).count(); + struct timeval tv; + gettimeofday(&tv, NULL); + + return (((long long)tv.tv_sec)*1000)+(tv.tv_usec/1000); + } int main(int argc, char* argv[]) { @@ -48,7 +52,7 @@ int main(int argc, char* argv[]) { if (argv[1][0] == '2') { LogWriter::log_copy_start("Copy 2"); CounterManager::set_counter(CounterManager::get_counter() * 2); - // sleep 2s + sleep(2); CounterManager::set_counter(CounterManager::get_counter() / 2); LogWriter::log_copy_finish("Copy 2"); return 0;