Browse Source

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

master
Peter Barker 10 years ago committed by Francisco Ferreira
parent
commit
0062084c40
  1. 16
      Tools/Replay/DataFlashFileReader.cpp
  2. 7
      Tools/Replay/DataFlashFileReader.h
  3. 29
      Tools/Replay/Replay.cpp
  4. 2
      Tools/Replay/Replay.h

16
Tools/Replay/DataFlashFileReader.cpp

@ -42,6 +42,20 @@ ssize_t DataFlashFileReader::read_input(void *buffer, const size_t count) @@ -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]) @@ -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);

7
Tools/Replay/DataFlashFileReader.h

@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
#include <DataFlash/DataFlash.h>
#define LOGREADER_MAX_FORMATS 255 // must be >= highest MESSAGE
class DataFlashFileReader
{
public:
@ -15,12 +17,14 @@ 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: @@ -30,4 +34,5 @@ private:
uint32_t message_count = 0;
uint64_t start_micros;
uint64_t packet_counts[LOGREADER_MAX_FORMATS] = {};
};

29
Tools/Replay/Replay.cpp

@ -156,6 +156,7 @@ void Replay::usage(void) @@ -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 { @@ -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[]) @@ -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[]) @@ -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() @@ -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<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()
{
char type[5];
@ -813,7 +841,6 @@ void Replay::loop() @@ -813,7 +841,6 @@ void Replay::loop()
if (!streq(type,"ATT")) {
return;
}
}

2
Tools/Replay/Replay.h

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

Loading…
Cancel
Save