forked from zephyrproject-rtos/TraceRecorderSource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trcDiagnostics.c
159 lines (118 loc) · 4.26 KB
/
trcDiagnostics.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
/*
* Trace Recorder for Tracealyzer v4.8.0.hotfix2
* Copyright 2023 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* The implementation of the diagnostics.
*/
#include <trcRecorder.h>
#if (TRC_USE_TRACEALYZER_RECORDER == 1)
#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
static TraceDiagnosticsData_t *pxDiagnostics TRC_CFG_RECORDER_DATA_ATTRIBUTE;
traceResult xTraceDiagnosticsInitialize(TraceDiagnosticsData_t *pxBuffer)
{
uint32_t i;
/* This should never fail */
TRC_ASSERT(pxBuffer != (void*)0);
pxDiagnostics = pxBuffer;
for (i = 0u; i < (TRC_DIAGNOSTICS_COUNT); i++)
{
pxDiagnostics->metrics[i] = 0;
}
xTraceSetComponentInitialized(TRC_RECORDER_COMPONENT_DIAGNOSTICS);
return TRC_SUCCESS;
}
traceResult xTraceDiagnosticsGet(TraceDiagnosticsType_t xType, TraceBaseType_t* pxValue)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_DIAGNOSTICS));
/* This should never fail */
TRC_ASSERT((TraceUnsignedBaseType_t)xType < TRC_DIAGNOSTICS_COUNT);
/* This should never fail */
TRC_ASSERT(pxValue != (void*)0);
*pxValue = pxDiagnostics->metrics[(TraceUnsignedBaseType_t)xType];
return TRC_SUCCESS;
}
traceResult xTraceDiagnosticsSet(TraceDiagnosticsType_t xType, TraceBaseType_t xValue)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_DIAGNOSTICS));
/* This should never fail */
TRC_ASSERT((TraceUnsignedBaseType_t)xType < TRC_DIAGNOSTICS_COUNT);
pxDiagnostics->metrics[(TraceUnsignedBaseType_t)xType] = xValue;
return TRC_SUCCESS;
}
traceResult xTraceDiagnosticsAdd(TraceDiagnosticsType_t xType, TraceBaseType_t xValue)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_DIAGNOSTICS));
/* This should never fail */
TRC_ASSERT((TraceUnsignedBaseType_t)xType < TRC_DIAGNOSTICS_COUNT);
pxDiagnostics->metrics[(TraceUnsignedBaseType_t)xType] += xValue;
return TRC_SUCCESS;
}
traceResult xTraceDiagnosticsIncrease(TraceDiagnosticsType_t xType)
{
return xTraceDiagnosticsAdd(xType, 1);
}
traceResult xTraceDiagnosticsDecrease(TraceDiagnosticsType_t xType)
{
return xTraceDiagnosticsAdd(xType, -1);
}
traceResult xTraceDiagnosticsSetIfHigher(TraceDiagnosticsType_t xType, TraceBaseType_t xValue)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_DIAGNOSTICS));
/* This should never fail */
TRC_ASSERT((TraceUnsignedBaseType_t)xType < TRC_DIAGNOSTICS_COUNT);
if (xValue > pxDiagnostics->metrics[xType])
{
pxDiagnostics->metrics[(TraceUnsignedBaseType_t)xType] = xValue;
}
return TRC_SUCCESS;
}
traceResult xTraceDiagnosticsSetIfLower(TraceDiagnosticsType_t xType, TraceBaseType_t xValue)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_DIAGNOSTICS));
/* This should never fail */
TRC_ASSERT((TraceUnsignedBaseType_t)xType < TRC_DIAGNOSTICS_COUNT);
if (xValue < pxDiagnostics->metrics[(TraceUnsignedBaseType_t)xType])
{
pxDiagnostics->metrics[(TraceUnsignedBaseType_t)xType] = xValue;
}
return TRC_SUCCESS;
}
traceResult xTraceDiagnosticsCheckStatus(void)
{
/* It is probably good if we always check this */
if (xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_DIAGNOSTICS) == 0U)
{
return TRC_FAIL;
}
if (pxDiagnostics->metrics[TRC_DIAGNOSTICS_ENTRY_SLOTS_NO_ROOM] > 0)
{
(void)xTraceWarning(TRC_WARNING_ENTRY_TABLE_SLOTS);
pxDiagnostics->metrics[TRC_DIAGNOSTICS_ENTRY_SLOTS_NO_ROOM] = 0;
}
if (pxDiagnostics->metrics[TRC_DIAGNOSTICS_ENTRY_SYMBOL_LONGEST_LENGTH] > (TRC_CFG_ENTRY_SYMBOL_MAX_LENGTH))
{
(void)xTraceWarning(TRC_WARNING_ENTRY_SYMBOL_MAX_LENGTH);
pxDiagnostics->metrics[TRC_DIAGNOSTICS_ENTRY_SYMBOL_LONGEST_LENGTH] = 0;
}
if (pxDiagnostics->metrics[TRC_DIAGNOSTICS_BLOB_MAX_BYTES_TRUNCATED] > 0)
{
(void)xTraceWarning(TRC_WARNING_EVENT_SIZE_TRUNCATED);
pxDiagnostics->metrics[TRC_DIAGNOSTICS_BLOB_MAX_BYTES_TRUNCATED] = 0;
}
if (pxDiagnostics->metrics[TRC_DIAGNOSTICS_STACK_MONITOR_NO_SLOTS] > 0)
{
(void)xTraceWarning(TRC_WARNING_STACKMON_NO_SLOTS);
pxDiagnostics->metrics[TRC_DIAGNOSTICS_STACK_MONITOR_NO_SLOTS] = 0;
}
return TRC_SUCCESS;
}
#endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
#endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */