aboutsummaryrefslogtreecommitdiff
path: root/libcmix-common
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-12-01 21:42:51 +0100
committerDennis Brentjes <d.brentjes@gmail.com>2016-12-01 21:43:48 +0100
commit16c28db384adbe61034eb8a2267cd6a886ffd72f (patch)
tree426be5a41f5186ba17e909dda90afca5b7921c30 /libcmix-common
parent463b8ec708db0d2d7405d434e28d0140c94b1d98 (diff)
downloadcmix-16c28db384adbe61034eb8a2267cd6a886ffd72f.tar.gz
cmix-16c28db384adbe61034eb8a2267cd6a886ffd72f.tar.bz2
cmix-16c28db384adbe61034eb8a2267cd6a886ffd72f.zip
Added the client side code for the statsd in the nodes.
Diffstat (limited to 'libcmix-common')
-rw-r--r--libcmix-common/CMakeLists.txt5
-rw-r--r--libcmix-common/cmixprotofunctor.hpp3
-rw-r--r--libcmix-common/performanceclient.cpp29
-rw-r--r--libcmix-common/performanceclient.hpp16
4 files changed, 51 insertions, 2 deletions
diff --git a/libcmix-common/CMakeLists.txt b/libcmix-common/CMakeLists.txt
index 2324622..958be6a 100644
--- a/libcmix-common/CMakeLists.txt
+++ b/libcmix-common/CMakeLists.txt
@@ -1,10 +1,12 @@
+find_package(Boost COMPONENTS timer REQUIRED)
+
add_library(cmix-common
cmixprotofunctor.hpp
receiver.hpp
sender.hpp
senderreceiver.hpp
- performanceclient.hpp
+ performanceclient.hpp performanceclient.cpp
)
set_target_properties(cmix-common PROPERTIES LINKER_LANGUAGE CXX)
@@ -16,4 +18,5 @@ target_include_directories(cmix-common
target_link_libraries(cmix-common
PRIVATE cmix-protobuf
PRIVATE cmix-network
+ PRIVATE Boost::timer
) \ No newline at end of file
diff --git a/libcmix-common/cmixprotofunctor.hpp b/libcmix-common/cmixprotofunctor.hpp
index 0c8a341..17793ec 100644
--- a/libcmix-common/cmixprotofunctor.hpp
+++ b/libcmix-common/cmixprotofunctor.hpp
@@ -68,7 +68,8 @@ struct CMixProtoFunctor {
PrePost, prepost,
RealPre, realpre,
RealMix, realmix,
- Payload, payload
+ Payload, payload,
+ Performance, performance
)
#undef MESSAGE_SETTER_DEFS
#undef MESSAGE_SETTER_DEF_ITERATION
diff --git a/libcmix-common/performanceclient.cpp b/libcmix-common/performanceclient.cpp
new file mode 100644
index 0000000..70953a8
--- /dev/null
+++ b/libcmix-common/performanceclient.cpp
@@ -0,0 +1,29 @@
+#include "performanceclient.hpp"
+
+#include <boost/date_time.hpp>
+
+#include <memory>
+
+PerformanceClient::PerformanceClient(std::string name, boost::asio::io_service& io_service, std::string host, std::string port)
+: node_name(name)
+, sender(std::unique_ptr<boost::asio::ip::tcp::socket>(new boost::asio::ip::tcp::socket(io_service)))
+, timer()
+{
+ timer.start();
+ sender.async_connect(host, port, []{});
+}
+
+void PerformanceClient::send(std::string column)
+{
+ cmix_proto::Performance perf;
+ perf.set_node(node_name);
+ perf.set_column(column);
+
+ auto tp = timer.elapsed();
+
+ perf.set_wall_time(std::to_string(tp.wall));
+ perf.set_user_time(std::to_string(tp.user));
+ perf.set_system_time(std::to_string(tp.system));
+
+ sender.async_send(perf);
+}
diff --git a/libcmix-common/performanceclient.hpp b/libcmix-common/performanceclient.hpp
new file mode 100644
index 0000000..cb9afb1
--- /dev/null
+++ b/libcmix-common/performanceclient.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "sender.hpp"
+
+#include <boost/timer/timer.hpp>
+
+class PerformanceClient
+{
+ std::string node_name;
+ Sender sender;
+ boost::timer::cpu_timer timer;
+public:
+ PerformanceClient(std::string name, boost::asio::io_service& io_service, std::string host, std::string port);
+
+ void send(std::string column);
+}; \ No newline at end of file