|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Formatting rule for OST traces |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracecompiler.engine.rules.osttrace; |
|
20 |
|
21 import com.nokia.tracecompiler.engine.header.ComplexHeaderRule; |
|
22 import com.nokia.tracecompiler.engine.rules.AutomaticTraceTextRule; |
|
23 import com.nokia.tracecompiler.engine.rules.EntryTraceRule; |
|
24 import com.nokia.tracecompiler.engine.rules.ExitTraceRule; |
|
25 import com.nokia.tracecompiler.engine.rules.PerformanceEventRuleBase; |
|
26 import com.nokia.tracecompiler.engine.rules.PerformanceEventStartRule; |
|
27 import com.nokia.tracecompiler.engine.rules.PerformanceEventStopRule; |
|
28 import com.nokia.tracecompiler.engine.rules.StateTraceRule; |
|
29 import com.nokia.tracecompiler.engine.rules.TraceFormatRuleBase; |
|
30 import com.nokia.tracecompiler.model.Trace; |
|
31 import com.nokia.tracecompiler.model.TraceModelListener; |
|
32 import com.nokia.tracecompiler.model.TraceObject; |
|
33 import com.nokia.tracecompiler.model.TraceParameter; |
|
34 import com.nokia.tracecompiler.plugin.TraceFormatConstants; |
|
35 import com.nokia.tracecompiler.plugin.TraceHeaderContribution; |
|
36 import com.nokia.tracecompiler.plugin.TraceAPIFormatter.TraceFormatType; |
|
37 import com.nokia.tracecompiler.source.SourceUtils; |
|
38 |
|
39 /** |
|
40 * Formatting rule for OST traces. |
|
41 * |
|
42 */ |
|
43 public final class OstTraceFormatRule extends TraceFormatRuleBase implements |
|
44 TraceHeaderContribution, TraceModelListener { |
|
45 |
|
46 /** |
|
47 * Separator for parameters within trace text |
|
48 */ |
|
49 private static final String PARAMETER_VALUE_SEPARATOR = "="; //$NON-NLS-1$ |
|
50 |
|
51 /** |
|
52 * Separator for parameter name value |
|
53 */ |
|
54 private static final String PARAMETER_SEPARATOR = ";"; //$NON-NLS-1$ |
|
55 |
|
56 /** |
|
57 * String parameter tag |
|
58 */ |
|
59 private static final String STRING_PARAMETER_TAG = "%s"; //$NON-NLS-1$ |
|
60 |
|
61 /** |
|
62 * Hex parameter tag |
|
63 */ |
|
64 private static final String HEX_PARAMETER_TAG = "0x%x"; //$NON-NLS-1$ |
|
65 |
|
66 /** |
|
67 * SDEC parameter tag |
|
68 */ |
|
69 private static final String SDEC_PARAMETER_TAG = "%d"; //$NON-NLS-1$ |
|
70 |
|
71 /** |
|
72 * UDEC parameter tag |
|
73 */ |
|
74 private static final String UDEC_PARAMETER_TAG = "%u"; //$NON-NLS-1$ |
|
75 |
|
76 /** |
|
77 * Category for traces |
|
78 */ |
|
79 private static final String TRACE_CATEGORY = "EXTRACT_GROUP_ID(aTraceID)"; //$NON-NLS-1$ |
|
80 |
|
81 /** |
|
82 * Name for storage |
|
83 */ |
|
84 public static final String STORAGE_NAME = "OstTraceFormat"; //$NON-NLS-1$ |
|
85 |
|
86 /** |
|
87 * OstTraceEventStart tag |
|
88 */ |
|
89 public static final String OST_TRACE_EVENT_START_TAG = "OstTraceEventStart"; //$NON-NLS-1$ |
|
90 |
|
91 /** |
|
92 * OstTraceEventStop tag |
|
93 */ |
|
94 public static final String OST_TRACE_EVENT_STOP_TAG = "OstTraceEventStop"; //$NON-NLS-1$ |
|
95 |
|
96 /** |
|
97 * Ext-function declaration format |
|
98 */ |
|
99 private static final String HEADER_FORMAT = "OstTraceGen" //$NON-NLS-1$ |
|
100 + TraceFormatConstants.PARAM_COUNT_FORMAT // Number of parameters |
|
101 + "( TUint32 aTraceID" //$NON-NLS-1$ |
|
102 + TraceFormatConstants.PARAMETERS_FORMAT // Trace parameters |
|
103 + " )"; //$NON-NLS-1$ |
|
104 |
|
105 /** |
|
106 * Activation query formatting |
|
107 */ |
|
108 private static final String ACTIVATION_FORMAT = "BTraceFiltered8( " //$NON-NLS-1$ |
|
109 + TRACE_CATEGORY + ", " //$NON-NLS-1$ |
|
110 + "EOstTraceActivationQuery, KOstTraceComponentID, aTraceID )"; //$NON-NLS-1$ |
|
111 |
|
112 /** |
|
113 * Buffered trace format |
|
114 */ |
|
115 private static final String TRACE_BUFFER_FORMAT = "OstSendNBytes( " //$NON-NLS-1$ |
|
116 + TRACE_CATEGORY + ", " //$NON-NLS-1$ |
|
117 + "EOstTrace, KOstTraceComponentID, aTraceID, " //$NON-NLS-1$ |
|
118 + TraceFormatConstants.DATA_BUFFER_FORMAT // Trace data |
|
119 + ", " //$NON-NLS-1$ |
|
120 + TraceFormatConstants.DATA_LENGTH_FORMAT // Trace data length |
|
121 + " );"; //$NON-NLS-1$ |
|
122 |
|
123 /** |
|
124 * Packed trace format |
|
125 */ |
|
126 private static final String TRACE_PACKED_FORMAT = "BTraceFilteredContext12( " //$NON-NLS-1$ |
|
127 + TRACE_CATEGORY + ", " //$NON-NLS-1$ |
|
128 + "EOstTrace, KOstTraceComponentID, aTraceID, " //$NON-NLS-1$ |
|
129 + TraceFormatConstants.DATA_BUFFER_FORMAT // Trace data |
|
130 + " );"; //$NON-NLS-1$ |
|
131 |
|
132 /** |
|
133 * Template for the OstTraceDefinitions.h header file |
|
134 */ |
|
135 private static final String[] MAIN_HEADER_TEMPLATE = { "\r\n" //$NON-NLS-1$ |
|
136 + "// OST_TRACE_COMPILER_IN_USE flag has been added by Trace Compiler\r\n" //$NON-NLS-1$ |
|
137 + "// REMOVE BEFORE CHECK-IN TO VERSION CONTROL\r\n" //$NON-NLS-1$ |
|
138 + "#define OST_TRACE_COMPILER_IN_USE\r\n" //$NON-NLS-1$ |
|
139 + "#include <opensystemtrace.h>\r\n#endif\r\n" }; //$NON-NLS-1$ |
|
140 |
|
141 /* |
|
142 * (non-Javadoc) |
|
143 * |
|
144 * @see com.nokia.tracecompiler.project.TraceProjectAPI#getName() |
|
145 */ |
|
146 public String getName() { |
|
147 return STORAGE_NAME; |
|
148 } |
|
149 |
|
150 /* |
|
151 * (non-Javadoc) |
|
152 * |
|
153 * @see com.nokia.tracecompiler.engine.source.TraceFormattingRule# |
|
154 * getFormat(com.nokia.tracecompiler.model.Trace, |
|
155 * com.nokia.tracecompiler.plugin.TraceAPIFormatter.TraceFormatType) |
|
156 */ |
|
157 public String getFormat(Trace trace, TraceFormatType formatType) { // CodForChk_Dis_ComplexFunc |
|
158 String retval; |
|
159 if (formatType == TraceFormatType.HEADER) { |
|
160 retval = HEADER_FORMAT; |
|
161 } else if (formatType == TraceFormatType.TRACE_BUFFER) { |
|
162 retval = TRACE_BUFFER_FORMAT; |
|
163 } else if (formatType == TraceFormatType.TRACE_PACKED) { |
|
164 retval = TRACE_PACKED_FORMAT; |
|
165 } else if (formatType == TraceFormatType.TRACE_ACTIVATION) { |
|
166 retval = ACTIVATION_FORMAT; |
|
167 } else { |
|
168 retval = null; |
|
169 } |
|
170 |
|
171 return retval; |
|
172 } |
|
173 |
|
174 /* |
|
175 * (non-Javadoc) |
|
176 * |
|
177 * @see com.nokia.tracecompiler.engine.source.SourceFormatRule# |
|
178 * mapParameterCountToSource(com.nokia.tracecompiler.model.Trace, int) |
|
179 */ |
|
180 @Override |
|
181 public String mapParameterCountToSource(Trace trace, int count) { |
|
182 String retval; |
|
183 ComplexHeaderRule rule = trace.getExtension(ComplexHeaderRule.class); |
|
184 if (rule != null && rule.getTraceIDDefineExtension() != null || trace.getExtension(EntryTraceRule.class)!= null) { |
|
185 // Uses the extension tag with extension headers |
|
186 retval = OstConstants.EXTENSION_TRACE_TAG; |
|
187 } else { |
|
188 retval = String.valueOf(count); |
|
189 } |
|
190 return retval; |
|
191 } |
|
192 |
|
193 /* |
|
194 * (non-Javadoc) |
|
195 * |
|
196 * @see com.nokia.tracecompiler.project.TraceHeaderContribution# |
|
197 * getContribution(com.nokia.tracecompiler.project.TraceHeaderContribution. |
|
198 * TraceHeaderContributionType) |
|
199 */ |
|
200 public String[] getContribution(TraceHeaderContributionType type) { |
|
201 String[] retval = null; |
|
202 if (type == TraceHeaderContributionType.GLOBAL_DEFINES) { |
|
203 retval = new String[] { "KOstTraceComponentID 0x" //$NON-NLS-1$ |
|
204 + Integer.toHexString(getOwner().getModel().getID()) }; |
|
205 } else if (type == TraceHeaderContributionType.MAIN_HEADER_CONTENT) { |
|
206 retval = MAIN_HEADER_TEMPLATE; |
|
207 } |
|
208 return retval; |
|
209 } |
|
210 |
|
211 /* |
|
212 * (non-Javadoc) |
|
213 * |
|
214 * @see |
|
215 * com.nokia.tracecompiler.engine.rules.ExtensionBase#setOwner(com.nokia |
|
216 * .tracecompiler.model.TraceObject) |
|
217 */ |
|
218 @Override |
|
219 public void setOwner(TraceObject owner) { |
|
220 if (getOwner() != null) { |
|
221 getOwner().getModel().removeModelListener(this); |
|
222 } |
|
223 super.setOwner(owner); |
|
224 if (owner != null) { |
|
225 owner.getModel().addModelListener(this); |
|
226 } |
|
227 } |
|
228 |
|
229 /* |
|
230 * (non-Javadoc) |
|
231 * |
|
232 * @see com.nokia.tracecompiler.model.TraceModelListener# |
|
233 * objectAdded(com.nokia.tracecompiler.model.TraceObject, |
|
234 * com.nokia.tracecompiler.model.TraceObject) |
|
235 */ |
|
236 public void objectAdded(TraceObject owner, TraceObject object) { |
|
237 } |
|
238 |
|
239 /* |
|
240 * (non-Javadoc) |
|
241 * |
|
242 * @see com.nokia.tracecompiler.model.TraceModelListener# |
|
243 * objectCreationComplete(com.nokia.tracecompiler.model.TraceObject) |
|
244 */ |
|
245 public void objectCreationComplete(TraceObject object) { |
|
246 } |
|
247 |
|
248 /* |
|
249 * (non-Javadoc) |
|
250 * |
|
251 * @see com.nokia.tracecompiler.model.TraceModelListener# |
|
252 * objectRemoved(com.nokia.tracecompiler.model.TraceObject, |
|
253 * com.nokia.tracecompiler.model.TraceObject) |
|
254 */ |
|
255 public void objectRemoved(TraceObject owner, TraceObject object) { |
|
256 } |
|
257 |
|
258 /* |
|
259 * (non-Javadoc) |
|
260 * |
|
261 * @see com.nokia.tracecompiler.model.TraceModelListener# |
|
262 * propertyUpdated(com.nokia.tracecompiler.model.TraceObject, int) |
|
263 */ |
|
264 public void propertyUpdated(TraceObject object, int property) { |
|
265 } |
|
266 |
|
267 /* |
|
268 * (non-Javadoc) |
|
269 * |
|
270 * @see com.nokia.tracecompiler.project.TraceProjectAPI# |
|
271 * formatTraceForExport(com.nokia.tracecompiler.model.Trace, |
|
272 * com.nokia.tracecompiler.project.TraceProjectAPI.TraceFormatFlags) |
|
273 */ |
|
274 public String formatTraceForExport(Trace trace, TraceFormatFlags flags) { |
|
275 // TODO: This uses default formats |
|
276 // -> Should be configurable |
|
277 // > for entry traces |
|
278 // < for exit traces |
|
279 // Logic analyzer format for performance traces |
|
280 String retval = trace.getTrace(); |
|
281 AutomaticTraceTextRule rule = trace |
|
282 .getExtension(AutomaticTraceTextRule.class); |
|
283 int parameterCount = trace.getParameterCount(); |
|
284 if (rule != null) { |
|
285 if (rule instanceof EntryTraceRule) { |
|
286 retval = "> " //$NON-NLS-1$ |
|
287 + retval; |
|
288 } else if (rule instanceof ExitTraceRule) { |
|
289 retval = "< " //$NON-NLS-1$ |
|
290 + retval; |
|
291 } else if (rule instanceof StateTraceRule) { |
|
292 if (parameterCount == 2) { // CodForChk_Dis_Magic |
|
293 retval = retval + "Machine" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
294 + STRING_PARAMETER_TAG + PARAMETER_SEPARATOR |
|
295 + "State" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
296 + STRING_PARAMETER_TAG; |
|
297 } else { |
|
298 retval = retval |
|
299 + "Machine" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
300 + STRING_PARAMETER_TAG + PARAMETER_SEPARATOR |
|
301 + "State" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
302 + STRING_PARAMETER_TAG + PARAMETER_SEPARATOR |
|
303 + "Instance" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
304 + HEX_PARAMETER_TAG; |
|
305 } |
|
306 } |
|
307 |
|
308 if (parameterCount >= 1 && !(rule instanceof StateTraceRule)) { |
|
309 TraceParameter param; |
|
310 for (int i = 0; i < parameterCount; i++) { |
|
311 param = trace.getParameter(i); |
|
312 retval += PARAMETER_SEPARATOR + param.getName() |
|
313 + PARAMETER_VALUE_SEPARATOR |
|
314 + SourceUtils.mapParameterTypeToFormat(param); |
|
315 } |
|
316 } |
|
317 } else { |
|
318 PerformanceEventRuleBase perf = trace |
|
319 .getExtension(PerformanceEventRuleBase.class); |
|
320 if (perf != null) { |
|
321 if (perf instanceof PerformanceEventStartRule) { |
|
322 retval = retval + ">" + PARAMETER_SEPARATOR //$NON-NLS-1$ |
|
323 + "Value" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
324 + SDEC_PARAMETER_TAG; |
|
325 } else if (perf instanceof PerformanceEventStopRule) { |
|
326 retval = retval |
|
327 + "<" //$NON-NLS-1$ |
|
328 + PARAMETER_SEPARATOR |
|
329 + "Value" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
330 + SDEC_PARAMETER_TAG |
|
331 + PARAMETER_SEPARATOR |
|
332 + "Start Event Trace ID" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
333 + UDEC_PARAMETER_TAG; |
|
334 } |
|
335 } |
|
336 } |
|
337 // If formatting is not supported the format characters and parameters |
|
338 // are removed. |
|
339 if (!flags.isFormattingSupported) { |
|
340 int index = retval.indexOf(PARAMETER_SEPARATOR); |
|
341 if (index > 0) { |
|
342 retval = retval.substring(0, index); |
|
343 } |
|
344 retval = SourceUtils.removePrintfFormatting(retval).trim(); |
|
345 } |
|
346 return retval; |
|
347 } |
|
348 } |