Fix #17: Add to stdout live statistics of the number of comments treated per second

This commit is contained in:
Benjamin Loison 2023-01-06 17:55:16 +01:00
parent f436007836
commit 773f86c551
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -9,6 +9,7 @@
#include <curl/curl.h>
#include <nlohmann/json.hpp>
using namespace std;
using namespace chrono;
using json = nlohmann::json;
vector<string> getFileContent(string filePath);
@ -37,6 +38,7 @@ mutex printMutex,
set<string> 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<milliseconds>(
system_clock::now().time_since_epoch()
);
toString << (ms.count() % 1000);
return toString.str();
}