forked from percepio/TraceRecorderSource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trcObject.c
297 lines (218 loc) · 7.88 KB
/
trcObject.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*
* Percepio Trace Recorder for Tracealyzer v4.6.3
* Copyright 2021 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* The implementation for strings.
*/
#include <trcRecorder.h>
#if (TRC_USE_TRACEALYZER_RECORDER == 1)
#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
#include <trcTypes.h>
#ifndef TRC_SEND_NAME_ONLY_ON_DELETE
#define TRC_SEND_NAME_ONLY_ON_DELETE 0
#endif
traceResult prvTraceObjectSendNameEvent(void* pvObject, const char* szName);
traceResult xTraceObjectRegisterInternal(uint32_t uiEventCode, void* pvObject, const char* szName, TraceUnsignedBaseType_t uxStateCount, TraceUnsignedBaseType_t uxStates[], TraceUnsignedBaseType_t uxOptions, TraceObjectHandle_t* pxObjectHandle)
{
TraceEntryHandle_t xEntryHandle;
TraceEventHandle_t xEventHandle = 0;
TraceUnsignedBaseType_t i;
TRACE_ALLOC_CRITICAL_SECTION();
/* This should never fail */
TRC_ASSERT(pxObjectHandle != 0);
/* This should never fail */
TRC_ASSERT(uxStateCount <= (TRC_ENTRY_TABLE_STATE_COUNT));
TRACE_ENTER_CRITICAL_SECTION();
if (pvObject != 0)
{
/* An address was supplied */
if (xTraceEntryCreateWithAddress(pvObject, &xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
}
else
{
/* No address was supplied */
if (xTraceEntryCreate(&xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetAddress(xEntryHandle, &pvObject) == TRC_SUCCESS);
}
for (i = 0; i < uxStateCount; i++)
{
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetState(xEntryHandle, i, uxStates[i]) == TRC_SUCCESS);
}
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetOptions(xEntryHandle, uxOptions) == TRC_SUCCESS);
*pxObjectHandle = (TraceObjectHandle_t)xEntryHandle;
TRACE_EXIT_CRITICAL_SECTION();
if (szName != 0 && szName[0] != 0)
{
/* Not a null or empty string */
/* This will set the symbol and create an event for it */
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceObjectSetName((TraceObjectHandle_t)xEntryHandle, szName) == TRC_SUCCESS);
}
/* Send the create event, if possible */
/*We need to check this */
if (xTraceEventBegin(uiEventCode, sizeof(void*) + uxStateCount * sizeof(TraceUnsignedBaseType_t), &xEventHandle) == TRC_SUCCESS)
{
xTraceEventAddPointer(xEventHandle, pvObject);
for (i = 0; i < uxStateCount; i++)
{
xTraceEventAddUnsignedBaseType(xEventHandle, uxStates[i]);
}
xTraceEventEnd(xEventHandle);
}
return TRC_SUCCESS;
}
traceResult xTraceObjectRegister(uint32_t uiEventCode, void *pvObject, const char* szName, TraceUnsignedBaseType_t uxState, TraceObjectHandle_t *pxObjectHandle)
{
return xTraceObjectRegisterInternal(uiEventCode, pvObject, szName, 1, &uxState, 0, pxObjectHandle);
}
traceResult xTraceObjectUnregister(TraceObjectHandle_t xObjectHandle, uint32_t uiEventCode, TraceUnsignedBaseType_t uxState)
{
void* pvObject = 0;
const char *szName = 0;
TraceEventHandle_t xEventHandle = 0;
/* If asserts are disabled this variable will not get used, this stops warnings. */
(void)szName;
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetAddress((TraceEntryHandle_t)xObjectHandle, &pvObject) == TRC_SUCCESS);
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetSymbol((TraceEntryHandle_t)xObjectHandle, &szName) == TRC_SUCCESS);
#if (TRC_SEND_NAME_ONLY_ON_DELETE == 1)
/* Send name event because this is a delete */
/* This should never fail */
TRC_ASSERT(prvTraceObjectSendNameEvent(pvObject, szName) == TRC_SUCCESS);
#endif /* (TRC_SEND_NAME_ONLY_ON_DELETE == 1) */
/* Send the delete event, if possible */
if (xTraceEventBegin(uiEventCode, sizeof(void*) + sizeof(TraceUnsignedBaseType_t), &xEventHandle) == TRC_SUCCESS)
{
xTraceEventAddPointer(xEventHandle, pvObject);
xTraceEventAddUnsignedBaseType(xEventHandle, uxState);
xTraceEventEnd(xEventHandle);
}
return xTraceEntryDelete(xObjectHandle);
}
traceResult xTraceObjectSetName(TraceObjectHandle_t xObjectHandle, const char* szName)
{
void* pvObject = 0;
/* If asserts are disabled this variable will not get used, this stops warnings. */
(void)pvObject;
if (szName == 0)
{
szName = "";
}
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetAddress((TraceEntryHandle_t)xObjectHandle, &pvObject) == TRC_SUCCESS);
#if (TRC_SEND_NAME_ONLY_ON_DELETE == 0)
/* Send name event now since we don't do it on delete events */
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(prvTraceObjectSendNameEvent(pvObject, szName) == TRC_SUCCESS);
#endif /* (TRC_SEND_NAME_ONLY_ON_DELETE == 0) */
return xTraceEntrySetSymbol((TraceEntryHandle_t)xObjectHandle, szName);
}
traceResult xTraceObjectRegisterWithoutHandle(uint32_t uiEventCode, void* pvObject, const char* szName, TraceUnsignedBaseType_t uxState)
{
TraceObjectHandle_t xObjectHandle;
return xTraceObjectRegister(uiEventCode, pvObject, szName, uxState, &xObjectHandle);
}
traceResult xTraceObjectUnregisterWithoutHandle(uint32_t uiEventCode, void* pvObject, TraceUnsignedBaseType_t uxState)
{
TraceEntryHandle_t xEntryHandle;
traceResult xResult;
TRACE_ALLOC_CRITICAL_SECTION();
TRACE_ENTER_CRITICAL_SECTION();
if (xTraceEntryFind(pvObject, &xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
xResult = xTraceObjectUnregister((TraceObjectHandle_t)xEntryHandle, uiEventCode, uxState);
TRACE_EXIT_CRITICAL_SECTION();
return xResult;
}
traceResult xTraceObjectSetNameWithoutHandle(void* pvObject, const char* szName)
{
TraceEntryHandle_t xEntryHandle;
traceResult xResult;
TRACE_ALLOC_CRITICAL_SECTION();
TRACE_ENTER_CRITICAL_SECTION();
if (xTraceEntryFind(pvObject, &xEntryHandle) == TRC_FAIL)
{
/* No previous entry found. Create one. */
if (xTraceEntryCreateWithAddress(pvObject, &xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
}
xResult = xTraceObjectSetName((TraceObjectHandle_t)xEntryHandle, szName);
TRACE_EXIT_CRITICAL_SECTION();
return xResult;
}
traceResult xTraceObjectSetSpecificStateWithoutHandle(void* pvObject, uint32_t uiIndex, TraceUnsignedBaseType_t uxState)
{
TraceEntryHandle_t xEntryHandle;
traceResult xResult;
TRACE_ALLOC_CRITICAL_SECTION();
TRACE_ENTER_CRITICAL_SECTION();
if (xTraceEntryFind(pvObject, &xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
xResult = xTraceObjectSetSpecificState((TraceObjectHandle_t)xEntryHandle, uiIndex, uxState);
TRACE_EXIT_CRITICAL_SECTION();
return xResult;
}
traceResult xTraceObjectSetOptionsWithoutHandle(void* pvObject, uint32_t uiMask)
{
TraceEntryHandle_t xEntryHandle;
traceResult xResult;
TRACE_ALLOC_CRITICAL_SECTION();
TRACE_ENTER_CRITICAL_SECTION();
if (xTraceEntryFind(pvObject, &xEntryHandle) == TRC_FAIL)
{
/* No previous entry found. Create one. */
if (xTraceEntryCreateWithAddress(pvObject, &xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
}
xResult = xTraceObjectSetOptions((TraceObjectHandle_t)xEntryHandle, uiMask);
TRACE_EXIT_CRITICAL_SECTION();
return xResult;
}
traceResult prvTraceObjectSendNameEvent(void* pvObject, const char* szName)
{
uint32_t i = 0, uiLength = 0, uiValue = 0;
TraceEventHandle_t xEventHandle = 0;
for (i = 0; (szName[i] != 0) && (i < (TRC_ENTRY_TABLE_SLOT_SYMBOL_SIZE)); i++) {}
uiLength = i;
if (xTraceEventBegin(PSF_EVENT_OBJ_NAME, sizeof(void*) + uiLength, &xEventHandle) == TRC_SUCCESS)
{
xTraceEventAddPointer(xEventHandle, pvObject);
xTraceEventAddData(xEventHandle, (void*)szName, uiLength);
/* Check if we can truncate */
xTraceEventPayloadRemaining(xEventHandle, &uiValue);
if (uiValue > 0)
{
xTraceEventAdd8(xEventHandle, 0);
}
xTraceEventEnd(xEventHandle);
}
return TRC_SUCCESS;
}
#endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
#endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */