From 0062084c406ed912afbb6d5c5bfa952ebf6c4486 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 30 Jun 2015 12:48:49 +1000 Subject: [PATCH] Tools: Replay: option to print packet counts out at end --- Tools/Replay/DataFlashFileReader.cpp | 16 +++++++++++++++ Tools/Replay/DataFlashFileReader.h | 7 ++++++- Tools/Replay/Replay.cpp | 29 +++++++++++++++++++++++++++- Tools/Replay/Replay.h | 2 ++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/Tools/Replay/DataFlashFileReader.cpp b/Tools/Replay/DataFlashFileReader.cpp index 7203c2eabc..7941c20913 100644 --- a/Tools/Replay/DataFlashFileReader.cpp +++ b/Tools/Replay/DataFlashFileReader.cpp @@ -42,6 +42,20 @@ ssize_t DataFlashFileReader::read_input(void *buffer, const size_t count) return ret; } +void DataFlashFileReader::format_type(uint16_t type, char dest[5]) +{ + const struct log_Format &f = formats[type]; + memset(dest,0,5); + if (f.length == 0) { + return; + } + strncpy(dest, f.name, 4); +} +void DataFlashFileReader::get_packet_counts(uint64_t dest[]) +{ + memcpy(dest, packet_counts, sizeof(packet_counts)); +} + bool DataFlashFileReader::update(char type[5]) { uint8_t hdr[3]; @@ -53,6 +67,8 @@ bool DataFlashFileReader::update(char type[5]) return false; } + packet_counts[hdr[2]]++; + if (hdr[2] == LOG_FORMAT_MSG) { struct log_Format f; memcpy(&f, hdr, 3); diff --git a/Tools/Replay/DataFlashFileReader.h b/Tools/Replay/DataFlashFileReader.h index 0bd2ffae0b..9ae0302143 100644 --- a/Tools/Replay/DataFlashFileReader.h +++ b/Tools/Replay/DataFlashFileReader.h @@ -2,6 +2,8 @@ #include +#define LOGREADER_MAX_FORMATS 255 // must be >= highest MESSAGE + class DataFlashFileReader { public: @@ -15,12 +17,14 @@ public: virtual bool handle_log_format_msg(const struct log_Format &f) = 0; virtual bool handle_msg(const struct log_Format &f, uint8_t *msg) = 0; + void format_type(uint16_t type, char dest[5]); + void get_packet_counts(uint64_t dest[]); + protected: int fd = -1; bool done_format_msgs = false; virtual void end_format_msgs(void) {} -#define LOGREADER_MAX_FORMATS 255 // must be >= highest MESSAGE struct log_Format formats[LOGREADER_MAX_FORMATS] {}; private: @@ -30,4 +34,5 @@ private: uint32_t message_count = 0; uint64_t start_micros; + uint64_t packet_counts[LOGREADER_MAX_FORMATS] = {}; }; diff --git a/Tools/Replay/Replay.cpp b/Tools/Replay/Replay.cpp index 80e3264cbb..8d78d5b4ca 100644 --- a/Tools/Replay/Replay.cpp +++ b/Tools/Replay/Replay.cpp @@ -156,6 +156,7 @@ void Replay::usage(void) ::printf("\t--logmatch match logging rate to source\n"); ::printf("\t--no-params don't use parameters from the log\n"); ::printf("\t--no-fpe do not generate floating point exceptions\n"); + ::printf("\t--packet-counts print packet counts at end of processing\n"); } @@ -171,6 +172,7 @@ enum { OPT_NOPARAMS, OPT_PARAM_FILE, OPT_NO_FPE, + OPT_PACKET_COUNTS, }; void Replay::flush_dataflash(void) { @@ -227,6 +229,7 @@ void Replay::_parse_command_line(uint8_t argc, char * const argv[]) {"logmatch", false, 0, OPT_LOGMATCH}, {"no-params", false, 0, OPT_NOPARAMS}, {"no-fpe", false, 0, OPT_NO_FPE}, + {"packet-counts", false, 0, OPT_PACKET_COUNTS}, {0, false, 0, 0} }; @@ -310,6 +313,10 @@ void Replay::_parse_command_line(uint8_t argc, char * const argv[]) generate_fpe = false; break; + case OPT_PACKET_COUNTS: + packet_counts = true; + break; + case 'h': default: usage(); @@ -780,9 +787,30 @@ void Replay::flush_and_exit() report_checks(); } + if (packet_counts) { + show_packet_counts(); + } + exit(0); } +void Replay::show_packet_counts() +{ + uint64_t counts[LOGREADER_MAX_FORMATS]; + logreader.get_packet_counts(counts); + char format_type[5]; + uint64_t total = 0; + for(uint16_t i=0;i