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 import xdc.runtime.Types;
37 import xdc.runtime.Diags;
38 import ti.uia.events.IUIACtx;
39
40 /*!
41 * UIA Channel Context Instrumentation
42 *
43 * The UIAChanCtx module defines context change events
44 * and methods that allow tooling to identify channel context
45 * switches and to enable channel-aware filtering, trace and
46 * analysis.
47 *
48 * It inherits IUIACtx, which defines a function pointer to
49 * an isLoggingEnabled function which, if configured to point to
50 * a function, will evaluate the function prior to logging the context
51 * change event and will determine whether to log the event based on the
52 * return value of the function. If the function is not configured,
53 * logging will be conditional upon ti_uia_runtime_CtxFilter_gIsLoggingEnabled.
54 *
55 * The generation of UIAChanCtx events is also controlled by a module's diagnostics
56 * mask, which is described in details in `{@link xdc.runtime.Diags}`.
57 * UIAChanCtx` events are generated only when the Diags.ANALYSIS bit is set
58 * in the module's diagnostics mask.
59 *
60 * The following configuration script demonstrates how the application might
61 * control the logging of ANALYSIS events embedded in the `Mod` module at configuration
62 * time. In this case, the configuration script arranges for the `Log`
63 * statements within modules to always generate ANALYSIS events.
64 * Without these configuration statements, no ANALYSIS events would be generated
65 * by any modules.
66 *
67 * @a(Examples)
68 * Example 1: This is part of the XDC configuration file for the application:
69 *
70 * @p(code)
71 * var LogCtxChg = xdc.useModule('ti.uia.runtime.LogCtxChg');
72 * var Diags = xdc.useModule('xdc.runtime.Diags');
73 * var LoggerSys = xdc.useModule('xdc.runtime.LoggerSys');
74 * var Defaults = xdc.useModule('xdc.runtime.Defaults');
75 * var logger = LoggerSys.create();
76 *
77 * Defaults.common$.diags_ANALYSIS = Diags.ALWAYS_ON;
78 * Defaults.common$.logger = logger;
79 * @p
80 *
81 * @p(html)
82 * <hr />
83 * @p
84 *
85 * Example 2: The following example configures a module to support logging
86 * of ANALYSIS events, but defers the actual activation and deactivation of the
87 * logging until runtime. See the `{@link Diags#setMask Diags_setMask()}`
88 * function for details on specifying the control string.
89 *
90 * This is a part of the XDC configuration file for the application:
91 *
92 * @p(code)
93 * var LogCtxChg = xdc.useModule('ti.uia.runtime.LogCtxChg');
94 * var Diags = xdc.useModule('xdc.runtime.Diags');
95 * var Mod = xdc.useModule('my.pkg.Mod');
96 *
97 * Mod.common$.diags_ANALYSIS = Diags.RUNTIME_OFF;
98 * @p
99 *
100 * This is a part of the C code for the application:
101 *
102 * @p(code)
103 * // turn on logging of ANALYSIS events in the module
104 * Diags_setMask("my.pkg.Mod+Z");
105 *
106 * // turn off logging of ANALYSIS events in the module
107 * Diags_setMask("my.pkg.Mod-Z");
108 * @p
109 */
110 @CustomHeader
111 module UIAChanCtx inherits IUIACtx {
112
113
114 /*!
115 * ======== ctxChg ========
116 * Channel Context Change event
117 *
118 * Used to log the start of a new channel
119 * Note that the previous channel Id is logged automatically by the ti_uia_runtime_LogCtxChg_thread
120 * API.
121 *
122 * @a(Example)
123 * The following C code shows how to log a Context Change
124 * event that identifies a new channel ID
125 *
126 * @p(code)
127 * #include <ti/uia/runtime/LogCtxChg.h>
128 * ...
129 * Void processChannel(Int chanId){
130 * ...
131 * LogCtxChg_channel("New chan ID=0x%x",chanId);
132 * ...
133 * }
134 * @p
135 * This event prints the Log call site (%$F) and a format string (%$S)
136 * which is recursively formatted with any addition arguments.
137 * The following text is an example of what will be displayed for the event:
138 * @p(code)
139 * "Channel Ctx Change at Line 123 in demo.c [Prev. chan ID=0x1234] New chan ID=0x1235"
140 *
141 * @param(fmt) a constant string that describes the context change and provides a format specifier for newAppId
142 * @param(newChanId) an integer which uniquely identifies the new context
143 */
144 config xdc.runtime.Log.Event ctxChg = {
145 mask: Diags.ANALYSIS,
146 msg: "Channel Ctx Change at %$F [Prev. chan ID=0x%x] %$S"};
147
148 /*!
149 * ======== metaEventChanCtxChg ========
150 * Metadata description of the Channel Context Change event
151 *
152 * @_nodoc
153 */
154 metaonly config DvtTypes.MetaEventDescriptor metaEventChanCtxChg = {
155 versionId: "2.0",
156 analysisType: DvtTypes.DvtAnalysisType_CONTEXTCHANGE,
157 displayText: "Channel Ctx Change",
158 tooltipText: "Channel ID Context Change",
159 numParameters: 5,
160 paramInfo: [
161 { name: '__FILE__',
162 dataDesc: DvtTypes.DvtDataDesc_FILENAMESTR,
163 dataTypeName: 'String',
164 units: 'none',
165 isHidden: false
166 },
167 { name: '__LINE__',
168 dataDesc: DvtTypes.DvtDataDesc_LINENUM,
169 dataTypeName: 'Int',
170 units: 'none',
171 isHidden: false
172 },
173 { name: 'Prev. Chan ID',
174 dataDesc: DvtTypes.DvtDataDesc_CHANNELID,
175 dataTypeName: 'Int',
176 units: 'none',
177 isHidden: false
178 },
179 { name: 'fmt',
180 dataDesc: DvtTypes.DvtDataDesc_FMTSTR,
181 dataTypeName: 'String',
182 units: 'none',
183 isHidden: false
184 },
185 { name: 'New Chan ID',
186 dataDesc: DvtTypes.DvtDataDesc_CHANNELID,
187 dataTypeName: 'Int',
188 units: 'none',
189 isHidden: false
190 }]
191
192 };
193 /*!
194 * ======== getCtxId ========
195 * Get the ID for the current channel
196 *
197 * @a(returns)
198 * returns the thread ID logged by the last call to UIAChanCtx_logCtxChg.
199 */
200 @Macro Int getCtxId();
201
202
203 /*!
204 * ======== isLoggingEnabled ========
205 * returns true if the new context matches the value to enable logging with.
206 *
207 * Default implementation of the IUIACtx_IsLoggingEnabledFxn for user context.
208 * To enable context-aware filtering, assign UIAChanCtx_isLoggingEnabledFxn = &UIAChanCtx_isLoggingEnabled
209 * in the config script or programmatically, or assign your own implementation of this
210 * function.
211 * @param(newChanId) the new channel ID
212 * @a(returns) true if logging is enabled
213 */
214 @DirectCall
215 Bool isLoggingEnabled(UInt newChanId);
216
217 /*!
218 * ======== setOldValue =========
219 * sets ti_uia_events_UIAChanCtx_gLastValue to the new value and returns the old value before it was updated.
220 *
221 * @param(newValue) the new value to save in the global variable
222 * @a(return0 the original value of the global variable before it was updated.
223 */
224 @DirectCall
225 UInt setOldValue(UInt newValue);
226 }