Fix #17: Add to stdout
live statistics of the number of comments treated per second
This commit is contained in:
parent
f436007836
commit
773f86c551
17
main.cpp
17
main.cpp
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user