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