From 773f86c5512579e71258a9baac1718042bf0a9cc Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Fri, 6 Jan 2023 17:55:16 +0100 Subject: [PATCH] Fix #17: Add to `stdout` live statistics of the number of comments treated per second --- main.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 0c6f021..de45d58 100644 --- a/main.cpp +++ b/main.cpp @@ -9,6 +9,7 @@ #include #include using namespace std; +using namespace chrono; using json = nlohmann::json; vector getFileContent(string filePath); @@ -37,6 +38,7 @@ mutex printMutex, set channelsAlreadyTreated, channelsToTreat; unsigned int commentsCount = 0, + commentsPerSecondCount = 0, requestsPerChannel = 0; string CHANNELS_DIRECTORY = "channels/", CHANNELS_FILE_PATH = "channels.txt"; @@ -67,6 +69,14 @@ int main() threads[threadsIndex] = thread(treatChannels, threadsIndex + 1); } + while(true) + { + PRINT(DEFAULT_THREAD_ID, "Comments per second: " << commentsPerSecondCount) + commentsPerSecondCount = 0; + sleep(1); + } + + // The following is dead code, as we assume below not to have ever treated completely YouTube. for(unsigned short threadsIndex = 0; threadsIndex < THREADS_NUMBER; threadsIndex++) { threads[threadsIndex].join(); @@ -233,6 +243,7 @@ void treatComment(unsigned short threadId, json comment, string channelId) } } commentsCount++; + commentsPerSecondCount++; } string exec(string cmd) @@ -288,7 +299,11 @@ string getDate() auto t = time(nullptr); auto tm = *localtime(&t); ostringstream toString; - toString << put_time(&tm, "%d-%m-%Y %H-%M-%S"); + toString << put_time(&tm, "%d-%m-%Y %H-%M-%S."); + milliseconds ms = duration_cast( + system_clock::now().time_since_epoch() + ); + toString << (ms.count() % 1000); return toString.str(); }