From a25eca761b1c84e15876b0da82cb073f7ef5aec6 Mon Sep 17 00:00:00 2001 From: Mike Leach Date: Thu, 17 Aug 2023 14:00:54 +0100 Subject: opencsd: test: add test mode to trc_pkt_lister to mute output Add option to mute printed output to allow tests of library performance Signed-off-by: Mike Leach --- decoder/build/linux/ref_trace_decode_lib/makefile | 3 +- .../ref_trace_decode_lib.vcxproj | 1 + .../ref_trace_decode_lib.vcxproj.filters | 3 + decoder/include/pkt_printers/gen_elem_printer.h | 40 +------ decoder/include/pkt_printers/item_printer.h | 19 +++- decoder/include/pkt_printers/pkt_printer_t.h | 6 + decoder/source/pkt_printers/gen_elem_printer.cpp | 122 +++++++++++++++++++++ decoder/source/pkt_printers/raw_frame_printer.cpp | 3 + decoder/tests/source/trc_pkt_lister.cpp | 17 +++ 9 files changed, 176 insertions(+), 38 deletions(-) create mode 100644 decoder/source/pkt_printers/gen_elem_printer.cpp diff --git a/decoder/build/linux/ref_trace_decode_lib/makefile b/decoder/build/linux/ref_trace_decode_lib/makefile index 58d5c6e..3cdfcfd 100644 --- a/decoder/build/linux/ref_trace_decode_lib/makefile +++ b/decoder/build/linux/ref_trace_decode_lib/makefile @@ -86,7 +86,8 @@ STMOBJ= $(BUILD_DIR)/trc_pkt_elem_stm.o \ $(BUILD_DIR)/trc_pkt_decode_stm.o PKTPRNTOBJ= $(BUILD_DIR)/raw_frame_printer.o \ - $(BUILD_DIR)/trc_print_fact.o + $(BUILD_DIR)/trc_print_fact.o \ + $(BUILD_DIR)/gen_elem_printer.o OBJECTS=$(BUILD_DIR)/ocsd_code_follower.o \ diff --git a/decoder/build/win-vs2022/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj b/decoder/build/win-vs2022/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj index 13d34ab..30724aa 100644 --- a/decoder/build/win-vs2022/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj +++ b/decoder/build/win-vs2022/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj @@ -440,6 +440,7 @@ + diff --git a/decoder/build/win-vs2022/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters b/decoder/build/win-vs2022/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters index 47e9a3a..4ec5327 100644 --- a/decoder/build/win-vs2022/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters +++ b/decoder/build/win-vs2022/ref_trace_decode_lib/ref_trace_decode_lib.vcxproj.filters @@ -511,5 +511,8 @@ Source Files\ete + + Source Files\pkt_printers + \ No newline at end of file diff --git a/decoder/include/pkt_printers/gen_elem_printer.h b/decoder/include/pkt_printers/gen_elem_printer.h index ba3138a..c3fe3aa 100644 --- a/decoder/include/pkt_printers/gen_elem_printer.h +++ b/decoder/include/pkt_printers/gen_elem_printer.h @@ -49,47 +49,15 @@ public: // funtionality to test wait / flush mechanism void ackWait() { m_needWaitAck = false; }; const bool needAckWait() const { return m_needWaitAck; }; + void set_collect_stats() { m_collect_stats = true; }; + void printStats(); protected: bool m_needWaitAck; + bool m_collect_stats; // collect stats on packets processed + int m_packet_counts[(int)OCSD_GEN_TRC_ELEM_CUSTOM + 1]; }; - -inline TrcGenericElementPrinter::TrcGenericElementPrinter() : - m_needWaitAck(false) -{ -} - -inline ocsd_datapath_resp_t TrcGenericElementPrinter::TraceElemIn(const ocsd_trc_index_t index_sop, - const uint8_t trc_chan_id, - const OcsdTraceElement &elem) -{ - ocsd_datapath_resp_t resp = OCSD_RESP_CONT; - std::string elemStr; - std::ostringstream oss; - oss << "Idx:" << index_sop << "; ID:"<< std::hex << (uint32_t)trc_chan_id << "; "; - elem.toString(elemStr); - oss << elemStr << std::endl; - itemPrintLine(oss.str()); - - // funtionality to test wait / flush mechanism - if(m_needWaitAck) - { - oss.str(""); - oss << "WARNING: Generic Element Printer; New element without previous _WAIT acknowledged\n"; - itemPrintLine(oss.str()); - m_needWaitAck = false; - } - - if(getTestWaits()) - { - resp = OCSD_RESP_WAIT; // return _WAIT for the 1st N packets. - decTestWaits(); - m_needWaitAck = true; - } - return resp; -} - #endif // ARM_GEN_ELEM_PRINTER_H_INCLUDED /* End of File gen_elem_printer.h */ diff --git a/decoder/include/pkt_printers/item_printer.h b/decoder/include/pkt_printers/item_printer.h index cc3ec37..0f1feeb 100644 --- a/decoder/include/pkt_printers/item_printer.h +++ b/decoder/include/pkt_printers/item_printer.h @@ -52,14 +52,21 @@ public: const int getTestWaits() const; void decTestWaits(); + // mute printers when profiling + void setMute(bool mute); + const bool is_muted() const; + + protected: ocsdMsgLogger *m_pMsgLogger; int m_test_waits; + bool m_mute; }; inline ItemPrinter::ItemPrinter() : m_pMsgLogger(0), - m_test_waits(0) + m_test_waits(0), + m_mute(false) { } @@ -89,6 +96,16 @@ inline void ItemPrinter::decTestWaits() m_test_waits--; } +inline void ItemPrinter::setMute(bool mute) +{ + m_mute = mute; +} + +inline const bool ItemPrinter::is_muted() const +{ + return m_mute; +} + #endif // ARM_ITEM_PRINTER_H_INCLUDED /* End of File item_printer.h */ diff --git a/decoder/include/pkt_printers/pkt_printer_t.h b/decoder/include/pkt_printers/pkt_printer_t.h index c00daa1..f2d3e09 100644 --- a/decoder/include/pkt_printers/pkt_printer_t.h +++ b/decoder/include/pkt_printers/pkt_printer_t.h @@ -97,6 +97,9 @@ template ocsd_datapath_resp_t PacketPrinter

::PacketDataIn( const ocs { std::string pktstr; ocsd_datapath_resp_t resp = OCSD_RESP_CONT; + + if (is_muted()) + return resp; // wait / flush test verification if(!m_bRawPrint && (m_last_resp == OCSD_RESP_WAIT)) @@ -152,6 +155,9 @@ template void PacketPrinter

::RawPacketDataMon( const ocsd_datapath_o const uint32_t size, const uint8_t *p_data) { + if (is_muted()) + return; + switch(op) { case OCSD_OP_DATA: diff --git a/decoder/source/pkt_printers/gen_elem_printer.cpp b/decoder/source/pkt_printers/gen_elem_printer.cpp new file mode 100644 index 0000000..ffd9a2d --- /dev/null +++ b/decoder/source/pkt_printers/gen_elem_printer.cpp @@ -0,0 +1,122 @@ +/* + * \file gen_elem_printer.cpp + * \brief OpenCSD : Generic element printer class. + * + * \copyright Copyright (c) 2015,2023 ARM Limited. All Rights Reserved. + */ + + /* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "opencsd.h" + +TrcGenericElementPrinter::TrcGenericElementPrinter() : + m_needWaitAck(false), + m_collect_stats(false) +{ + for (int i = 0; i <= (int)OCSD_GEN_TRC_ELEM_CUSTOM; i++) + m_packet_counts[i] = 0; +} + +ocsd_datapath_resp_t TrcGenericElementPrinter::TraceElemIn(const ocsd_trc_index_t index_sop, + const uint8_t trc_chan_id, + const OcsdTraceElement& elem) +{ + ocsd_datapath_resp_t resp = OCSD_RESP_CONT; + + if (m_collect_stats) + m_packet_counts[(int)elem.getType()]++; + + if (is_muted()) + return resp; + + std::string elemStr; + std::ostringstream oss; + oss << "Idx:" << index_sop << "; ID:" << std::hex << (uint32_t)trc_chan_id << "; "; + elem.toString(elemStr); + oss << elemStr << std::endl; + itemPrintLine(oss.str()); + + // funtionality to test wait / flush mechanism + if (m_needWaitAck) + { + oss.str(""); + oss << "WARNING: Generic Element Printer; New element without previous _WAIT acknowledged\n"; + itemPrintLine(oss.str()); + m_needWaitAck = false; + } + + if (getTestWaits()) + { + resp = OCSD_RESP_WAIT; // return _WAIT for the 1st N packets. + decTestWaits(); + m_needWaitAck = true; + } + return resp; +} + +void TrcGenericElementPrinter::printStats() +{ + static const char* gen_elem_packet_names[] = { + "OCSD_GEN_TRC_ELEM_UNKNOWN", + "OCSD_GEN_TRC_ELEM_NO_SYNC", + "OCSD_GEN_TRC_ELEM_TRACE_ON", + "OCSD_GEN_TRC_ELEM_EO_TRACE", + "OCSD_GEN_TRC_ELEM_PE_CONTEXT", + "OCSD_GEN_TRC_ELEM_INSTR_RANGE", + "OCSD_GEN_TRC_ELEM_I_RANGE_NOPATH", + "OCSD_GEN_TRC_ELEM_ADDR_NACC", + "OCSD_GEN_TRC_ELEM_ADDR_UNKNOWN", + "OCSD_GEN_TRC_ELEM_EXCEPTION", + "OCSD_GEN_TRC_ELEM_EXCEPTION_RET", + "OCSD_GEN_TRC_ELEM_TIMESTAMP", + "OCSD_GEN_TRC_ELEM_CYCLE_COUNT", + "OCSD_GEN_TRC_ELEM_EVENT", + "OCSD_GEN_TRC_ELEM_SWTRACE", + "OCSD_GEN_TRC_ELEM_SYNC_MARKER", + "OCSD_GEN_TRC_ELEM_MEMTRANS", + "OCSD_GEN_TRC_ELEM_INSTRUMENTATION", + "OCSD_GEN_TRC_ELEM_CUSTOM", + }; + + std::ostringstream oss; + + oss << "Generic Packets processed:-\n"; + for (int i = 0; i <= OCSD_GEN_TRC_ELEM_CUSTOM; i++) + { + oss << gen_elem_packet_names[i] << " : " << m_packet_counts[i] << "\n"; + } + oss << "\n\n"; + + itemPrintLine(oss.str()); +} + + diff --git a/decoder/source/pkt_printers/raw_frame_printer.cpp b/decoder/source/pkt_printers/raw_frame_printer.cpp index 7ac2ddf..421d88d 100644 --- a/decoder/source/pkt_printers/raw_frame_printer.cpp +++ b/decoder/source/pkt_printers/raw_frame_printer.cpp @@ -47,6 +47,9 @@ ocsd_err_t RawFramePrinter::TraceRawFrameIn( const ocsd_datapath_op_t op, const uint8_t traceID) { + if (is_muted()) + return OCSD_OK; + if(op == OCSD_OP_DATA) // only interested in actual frame data. { std::string strData; diff --git a/decoder/tests/source/trc_pkt_lister.cpp b/decoder/tests/source/trc_pkt_lister.cpp index 9760351..83f8b85 100644 --- a/decoder/tests/source/trc_pkt_lister.cpp +++ b/decoder/tests/source/trc_pkt_lister.cpp @@ -75,6 +75,7 @@ static bool tpiu_format = false; static bool has_hsync = false; static bool src_addr_n = false; static bool stats = false; +static bool profile = false; int main(int argc, char* argv[]) { @@ -197,6 +198,7 @@ void print_help() oss << "-test_waits 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 << "-profile Mute logging output while profiling library performance\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"; @@ -432,6 +434,10 @@ bool process_cmd_line_opts(int argc, char* argv[]) has_hsync = true; tpiu_format = true; } + else if (strcmp(argv[optIdx], "-profile") == 0) + { + profile = true; + } else { std::ostringstream errstr; @@ -505,6 +511,8 @@ void AttachPacketPrinters( DecodeTree *dcd_tree) else oss << "Trace Packet Lister : Failed to Protocol printer " << pElement->getDecoderTypeName() << " on Trace ID 0x" << std::hex << (uint32_t)elemID << "\n"; logger.LogMsg(oss.str()); + if (profile) + pPrinter->setMute(true); } pElement = dcd_tree->getNextElement(elemID); @@ -613,6 +621,8 @@ void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader AttachPacketPrinters(dcd_tree); ConfigureFrameDeMux(dcd_tree, &framePrinter); + if (profile && framePrinter) + framePrinter->setMute(true); // if decoding set the generic element printer to the output interface on the tree. if(decode) @@ -623,6 +633,11 @@ void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader oss << "Trace Packet Lister : Set trace element decode printer\n"; logger.LogMsg(oss.str()); genElemPrinter->setTestWaits(test_waits); + if (profile) + { + genElemPrinter->setMute(true); + genElemPrinter->set_collect_stats(); + } } if(decode) @@ -741,6 +756,8 @@ void ListTracePackets(ocsdDefaultErrorLogger &err_logger, SnapShotReader &reader logger.LogMsg(oss.str()); if (stats) PrintDecodeStats(dcd_tree); + if (profile) + genElemPrinter->printStats(); } else { -- cgit v1.2.3