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 import xdc.runtime.Types;
38 import xdc.runtime.Diags;
39 import ti.uia.events.IUIACtx;
40 import xdc.rov.ViewInfo;
41
42 /*!
43 * UIA User Context Instrumentation
44 *
45 * The UIAUserCtx module provides context change events
46 * and methods that allow tooling to identify user-defined
47 * context switches and to enable context-aware filtering,
48 * trace and analysis.
49 *
50 * It inherits IUIACtx, which defines a function pointer to
51 * an isLoggingEnabled function which, if configured to point to
52 * a function, will evaluate the function prior to logging the context
53 * change event and will determine whether to log the event based on the
54 * return value of the function. If the function is not configured,
55 * logging will be conditional upon ti_uia_runtime_CtxFilter_module->mIsLoggingEnabled.
56 *
57 * The generation of UIAUserCtx events is also controlled by a module's diagnostics
58 * mask, which is described in details in `{@link xdc.runtime.Diags}`.
59 * `UIAUserCtx` events are generated only when the Diags.ANALYSIS bit is set
60 * in the module's diagnostics mask.
61 *
62 * The following configuration script demonstrates how the application might
63 * control the logging of ANALYSIS events embedded in the `Mod` module at configuration
64 * time. In this case, the configuration script arranges for the `Log`
65 * statements within modules to always generate ANALYSIS events.
66 * Without these configuration statements, no ANALYSIS events would be generated
67 * by any modules.
68 *
69 * @a(Examples)
70 * Example 1: This is part of the XDC configuration file for the application:
71 *
72 * @p(code)
73 * var LogCtxChg = xdc.useModule('ti.uia.runtime.LogCtxChg');
74 * var Diags = xdc.useModule('xdc.runtime.Diags');
75 * var LoggerSys = xdc.useModule('xdc.runtime.LoggerSys');
76 * var Defaults = xdc.useModule('xdc.runtime.Defaults');
77 * var logger = LoggerSys.create();
78 *
79 * Defaults.common$.diags_ANALYSIS = Diags.ALWAYS_ON;
80 * Defaults.common$.logger = logger;
81 * @p
82 *
83 * @p(html)
84 * <hr />
85 * @p
86 *
87 * Example 2: The following example configures a module to support logging
88 * of ANALYSIS events, but defers the actual activation and deactivation of the
89 * logging until runtime. See the `{@link Diags#setMask Diags_setMask()}`
90 * function for details on specifying the control string.
91 *
92 * This is a part of the XDC configuration file for the application:
93 *
94 * @p(code)
95 * var LogCtxChg = xdc.useModule('ti.uia.runtime.LogCtxChg');
96 * var Diags = xdc.useModule('xdc.runtime.Diags');
97 * var Mod = xdc.useModule('my.pkg.Mod');
98 *
99 * Mod.common$.diags_ANALYSIS = Diags.RUNTIME_OFF;
100 * @p
101 *
102 * This is a part of the C code for the application:
103 *
104 * @p(code)
105 * // turn on logging of ANALYSIS events in the module
106 * Diags_setMask("my.pkg.Mod+Z");
107 *
108 * // turn off logging of ANALYSIS events in the module
109 * Diags_setMask("my.pkg.Mod-Z");
110 * @p
111 */
112
113 @CustomHeader
114 module UIAUserCtx inherits IUIACtx {
115
116 /*!
117 * @_nodoc
118 * ======== ModuleView ========
119 */
120 metaonly struct ModuleView {
121 UInt mLastValue;
122 UInt mEnableOnValue;
123 }
124
125 /*!
126 * @_nodoc
127 * ======== rovViewInfo ========
128 */
129 @Facet
130 metaonly config ViewInfo.Instance rovViewInfo =
131 ViewInfo.create({
132 viewMap: [['Module', {type: ViewInfo.MODULE,
133 viewInitFxn: 'viewInitModule',
134 structName: 'ModuleView'}
135 ]]
136 });
137
138 /*!
139 * ======== ctxChg ========
140 * User-defined Context Change event
141 *
142 * Used to log the start of new state in the user-defined context
143 *
144 * Note that this event should not be referenced directly by user code - it is used
145 * internally by the LogCtxChg_user function, which logs the previous user context Id automatically.
146 *
147 * @a(Example)
148 * The following C code shows how to log a Context Change
149 * event that identifies a new user-specified context ID
150 *
151 * @p(code)
152 * #include <ti/uia/runtime/LogCtxChg.h>
153 * ...
154 * LogCtxChg_user("New user context=0x%x",newUserContextId);
155 * ...
156 *
157 * @p
158 * This event prints the Log call site (%$F) and a format string (%$S)
159 * which is recursively formatted with any addition arguments.
160 * The following text is an example of what will be displayed for the event:
161 * @p(code)
162 * "User Ctx Change at Line 123 in appLoader.c [Prev. ctx = 0x1234] New user context=0x1235"
163 *
164 * @param(fmt) a constant string that describes the context change and provides a format specifier for newAppId
165 * @param(newUserContextId) an integer which uniquely identifies the new user context
166 */
167 config xdc.runtime.Log.Event ctxChg = {
168 mask: Diags.ANALYSIS,
169 msg: "User Ctx Change at %$F [Prev. ctx = 0x%x] %$S"};
170
171 /*!
172 * ======== metaEventUserCtxChg ========
173 * Metadata description of the User Context Change event
174 *
175 * @_nodoc
176 */
177 metaonly config DvtTypes.MetaEventDescriptor metaEventUserCtxChg = {
178 versionId: "2.0",
179 analysisType: DvtTypes.DvtAnalysisType_CONTEXTCHANGE,
180 displayText: "User Ctx Change",
181 tooltipText: "User Context Change",
182 numParameters: 5,
183 paramInfo: [
184 { name: '__FILE__',
185 dataDesc: DvtTypes.DvtDataDesc_FILENAMESTR,
186 dataTypeName: 'String',
187 units: 'none',
188 isHidden: false
189 },
190 { name: '__LINE__',
191 dataDesc: DvtTypes.DvtDataDesc_LINENUM,
192 dataTypeName: 'Int',
193 units: 'none',
194 isHidden: false
195 },
196 { name: 'Prev. User Context',
197 dataDesc: DvtTypes.DvtDataDesc_STATEID,
198 dataTypeName: 'Int',
199 units: 'none',
200 isHidden: false
201 },
202 { name: 'fmt',
203 dataDesc: DvtTypes.DvtDataDesc_FMTSTR,
204 dataTypeName: 'String',
205 units: 'none',
206 isHidden: false
207 },
208 { name: 'New User Context',
209 dataDesc: DvtTypes.DvtDataDesc_STATEID,
210 dataTypeName: 'Int',
211 units: 'none',
212 isHidden: false
213 }]
214
215 };
216 /*!
217 * ======== getCtxId ========
218 * Get the ID for the current user-defined context
219 *
220 * @a(returns)
221 * returns the context ID logged by the last call to UIAUserCtx_logCtxChg.
222 */
223 @DirectCall
224 UInt getCtxId();
225
226 /*!
227 * ======== getEnableOnValue ========
228 * Get the EnableOn value
229 *
230 * @a(returns) returns the context ID value that logging will be enabled for.
231 */
232 @DirectCall
233 UInt getEnableOnValue();
234
235 /*!
236 * ======== setEnableOnValue ========
237 * Set the EnableOn value
238 *
239 * @param(value) the CtxId value that logging will be enabled for.
240 */
241 @DirectCall
242 Void setEnableOnValue(UInt value);
243
244 /*!
245 * ======== isLoggingEnabled ========
246 * returns true if the new context matches the value to enable logging with.
247 *
248 * Default implementation of the IUIACtx_IsLoggingEnabledFxn for user context.
249 * To enable context-aware filtering, in the .cfg script assign
250 * UIAUserCtx_isLoggingEnabledFxn = '&UIAUserCtx_isLoggingEnabled'
251 * or assign your own implementation of this function.
252 *
253 * @param(newUserCtx) the new user context
254 * @a(returns) true if logging is enabled
255 */
256 @DirectCall
257 Bool isLoggingEnabled(UInt newUserCtx);
258
259 /*!
260 * ======== setOldValue =========
261 * sets ti_uia_events_UIAUserCtx_gLastValue to the new value and returns the old value before it was updated.
262 *
263 * @param(newValue) the new value to save in the global variable
264 * @a(return) the original value of the global variable before it was updated.
265 */
266 @DirectCall
267 UInt setOldValue(UInt newValue);
268
269 internal:
270
271 struct Module_State {
272 UInt mLastValue;
273 UInt mEnableOnValue;
274 };
275 }