Skip to content

Commit

Permalink
tool update
Browse files Browse the repository at this point in the history
  • Loading branch information
renukamanavalan committed Jul 15, 2022
1 parent f10f25b commit b6484c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/sonic-eventd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
22 changes: 13 additions & 9 deletions src/sonic-eventd/tools/events_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Note:\n\
]\n\
Default: <some test message>\n\
\n\
-c - Use offline cache in receive mode\n\
-o - O/p file to write received events\n\
Default: STDOUT\n";

Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -277,15 +276,20 @@ 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;
event_subscribe_sources_t filter;

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;
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b6484c2

Please sign in to comment.