1 /*
2 * \file gen_elem_printer.cpp
3 * \brief OpenCSD : Generic element printer class.
4 *
5 * \copyright Copyright (c) 2015,2023 ARM Limited. All Rights Reserved.
6 */
7
8 /*
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of the copyright holder nor the names of its contributors
20 * may be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <string>
36 #include <sstream>
37 #include <iomanip>
38
39 #include "opencsd.h"
40
TrcGenericElementPrinter()41 TrcGenericElementPrinter::TrcGenericElementPrinter() :
42 m_needWaitAck(false),
43 m_collect_stats(false)
44 {
45 for (int i = 0; i <= (int)OCSD_GEN_TRC_ELEM_CUSTOM; i++)
46 m_packet_counts[i] = 0;
47 }
48
TraceElemIn(const ocsd_trc_index_t index_sop,const uint8_t trc_chan_id,const OcsdTraceElement & elem)49 ocsd_datapath_resp_t TrcGenericElementPrinter::TraceElemIn(const ocsd_trc_index_t index_sop,
50 const uint8_t trc_chan_id,
51 const OcsdTraceElement& elem)
52 {
53 ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
54
55 if (m_collect_stats)
56 m_packet_counts[(int)elem.getType()]++;
57
58 if (is_muted())
59 return resp;
60
61 std::string elemStr;
62 std::ostringstream oss;
63 oss << "Idx:" << index_sop << "; ID:" << std::hex << (uint32_t)trc_chan_id << "; ";
64 elem.toString(elemStr);
65 oss << elemStr << std::endl;
66 itemPrintLine(oss.str());
67
68 // funtionality to test wait / flush mechanism
69 if (m_needWaitAck)
70 {
71 oss.str("");
72 oss << "WARNING: Generic Element Printer; New element without previous _WAIT acknowledged\n";
73 itemPrintLine(oss.str());
74 m_needWaitAck = false;
75 }
76
77 if (getTestWaits())
78 {
79 resp = OCSD_RESP_WAIT; // return _WAIT for the 1st N packets.
80 decTestWaits();
81 m_needWaitAck = true;
82 }
83 return resp;
84 }
85
printStats()86 void TrcGenericElementPrinter::printStats()
87 {
88 static const char* gen_elem_packet_names[] = {
89 "OCSD_GEN_TRC_ELEM_UNKNOWN",
90 "OCSD_GEN_TRC_ELEM_NO_SYNC",
91 "OCSD_GEN_TRC_ELEM_TRACE_ON",
92 "OCSD_GEN_TRC_ELEM_EO_TRACE",
93 "OCSD_GEN_TRC_ELEM_PE_CONTEXT",
94 "OCSD_GEN_TRC_ELEM_INSTR_RANGE",
95 "OCSD_GEN_TRC_ELEM_I_RANGE_NOPATH",
96 "OCSD_GEN_TRC_ELEM_ADDR_NACC",
97 "OCSD_GEN_TRC_ELEM_ADDR_UNKNOWN",
98 "OCSD_GEN_TRC_ELEM_EXCEPTION",
99 "OCSD_GEN_TRC_ELEM_EXCEPTION_RET",
100 "OCSD_GEN_TRC_ELEM_TIMESTAMP",
101 "OCSD_GEN_TRC_ELEM_CYCLE_COUNT",
102 "OCSD_GEN_TRC_ELEM_EVENT",
103 "OCSD_GEN_TRC_ELEM_SWTRACE",
104 "OCSD_GEN_TRC_ELEM_SYNC_MARKER",
105 "OCSD_GEN_TRC_ELEM_MEMTRANS",
106 "OCSD_GEN_TRC_ELEM_INSTRUMENTATION",
107 "OCSD_GEN_TRC_ELEM_CUSTOM",
108 };
109
110 std::ostringstream oss;
111
112 oss << "Generic Packets processed:-\n";
113 for (int i = 0; i <= OCSD_GEN_TRC_ELEM_CUSTOM; i++)
114 {
115 oss << gen_elem_packet_names[i] << " : " << m_packet_counts[i] << "\n";
116 }
117 oss << "\n\n";
118
119 itemPrintLine(oss.str());
120 }
121
122
123