Update the trc_pkt_lister and C-API tests to use the stats API. Command line -stats on both programs will activate use of this feature.
Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/tests/source/c_api_pkt_print_test.c | 37 ++++++++++++++++++++- decoder/tests/source/trc_pkt_lister.cpp | 37 ++++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/decoder/tests/source/c_api_pkt_print_test.c b/decoder/tests/source/c_api_pkt_print_test.c index caa67e9..01e48cf 100644 --- a/decoder/tests/source/c_api_pkt_print_test.c +++ b/decoder/tests/source/c_api_pkt_print_test.c @@ -119,6 +119,9 @@ static int test_lib_printers = 0; /* test the last error / error code api */ static int test_error_api = 0;
+/* log statistics */ +static int stats = 0; + /* Process command line options - choose the operation to use for the test. */ static int process_cmd_line(int argc, char *argv[]) { @@ -185,6 +188,10 @@ static int process_cmd_line(int argc, char *argv[]) { frame_raw_unpacked = 1; } + else if (strcmp(argv[idx], "-stats") == 0) + { + stats = 1; + } else if (strcmp(argv[idx], "-raw_packed") == 0) { frame_raw_packed = 1; @@ -648,6 +655,7 @@ static ocsd_err_t create_decoder_etmv4(dcd_tree_handle_t dcd_tree_h) { trace_config.reg_traceidr = (uint32_t)test_trc_id_override; } + test_trc_id_override = trace_config.reg_traceidr; /* remember what ID we actually used */
trace_config.reg_idr0 = 0x28000EA1; trace_config.reg_idr1 = 0x4100F403; @@ -683,6 +691,7 @@ static ocsd_err_t create_decoder_etmv3(dcd_tree_handle_t dcd_tree_h) { trace_config_etmv3.reg_trc_id = (uint32_t)test_trc_id_override; } + test_trc_id_override = trace_config_etmv3.reg_trc_id; /* remember what ID we actually used */
/* create an ETMV3 decoder - no context needed as we have a single stream to a single handler. */ return create_generic_decoder(dcd_tree_h,OCSD_BUILTIN_DCD_ETMV3,(void *)&trace_config_etmv3,0); @@ -708,6 +717,7 @@ static ocsd_err_t create_decoder_ptm(dcd_tree_handle_t dcd_tree_h) { trace_config_ptm.reg_trc_id = (uint32_t)test_trc_id_override; } + test_trc_id_override = trace_config_ptm.reg_trc_id; /* remember what ID we actually used */
/* create an PTM decoder - no context needed as we have a single stream to a single handler. */ return create_generic_decoder(dcd_tree_h,OCSD_BUILTIN_DCD_PTM,(void *)&trace_config_ptm,0); @@ -754,6 +764,7 @@ static ocsd_err_t create_decoder_extern(dcd_tree_handle_t dcd_tree_h) { trace_cfg_ext.cs_id = (uint32_t)test_trc_id_override; } + test_trc_id_override = trace_cfg_ext.cs_id;
/* create an external decoder - no context needed as we have a single stream to a single handler. */ return create_generic_decoder(dcd_tree_h, EXT_DCD_NAME, (void *)&trace_cfg_ext, 0); @@ -881,6 +892,28 @@ ocsd_err_t process_data_block(dcd_tree_handle_t dcd_tree_h, int block_index, uin return ret; }
+void print_statistics(dcd_tree_handle_t dcdtree_handle) +{ + ocsd_decode_stats_t *p_stats = 0; + ocsd_err_t err; + + sprintf(packet_str, "\nReading packet decoder statistics for ID:0x%02x...\n", test_trc_id_override); + ocsd_def_errlog_msgout(packet_str); + + err = ocsd_dt_get_decode_stats(dcdtree_handle, test_trc_id_override, &p_stats); + if (!err && p_stats) + { + sprintf(packet_str, "Total Bytes %lld; Unsynced Bytes: %lld\nBad Header Errors: %d; Bad sequence errors: %d\n", p_stats->channel_total, + p_stats->channel_unsynced, p_stats->bad_header_errs, p_stats->bad_sequence_errs); + ocsd_dt_reset_decode_stats(dcdtree_handle, test_trc_id_override); + } + else + { + sprintf(packet_str, "Not available for this ID.\n"); + } + ocsd_def_errlog_msgout(packet_str); +} + int process_trace_data(FILE *pf) { ocsd_err_t ret = OCSD_OK; @@ -943,7 +976,9 @@ int process_trace_data(FILE *pf) if(ret == OCSD_OK) ocsd_dt_process_data(dcdtree_handle, OCSD_OP_EOT, 0,0,NULL,NULL);
- + if (stats) { + print_statistics(dcdtree_handle); + } /* shut down the mem acc CB if in use. */ if(using_mem_acc_cb) { diff --git a/decoder/tests/source/trc_pkt_lister.cpp b/decoder/tests/source/trc_pkt_lister.cpp index 6c8614e..2a54905 100644 --- a/decoder/tests/source/trc_pkt_lister.cpp +++ b/decoder/tests/source/trc_pkt_lister.cpp @@ -74,6 +74,7 @@ static bool dstream_format = false; static bool tpiu_format = false; static bool has_hsync = false; static bool src_addr_n = false; +static bool stats = false;
int main(int argc, char* argv[]) { @@ -195,6 +196,7 @@ void print_help() oss << "-o_raw_unpacked Output raw unpacked trace data per ID\n"; oss << "-test_waits <N> Force wait from packet printer for N packets - test the wait/flush mechanisms for the decoder\n"; oss << "-src_addr_n ETE protocol: Split source address ranges on N atoms\n"; + oss << "-stats Output packet processing statistics (if available).\n"; oss << "\nOutput:\n"; oss << " Setting any of these options cancels the default output to file & stdout,\n using _only_ the options supplied.\n\n"; oss << "-logstdout Output to stdout -> console.\n"; @@ -396,6 +398,10 @@ bool process_cmd_line_opts(int argc, char* argv[]) { src_addr_n = true; } + else if (strcmp(argv[optIdx], "-stats") == 0) + { + stats = true; + } else if((strcmp(argv[optIdx], "-help") == 0) || (strcmp(argv[optIdx], "--help") == 0) || (strcmp(argv[optIdx], "-h") == 0)) { print_help(); @@ -536,6 +542,34 @@ void ConfigureFrameDeMux(DecodeTree *dcd_tree, RawFramePrinter **framePrinter) } }
+void PrintDecodeStats(DecodeTree *dcd_tree) +{ + uint8_t elemID; + std::ostringstream oss; + ocsd_decode_stats_t *pStats = 0; + ocsd_err_t err; + + oss << "\nReading packet decoder statistics....\n\n"; + logger.LogMsg(oss.str()); + + DecodeTreeElement *pElement = dcd_tree->getFirstElement(elemID); + while (pElement) + { + oss.str(""); + err = dcd_tree->getDecoderStats(elemID, &pStats); + if (!err && pStats) + { + oss << "Decode stats ID 0x" << std::hex << (uint32_t)elemID << "\n"; + oss << "Total Bytes: " << std::dec << pStats->channel_total << "; Unsynced Bytes: " << std::dec << pStats->channel_unsynced << "\n"; + oss << "Bad Header Errors: " << std::dec << pStats->bad_header_errs << "; Bad Sequence Errors: " << std::dec << pStats->bad_sequence_errs << "\n"; + } + else + oss << "Decode stats unavailable on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; + logger.LogMsg(oss.str()); + pElement = dcd_tree->getNextElement(elemID); + } +} + void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader, const std::string &trace_buffer_name) { CreateDcdTreeFromSnapShot tree_creator; @@ -679,7 +713,8 @@ void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader std::ostringstream oss; oss << "Trace Packet Lister : Trace buffer done, processed " << trace_index << " bytes.\n"; logger.LogMsg(oss.str()); - + if (stats) + PrintDecodeStats(dcd_tree); } else {