1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 #include "platform_trace.h"
31 #include "hdf_base.h"
32 #include "hdf_log.h"
33 #include "los_trace.h"
34
PlatformTraceStart(void)35 int32_t PlatformTraceStart(void)
36 {
37 #ifdef LOSCFG_KERNEL_TRACE
38 uint32_t ret;
39 ret = LOS_TraceStart();
40 if (ret != LOS_OK) {
41 HDF_LOGE("PlatformTraceStart error:%d", ret);
42 return HDF_FAILURE;
43 }
44 #endif
45 return HDF_SUCCESS;
46 }
47
PlatformTraceStop(void)48 int32_t PlatformTraceStop(void)
49 {
50 #ifdef LOSCFG_KERNEL_TRACE
51 LOS_TraceStop();
52 #endif
53 return HDF_SUCCESS;
54 }
55
PlatformTraceReset(void)56 void PlatformTraceReset(void)
57 {
58 #ifdef LOSCFG_KERNEL_TRACE
59 LOS_TraceReset();
60 #endif
61 }
62
63 #ifdef LOSCFG_KERNEL_TRACE
TraceMeanPrint(void)64 static void TraceMeanPrint(void)
65 {
66 uint32_t i = 0;
67 dprintf("********trace moudle and function explain:********\t");
68 const struct PlatformTraceModuleExplain *explains = PlatformTraceModuleExplainGetAll();
69 int32_t size = PlatformTraceModuleExplainCount();
70 for (i = 0; i < size; i++) {
71 if (explains[i].moduleInfo < PLATFORM_TRACE_MODULE_MAX) {
72 dprintf("meaning of module num 0x%x is %s\t", explains[i].moduleInfo, explains[i].moduleMean);
73 } else if (explains[i].moduleInfo > PLATFORM_TRACE_MODULE_MAX) {
74 dprintf("meaning of function num 0x%x is %s\t", explains[i].moduleInfo, explains[i].moduleMean);
75 }
76 }
77 }
78 #endif
79
PlatformTraceInfoDump(void)80 void PlatformTraceInfoDump(void)
81 {
82 #ifdef LOSCFG_KERNEL_TRACE
83 TraceMeanPrint();
84 LOS_TraceRecordDump(FALSE);
85 #endif
86 }
87
88 #define PLATFORM_TRACE_IDENTIFY 0x33
PlatformTraceAddUintMsg(int module,int moduleFun,const unsigned int infos[],uint8_t size)89 void PlatformTraceAddUintMsg(int module, int moduleFun, const unsigned int infos[], uint8_t size)
90 {
91 #ifdef LOSCFG_KERNEL_TRACE
92 if ((size == 0) || (size > PLATFORM_TRACE_UINT_PARAM_SIZE_MAX)) {
93 HDF_LOGE("PlatformTraceAddUintMsg %hhu size illegal", size);
94 return;
95 }
96 if ((module < PLATFORM_TRACE_MODULE_I2S) || (module >= PLATFORM_TRACE_MODULE_MAX)) {
97 HDF_LOGE("PlatformTraceAddUintMsg %d module illegal", module);
98 return;
99 }
100 if ((moduleFun < PLATFORM_TRACE_MODULE_I2S_FUN) || (moduleFun >= PLATFORM_TRACE_MODULE_MAX_FUN)) {
101 HDF_LOGE("PlatformTraceAddUintMsg %d moduleFun illegal", moduleFun);
102 return;
103 }
104
105 switch (size) {
106 case PLATFORM_TRACE_UINT_PARAM_SIZE_1:
107 LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun,
108 infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1]);
109 break;
110 case PLATFORM_TRACE_UINT_PARAM_SIZE_2:
111 LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun,
112 infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1]);
113 break;
114 case PLATFORM_TRACE_UINT_PARAM_SIZE_3:
115 LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun,
116 infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1],
117 infos[PLATFORM_TRACE_UINT_PARAM_SIZE_3 - 1]);
118 break;
119 case PLATFORM_TRACE_UINT_PARAM_SIZE_4:
120 LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun,
121 infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1],
122 infos[PLATFORM_TRACE_UINT_PARAM_SIZE_3 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_4 - 1]);
123 break;
124 case PLATFORM_TRACE_UINT_PARAM_SIZE_MAX:
125 LOS_TRACE_EASY(TRACE_SYS_FLAG, PLATFORM_TRACE_IDENTIFY, module, moduleFun,
126 infos[PLATFORM_TRACE_UINT_PARAM_SIZE_1 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_2 - 1],
127 infos[PLATFORM_TRACE_UINT_PARAM_SIZE_3 - 1], infos[PLATFORM_TRACE_UINT_PARAM_SIZE_4 - 1],
128 infos[PLATFORM_TRACE_UINT_PARAM_SIZE_MAX - 1]);
129 break;
130 default:
131 HDF_LOGE("PlatformTraceAddUintMsg %hhu size illegal", size);
132 break;
133 }
134 #endif
135 }
136
PlatformTraceAddMsg(const char * module,const char * moduleFun,const char * fmt,...)137 void PlatformTraceAddMsg(const char *module, const char *moduleFun, const char *fmt, ...)
138 {
139 // not support, return
140 (void)module;
141 (void)moduleFun;
142 (void)fmt;
143 return;
144 }
145