Tools: Replay: option to print packet counts out at end

This commit is contained in:
Peter Barker 2015-06-30 12:48:49 +10:00 committed by Francisco Ferreira
parent 6b5fd5fbdd
commit 0062084c40
4 changed files with 52 additions and 2 deletions

View File

@ -42,6 +42,20 @@ ssize_t DataFlashFileReader::read_input(void *buffer, const size_t count)
return ret; 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]) bool DataFlashFileReader::update(char type[5])
{ {
uint8_t hdr[3]; uint8_t hdr[3];
@ -53,6 +67,8 @@ bool DataFlashFileReader::update(char type[5])
return false; return false;
} }
packet_counts[hdr[2]]++;
if (hdr[2] == LOG_FORMAT_MSG) { if (hdr[2] == LOG_FORMAT_MSG) {
struct log_Format f; struct log_Format f;
memcpy(&f, hdr, 3); memcpy(&f, hdr, 3);

View File

@ -2,6 +2,8 @@
#include <DataFlash/DataFlash.h> #include <DataFlash/DataFlash.h>
#define LOGREADER_MAX_FORMATS 255 // must be >= highest MESSAGE
class DataFlashFileReader class DataFlashFileReader
{ {
public: public:
@ -15,12 +17,14 @@ public:
virtual bool handle_log_format_msg(const struct log_Format &f) = 0; 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; 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: protected:
int fd = -1; int fd = -1;
bool done_format_msgs = false; bool done_format_msgs = false;
virtual void end_format_msgs(void) {} virtual void end_format_msgs(void) {}
#define LOGREADER_MAX_FORMATS 255 // must be >= highest MESSAGE
struct log_Format formats[LOGREADER_MAX_FORMATS] {}; struct log_Format formats[LOGREADER_MAX_FORMATS] {};
private: private:
@ -30,4 +34,5 @@ private:
uint32_t message_count = 0; uint32_t message_count = 0;
uint64_t start_micros; uint64_t start_micros;
uint64_t packet_counts[LOGREADER_MAX_FORMATS] = {};
}; };

View File

@ -156,6 +156,7 @@ void Replay::usage(void)
::printf("\t--logmatch match logging rate to source\n"); ::printf("\t--logmatch match logging rate to source\n");
::printf("\t--no-params don't use parameters from the log\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--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_NOPARAMS,
OPT_PARAM_FILE, OPT_PARAM_FILE,
OPT_NO_FPE, OPT_NO_FPE,
OPT_PACKET_COUNTS,
}; };
void Replay::flush_dataflash(void) { 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}, {"logmatch", false, 0, OPT_LOGMATCH},
{"no-params", false, 0, OPT_NOPARAMS}, {"no-params", false, 0, OPT_NOPARAMS},
{"no-fpe", false, 0, OPT_NO_FPE}, {"no-fpe", false, 0, OPT_NO_FPE},
{"packet-counts", false, 0, OPT_PACKET_COUNTS},
{0, false, 0, 0} {0, false, 0, 0}
}; };
@ -310,6 +313,10 @@ void Replay::_parse_command_line(uint8_t argc, char * const argv[])
generate_fpe = false; generate_fpe = false;
break; break;
case OPT_PACKET_COUNTS:
packet_counts = true;
break;
case 'h': case 'h':
default: default:
usage(); usage();
@ -780,9 +787,30 @@ void Replay::flush_and_exit()
report_checks(); report_checks();
} }
if (packet_counts) {
show_packet_counts();
}
exit(0); 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<LOGREADER_MAX_FORMATS;i++) {
if (counts[i] != 0) {
logreader.format_type(i, format_type);
printf("%10ld %s\n", counts[i], format_type);
total += counts[i];
}
}
printf("%ld total\n", total);
}
void Replay::loop() void Replay::loop()
{ {
char type[5]; char type[5];
@ -813,7 +841,6 @@ void Replay::loop()
if (!streq(type,"ATT")) { if (!streq(type,"ATT")) {
return; return;
} }
} }

View File

@ -94,6 +94,7 @@ public:
void loop() override; void loop() override;
void flush_dataflash(void); void flush_dataflash(void);
void show_packet_counts();
bool check_solution = false; bool check_solution = false;
const char *log_filename = NULL; const char *log_filename = NULL;
@ -142,6 +143,7 @@ private:
bool logmatch = false; bool logmatch = false;
uint32_t output_counter = 0; uint32_t output_counter = 0;
uint64_t last_timestamp = 0; uint64_t last_timestamp = 0;
bool packet_counts = false;
struct { struct {
float max_roll_error; float max_roll_error;