ready to launch
This commit is contained in:
parent
2595b0b7b7
commit
3ef5493892
3
.gitignore
vendored
3
.gitignore
vendored
@ -15,3 +15,6 @@ CMakeCache.txt
|
||||
*.cmake
|
||||
*.a
|
||||
|
||||
|
||||
# for task3
|
||||
counter.txt
|
@ -1 +1 @@
|
||||
233
|
||||
28
|
@ -1,7 +1,5 @@
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
class CounterManager {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctime>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
class LogWriter {
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "process_launcher.h"
|
||||
#include "log_writer.h"
|
||||
#include "counter_manager.h"
|
||||
#include <chrono> // for ms in timestamp
|
||||
#include <iostream> // for debugging
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
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<milliseconds>(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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user