From 387b4ff21562f6db6740d482b7f416982a1c703d Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Tue, 23 Oct 2018 18:03:22 +0200 Subject: [PATCH 1/4] T: fix compilation of tracers If you run 'make' in common/utils/T/tracer just after a clone of the repository then the compilation will fail because the file ../T_IDs.h was not generated. Let's add a simple dependency to fix this. --- common/utils/T/tracer/Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/utils/T/tracer/Makefile b/common/utils/T/tracer/Makefile index 3da4aa13a1..792c2a407c 100644 --- a/common/utils/T/tracer/Makefile +++ b/common/utils/T/tracer/Makefile @@ -60,6 +60,11 @@ macpdu2wireshark: macpdu2wireshark.o database.o utils.o handler.o event.o \ multi: multi.o utils.o database.o config.o $(CC) $(CFLAGS) -o multi $^ $(LIBS) +multi.o: ../T_IDs.h + +../T_IDs.h: + cd .. && $(MAKE) + .PHONY: all gui/gui.a view/view.a logger/logger.a filter/filter.a gui/gui.a: From f6f6570d6e9545371373f5fd109bcce74533f3ae Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Tue, 23 Oct 2018 18:05:40 +0200 Subject: [PATCH 2/4] T: minor: don't abort() in textlog.c This leads to some logs missing in some situations. Plus it's not user-friendly. --- common/utils/T/tracer/textlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/utils/T/tracer/textlog.c b/common/utils/T/tracer/textlog.c index bb773b4215..dba9d55483 100644 --- a/common/utils/T/tracer/textlog.c +++ b/common/utils/T/tracer/textlog.c @@ -187,7 +187,7 @@ int main(int n, char **v) while (1) { event e; e = get_event(textlog_data.socket, &ebuf, database); - if (e.type == -1) abort(); + if (e.type == -1) break; handle_event(h, e); } From a46443b2a910eee6f7c904f5f811ee06a028084e Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Wed, 31 Oct 2018 12:05:08 +0100 Subject: [PATCH 3/4] T: textlog: add option to dump 'raw time' 'raw time' is the tv_sec element in the struct tm as returned by 'localtime'. This can be useful to extract events from a dump based on their time. --- common/utils/T/tracer/logger/logger.h | 1 + common/utils/T/tracer/logger/textlog.c | 17 ++++++++++++++--- common/utils/T/tracer/textlog.c | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/common/utils/T/tracer/logger/logger.h b/common/utils/T/tracer/logger/logger.h index 434cf5a90f..7c019b4797 100644 --- a/common/utils/T/tracer/logger/logger.h +++ b/common/utils/T/tracer/logger/logger.h @@ -30,6 +30,7 @@ void framelog_set_skip(logger *_this, int skip_delay); void framelog_set_update_only_at_sf9(logger *_this, int update_only_at_sf9); void textlog_dump_buffer(logger *_this, int dump_buffer); +void textlog_raw_time(logger *_this, int raw_time); #include "view/view.h" diff --git a/common/utils/T/tracer/logger/textlog.c b/common/utils/T/tracer/logger/textlog.c index 9eb6fd02d8..76f920e1e2 100644 --- a/common/utils/T/tracer/logger/textlog.c +++ b/common/utils/T/tracer/logger/textlog.c @@ -33,6 +33,7 @@ struct textlog { /* local output buffer */ OBUF o; int dump_buffer; + int raw_time; }; static void _event(void *p, event e) @@ -51,9 +52,13 @@ static void _event(void *p, event e) #ifdef T_SEND_TIME t = localtime(&e.sending_time.tv_sec); - /* round tv_nsec to nearest millisecond */ - sprintf(tt, "%2.2d:%2.2d:%2.2d.%9.9ld: ", t->tm_hour, t->tm_min, t->tm_sec, - e.sending_time.tv_nsec); + if (l->raw_time) + sprintf(tt, "%2.2d:%2.2d:%2.2d.%9.9ld [%ld]: ", + t->tm_hour, t->tm_min, t->tm_sec, + e.sending_time.tv_nsec, e.sending_time.tv_sec); + else + sprintf(tt, "%2.2d:%2.2d:%2.2d.%9.9ld: ", t->tm_hour, t->tm_min, t->tm_sec, + e.sending_time.tv_nsec); PUTS(&l->o, tt); #endif @@ -215,3 +220,9 @@ void textlog_dump_buffer(logger *_this, int dump_buffer) struct textlog *l = _this; l->dump_buffer = dump_buffer; } + +void textlog_raw_time(logger *_this, int raw_time) +{ + struct textlog *l = _this; + l->raw_time = raw_time; +} diff --git a/common/utils/T/tracer/textlog.c b/common/utils/T/tracer/textlog.c index dba9d55483..a123bf9bf5 100644 --- a/common/utils/T/tracer/textlog.c +++ b/common/utils/T/tracer/textlog.c @@ -52,6 +52,7 @@ void usage(void) " they will be processed in order\n" " by default, all is off\n" " -full also dump buffers' content\n" +" -raw-time also prints 'raw time'\n" " -ip connect to given IP address (default %s)\n" " -p connect to given port (default %d)\n" " -x GUI output\n" @@ -91,6 +92,7 @@ int main(int n, char **v) int gui_active = 1; textlog_data textlog_data; int full = 0; + int raw_time = 0; /* write on a socket fails if the other end is closed and we get SIGPIPE */ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) abort(); @@ -117,6 +119,7 @@ int main(int n, char **v) if (!strcmp(v[i], "-debug-gui")) { gui_logd = 1; continue; } if (!strcmp(v[i], "-no-gui")) { gui_active = 0; continue; } if (!strcmp(v[i], "-full")) { full = 1; continue; } + if (!strcmp(v[i], "-raw-time")) { raw_time = 1; continue; } usage(); } @@ -162,6 +165,7 @@ int main(int n, char **v) // "ev: {} eNB_id [eNB_ID] frame [frame] subframe [subframe]"); logger_add_view(textlog, out); if (full) textlog_dump_buffer(textlog, 1); + if (raw_time) textlog_raw_time(textlog, 1); free(name); free(desc); } From 633534c2f0227672188368c17b0b15ff2705be9f Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 2 Nov 2018 09:50:02 +0100 Subject: [PATCH 4/4] T: extract: add time and count criteria --- common/utils/T/tracer/extract.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/common/utils/T/tracer/extract.c b/common/utils/T/tracer/extract.c index 2aec38831f..d66e8a3bb8 100644 --- a/common/utils/T/tracer/extract.c +++ b/common/utils/T/tracer/extract.c @@ -16,6 +16,8 @@ void usage(void) " -f field 'name' of 'event' has to match 'value'\n" " type of 'name' must be int\n" " (you can use several -f options)\n" +" -after 'event' time has to be greater than this\n" +" -count dump 'n' matching events (less if EOF reached)\n" ); exit(1); } @@ -51,6 +53,10 @@ int main(int n, char **v) int filter_count = 0; int buffer_arg; int found; + int count = 1; + int check_time = 0; + time_t sec; + long nsec; for (i = 1; i < n; i++) { if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); @@ -63,6 +69,14 @@ int main(int n, char **v) filter_value[filter_count++] = atoi(v[++i]); continue; } + if (!strcmp(v[i], "-after")) { if (i>n-3) usage(); + check_time = 1; + sec = atoll(v[++i]); + nsec = atol(v[++i]); + continue; + } + if (!strcmp(v[i], "-count")) + { if (i > n-2) usage(); count = atoi(v[++i]); continue; } if (file == NULL) { file = v[i]; continue; } if (event_name == NULL) { event_name = v[i]; continue; } if (buffer_name == NULL) { buffer_name = v[i]; continue; } @@ -111,13 +125,20 @@ int main(int n, char **v) break; if (i != filter_count) continue; + if (check_time && + !(e.sending_time.tv_sec > sec || + (e.sending_time.tv_sec == sec && e.sending_time.tv_nsec >= nsec))) + continue; if (fwrite(e.e[buffer_arg].b, e.e[buffer_arg].bsize, 1, out) != 1) { perror(output_file); exit(1); } - found = 1; - break; + found++; + if (found == count) + break; } if (found == 0) printf("ERROR: event not found\n"); + if (found != count) + printf("WARNING: dumped %d events (wanted %d)\n", found, count); fclose(out);