diff --git a/src/sonic-eventd/Makefile b/src/sonic-eventd/Makefile index ed54ea170e7d..16aced1716bd 100644 --- a/src/sonic-eventd/Makefile +++ b/src/sonic-eventd/Makefile @@ -7,7 +7,7 @@ RSYSLOG-PLUGIN_TEST := rsyslog_plugin_tests/tests CP := cp MKDIR := mkdir CC := g++ -MV := mv +CP := cp LIBS := -levent -lhiredis -lswsscommon -lpthread -lboost_thread -lboost_system -lzmq -lboost_serialization -luuid TEST_LIBS := -L/usr/src/gtest -lgtest -lgtest_main -lgmock -lgmock_main @@ -69,8 +69,8 @@ rsyslog-plugin-tests: $(RSYSLOG-PLUGIN-TEST_OBJS) install: $(MKDIR) -p $(DESTDIR)/usr/sbin - $(MV) $(EVENTD_TARGET) $(DESTDIR)/usr/sbin - $(MV) $(EVENTD_TOOL) $(DESTDIR)/usr/sbin + $(CP) $(EVENTD_TARGET) $(DESTDIR)/usr/sbin + $(CP) $(EVENTD_TOOL) $(DESTDIR)/usr/sbin deinstall: $(RM) $(DESTDIR)/usr/sbin/$(EVENTD_TARGET) diff --git a/src/sonic-eventd/tools/events_tool.cpp b/src/sonic-eventd/tools/events_tool.cpp index 4e42591d4596..8da0a8bf396e 100644 --- a/src/sonic-eventd/tools/events_tool.cpp +++ b/src/sonic-eventd/tools/events_tool.cpp @@ -61,6 +61,7 @@ Note:\n\ ]\n\ Default: \n\ \n\ +-c - Use offline cache in receive mode\n\ -o - O/p file to write received events\n\ Default: STDOUT\n"; @@ -86,7 +87,7 @@ t_map_to_str(const Map &m) } void -do_receive(const event_subscribe_sources_t filter, const string outfile, int cnt=0, int pause=0) +do_receive(const event_subscribe_sources_t filter, const string outfile, int cnt, int pause, bool use_cache) { int index=0, total_missed = 0; ostream* fp = &cout; @@ -99,7 +100,9 @@ do_receive(const event_subscribe_sources_t filter, const string outfile, int cnt printf("outfile=%s set\n", outfile.c_str()); } } - event_handle_t h = events_init_subscriber(false, 100, filter.empty() ? NULL : &filter); + event_handle_t h = events_init_subscriber(use_cache, 2000, filter.empty() ? NULL : &filter); + printf("Subscribed with use_cache=%d timeout=2000 filter %s\n", + use_cache, filter.empty() ? "empty" : "non-empty"); ASSERT(h != NULL, "Failed to get subscriber handle"); while(!term_receive) { @@ -130,10 +133,6 @@ do_receive(const event_subscribe_sources_t filter, const string outfile, int cnt break; } } - if (pause) { - /* Pause between two sends */ - this_thread::sleep_for(chrono::milliseconds(pause)); - } } events_deinit_subscriber(h); @@ -277,6 +276,7 @@ void usage() int main(int argc, char **argv) { + bool use_cache = false; int op = OP_INIT; int cnt=0, pause=0; string json_str_msg, outfile("STDOUT"), infile; @@ -284,8 +284,12 @@ int main(int argc, char **argv) for(;;) { - switch(getopt(argc, argv, "srn:p:i:o:f:")) // note the colon (:) to indicate that 'b' has a parameter and is not a switch + switch(getopt(argc, argv, "srn:p:i:o:f:c")) // note the colon (:) to indicate that 'b' has a parameter and is not a switch { + case 'c': + use_cache = true; + continue; + case 's': op |= OP_SEND; continue; @@ -339,14 +343,14 @@ int main(int argc, char **argv) op, cnt, pause, infile.c_str(), outfile.c_str()); if (op == OP_SEND_RECV) { - thread thr(&do_receive, filter, outfile, 0, 0); + thread thr(&do_receive, filter, outfile, 0, 0, use_cache); do_send(infile, cnt, pause); } else if (op == OP_SEND) { do_send(infile, cnt, pause); } else if (op == OP_RECV) { - do_receive(filter, outfile, cnt, pause); + do_receive(filter, outfile, cnt, pause, use_cache); } else { ASSERT(false, "Elect -s for send or -r receive or both; Bailing out with no action\n");