Added logging of mercury events to uncover performance problems.

This commit is contained in:
Pedro Pinto committed 2018-10-20 16:36:21 +00:00
1 parent df56c85e7b
commit 2db8d717d4
1 file changed
+30 -5
+30 -5
View File
@@ -4,6 +4,7 @@
#include "lib/mercury/topics/ITopic.h"
#include "lib/utils/Puid.h"
#include "lib/utils/bts_assert.h"
#include "lib/utils/bts_chrono.h"
#include <algorithm>
#include <boost/container/flat_map.hpp>
@@ -30,13 +31,15 @@ struct Broker::LocalSubFilter {
struct Broker::StreamRec {
StreamRec(Broker &owner, IRemoteBroker &src, StreamID sid,
TopicPtr const &topic)
: owner(owner), local(false), src(&src), sid(sid), topic(topic),
local_subs(), external_subs(), sub_id(),
: owner(owner), local(false), src(&src), sid(sid),
topic_str(intern_topic_str(topic)), topic(topic), local_subs(),
external_subs(), sub_id(),
synopsis_builder(topic->make_synopsis_builder()),
topic_tag(topic->to_str()) {}
StreamRec(Broker &owner, StreamID sid, TopicPtr const &topic)
: owner(owner), local(true), src(), sid(sid), topic(topic), local_subs(),
: owner(owner), local(true), src(), sid(sid),
topic_str(intern_topic_str(topic)), topic(topic), local_subs(),
external_subs(), sub_id(),
synopsis_builder(topic->make_synopsis_builder()),
topic_tag(topic->to_str()) {}
@@ -56,10 +59,21 @@ struct Broker::StreamRec {
IRemoteBroker *neighbour;
};
char *intern_topic_str(TopicPtr const &topic) {
// this C string is used to make it possible to log topic names
// assynchronously, without copying strings around. we leak
// topic names, which isn't great, but performance oblige.
auto ts = topic->to_str();
auto result = new char[ts.size() + 1];
memcpy(result, ts.c_str(), ts.size() + 1);
return result;
}
Broker &owner;
const bool local;
IRemoteBroker *const src;
const StreamID sid;
const char *topic_str;
const TopicPtr topic;
std::vector<LocalSubRec> local_subs;
@@ -337,15 +351,26 @@ void Broker::notify(BrokerID sender, StreamID sid, SubID ex_subid,
Notification const &payload) {
NoReenter nr(me->inside);
#else
void Broker::notify(BrokerID , StreamID sid, SubID ex_subid,
void Broker::notify(BrokerID, StreamID sid, SubID ex_subid,
Notification const &payload) {
#endif
auto &srec = me->streams[sid];
bts_assert_d(srec);
bts_assert_d((srec->is_local() && sender == id()) ||
(!srec->is_local() && srec->src->id() == sender));
if (srec->is_local() || srec->sub_id == ex_subid)
if (srec->is_local() || srec->sub_id == ex_subid) {
LOG(Mercury, Diag, "Started handling event {} on broker {}",
log::CharPtrWrapper{srec->topic_str}, me->my_id.value());
auto start = Timer::now();
srec->notify(payload);
auto stop = Timer::now();
LOG(Mercury, Diag, "Finished handling event {} on broker {}. Time: {}ns",
log::CharPtrWrapper{srec->topic_str}, me->my_id.value(),
ns_diff(stop, start));
}
}
void Broker::subscribe(BrokerID sender, SubID ex_subid, StreamID sid) {