aboutsummaryrefslogtreecommitdiff
path: root/src/p2p/data_logger.cpp
diff options
context:
space:
mode:
authorrfree2monero <rfreemonero@op.pl>2015-02-12 20:59:39 +0100
committerrfree2monero <rfreemonero@op.pl>2015-02-20 22:13:00 +0100
commit5ce4256e3d6ff2e1595750e3875865089e20a03b (patch)
tree6e26a3ac3285cb3c86c24caa7fa51033d2794085 /src/p2p/data_logger.cpp
parent2014 network limit 1.0a +utils +toc -doc -drmonero (diff)
downloadmonero-5ce4256e3d6ff2e1595750e3875865089e20a03b.tar.xz
2014 network limit 1.1 +utils +toc -doc -drmonero
Update of the PR with network limits works very well for all speeds (but remember that low download speed can stop upload because we then slow down downloading of blockchain requests too) more debug options fixed pedantic warnings in our code should work again on Mac OS X and FreeBSD fixed warning about size_t tested on Debian, Ubuntu, Windows(testing now) TCP options and ToS (QoS) flag FIXED peer number limit FIXED some spikes in ingress/download FIXED problems when other up and down limit
Diffstat (limited to 'src/p2p/data_logger.cpp')
-rw-r--r--src/p2p/data_logger.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/p2p/data_logger.cpp b/src/p2p/data_logger.cpp
new file mode 100644
index 000000000..6a8eb25be
--- /dev/null
+++ b/src/p2p/data_logger.cpp
@@ -0,0 +1,81 @@
+#include "data_logger.hpp"
+
+#include <boost/chrono.hpp>
+#include <chrono>
+
+namespace epee
+{
+namespace net_utils
+{
+ data_logger &data_logger::get_instance()
+ {
+ static data_logger instance;
+ return instance;
+ }
+
+ data_logger::data_logger()
+ {
+ //create timer
+ std::shared_ptr<std::thread> logger_thread(new std::thread([&]()
+ {
+ while (true)
+ {
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ saveToFile();
+ }
+ }));
+ logger_thread->detach();
+
+ mFilesMap["peers"] = data_logger::fileData("log/dr-monero/peers.data");
+ mFilesMap["download"] = data_logger::fileData("log/dr-monero/net/in-all.data");
+ mFilesMap["upload"] = data_logger::fileData("log/dr-monero/net/out-all.data");
+ mFilesMap["request"] = data_logger::fileData("log/dr-monero/net/req-all.data");
+ mFilesMap["sleep_down"] = data_logger::fileData("log/dr-monero/down_sleep_log.data");
+ mFilesMap["sleep_up"] = data_logger::fileData("log/dr-monero/up_sleep_log.data");
+
+ }
+
+ void data_logger::add_data(std::string filename, unsigned int data)
+ {
+ if (mFilesMap.find(filename) == mFilesMap.end())
+ return; // TODO: exception
+
+ mFilesMap[filename].mDataToSave += data;
+ }
+
+ double data_logger::fileData::get_current_time()
+ {
+ using namespace boost::chrono;
+ auto point = steady_clock::now();
+ auto time_from_epoh = point.time_since_epoch();
+ auto ms = duration_cast< milliseconds >( time_from_epoh ).count();
+ double ms_f = ms;
+ return ms_f / 1000.;
+ }
+
+ data_logger::fileData::fileData(std::string pFile)
+ {
+ mFile = std::make_shared<std::ofstream> (pFile);
+ }
+
+ void data_logger::fileData::save()
+ {
+ if (!data_logger::m_save_graph)
+ return;
+ *mFile << static_cast<int>(get_current_time()) << " " << mDataToSave << std::endl;
+ }
+
+ void data_logger::saveToFile()
+ {
+ std::lock_guard<std::mutex> lock(mSaveMutex);
+ for (auto &element : mFilesMap)
+ {
+ element.second.save();
+ element.second.mDataToSave = 0;
+ }
+ }
+
+std::atomic<bool> data_logger::m_save_graph(false);
+
+} // namespace
+} // namespace