|
1 /* |
|
2 * Copyright (c) 2009-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.tracebuilder.engine.rules.osttrace; |
|
20 |
|
21 import com.nokia.tracebuilder.engine.TraceBuilderGlobals; |
|
22 import com.nokia.tracebuilder.engine.rules.AutomaticTraceTextRule; |
|
23 import com.nokia.tracebuilder.engine.rules.ComplexHeaderRule; |
|
24 import com.nokia.tracebuilder.engine.rules.EntryTraceRule; |
|
25 import com.nokia.tracebuilder.engine.rules.ExitTraceRule; |
|
26 import com.nokia.tracebuilder.engine.rules.PerformanceEventRuleBase; |
|
27 import com.nokia.tracebuilder.engine.rules.PerformanceEventStartRule; |
|
28 import com.nokia.tracebuilder.engine.rules.PerformanceEventStopRule; |
|
29 import com.nokia.tracebuilder.engine.rules.StateTraceRule; |
|
30 import com.nokia.tracebuilder.engine.rules.TraceFormatRuleBase; |
|
31 import com.nokia.tracebuilder.model.Trace; |
|
32 import com.nokia.tracebuilder.model.TraceModelListener; |
|
33 import com.nokia.tracebuilder.model.TraceObject; |
|
34 import com.nokia.tracebuilder.model.TraceParameter; |
|
35 import com.nokia.tracebuilder.plugin.TraceFormatConstants; |
|
36 import com.nokia.tracebuilder.plugin.TraceHeaderContribution; |
|
37 import com.nokia.tracebuilder.plugin.TraceAPIFormatter.TraceFormatType; |
|
38 import com.nokia.tracebuilder.project.GroupNameHandlerBase; |
|
39 import com.nokia.tracebuilder.rules.HiddenTraceObjectRule; |
|
40 import com.nokia.tracebuilder.source.SourceConstants; |
|
41 import com.nokia.tracebuilder.source.SourceUtils; |
|
42 import java.util.regex.Matcher; |
|
43 |
|
44 /** |
|
45 * Formatting rule for OST traces. |
|
46 * |
|
47 */ |
|
48 public final class OstTraceFormatRule extends TraceFormatRuleBase implements |
|
49 TraceHeaderContribution, TraceModelListener { |
|
50 |
|
51 /** |
|
52 * Separator for parameters within trace text |
|
53 */ |
|
54 private static final String PARAMETER_VALUE_SEPARATOR = "="; //$NON-NLS-1$ |
|
55 |
|
56 /** |
|
57 * Separator for parameter name ane value |
|
58 */ |
|
59 private static final String PARAMETER_SEPARATOR = ";"; //$NON-NLS-1$ |
|
60 |
|
61 /** |
|
62 * String parameter tag |
|
63 */ |
|
64 private static final String STRING_PARAMETER_TAG = "%s"; //$NON-NLS-1$ |
|
65 |
|
66 /** |
|
67 * Hex parameter tag |
|
68 */ |
|
69 private static final String HEX_PARAMETER_TAG = "0x%x"; //$NON-NLS-1$ |
|
70 |
|
71 /** |
|
72 * SDEC parameter tag |
|
73 */ |
|
74 private static final String SDEC_PARAMETER_TAG = "%d"; //$NON-NLS-1$ |
|
75 |
|
76 /** |
|
77 * Category for traces |
|
78 */ |
|
79 private static final String TRACE_CATEGORY = "KBTraceCategoryOpenSystemTrace"; //$NON-NLS-1$ |
|
80 |
|
81 /** |
|
82 * Title shown in UI |
|
83 */ |
|
84 private static final String UI_TITLE = "Open System Trace"; //$NON-NLS-1$ |
|
85 |
|
86 /** |
|
87 * Name for storage |
|
88 */ |
|
89 public static final String STORAGE_NAME = "OstTraceFormat"; //$NON-NLS-1$ |
|
90 |
|
91 /** |
|
92 * OstTraceEventStart tag |
|
93 */ |
|
94 public static final String OST_TRACE_EVENT_START_TAG = "OstTraceEventStart"; //$NON-NLS-1$ |
|
95 |
|
96 /** |
|
97 * OstTraceEventStop tag |
|
98 */ |
|
99 public static final String OST_TRACE_EVENT_STOP_TAG = "OstTraceEventStop"; //$NON-NLS-1$ |
|
100 |
|
101 /** |
|
102 * Source formatting |
|
103 */ |
|
104 private static final String TRACE_FORMAT = "OstTrace" //$NON-NLS-1$ |
|
105 + TraceFormatConstants.PARAM_COUNT_FORMAT // Number of parameters |
|
106 + "( " //$NON-NLS-1$ |
|
107 + TraceFormatConstants.GROUP_FORMAT // Group name |
|
108 + ", " //$NON-NLS-1$ |
|
109 + TraceFormatConstants.NAME_FORMAT // Trace name |
|
110 + ", " //$NON-NLS-1$ |
|
111 + TraceFormatConstants.TEXT_FORMAT // Trace text |
|
112 + TraceFormatConstants.PARAMETERS_FORMAT // Trace parameters |
|
113 + " );"; //$NON-NLS-1$ |
|
114 |
|
115 /** |
|
116 * Source formatting with complex traces |
|
117 */ |
|
118 private static final String COMPLEX_TRACE_FORMAT = "OstTraceExt" //$NON-NLS-1$ |
|
119 + TraceFormatConstants.PARAM_COUNT_FORMAT // Number of parameters |
|
120 + "( " //$NON-NLS-1$ |
|
121 + TraceFormatConstants.GROUP_FORMAT // Group name |
|
122 + ", " //$NON-NLS-1$ |
|
123 + TraceFormatConstants.NAME_FORMAT // Trace name |
|
124 + ", " //$NON-NLS-1$ |
|
125 + TraceFormatConstants.TEXT_FORMAT // Trace text |
|
126 + TraceFormatConstants.PARAMETERS_FORMAT // Trace parameters |
|
127 + " );"; //$NON-NLS-1$ |
|
128 |
|
129 /** |
|
130 * Function entry formatting |
|
131 */ |
|
132 private static final String ENTRY_TRACE_FORMAT = "OstTraceFunctionEntry" //$NON-NLS-1$ |
|
133 + TraceFormatConstants.PARAM_COUNT_FORMAT + "( " //$NON-NLS-1$ |
|
134 + TraceFormatConstants.NAME_FORMAT // Trace name |
|
135 + TraceFormatConstants.PARAMETERS_FORMAT // Trace parameters |
|
136 + " );"; //$NON-NLS-1$ |
|
137 |
|
138 /** |
|
139 * Function entry Ext formatting |
|
140 */ |
|
141 private static final String ENTRY_TRACE_EXT_FORMAT_THIS = "OstTraceFunctionEntryExt( " //$NON-NLS-1$ |
|
142 + TraceFormatConstants.NAME_FORMAT // Trace name |
|
143 + ", this );"; //$NON-NLS-1$ |
|
144 |
|
145 /** |
|
146 * Function exit formatting |
|
147 */ |
|
148 private static final String EXIT_TRACE_FORMAT = "OstTraceFunctionExit" //$NON-NLS-1$ |
|
149 + TraceFormatConstants.PARAM_COUNT_FORMAT + "( " //$NON-NLS-1$ |
|
150 + TraceFormatConstants.NAME_FORMAT // Trace name |
|
151 + TraceFormatConstants.PARAMETERS_FORMAT // Trace parameters |
|
152 + " );"; //$NON-NLS-1$ |
|
153 |
|
154 /** |
|
155 * Function exit Ext formatting |
|
156 */ |
|
157 private static final String EXIT_TRACE_EXT_FORMAT = "OstTraceFunctionExitExt( " //$NON-NLS-1$ |
|
158 + TraceFormatConstants.NAME_FORMAT // Trace name |
|
159 + TraceFormatConstants.PARAMETERS_FORMAT // Trace parameters |
|
160 + " );"; //$NON-NLS-1$ |
|
161 |
|
162 /** |
|
163 * State formatting |
|
164 */ |
|
165 private static final String STATE_TRACE_FORMAT = "OstTraceState" //$NON-NLS-1$ |
|
166 + TraceFormatConstants.PARAM_COUNT_FORMAT |
|
167 + "( " //$NON-NLS-1$ |
|
168 + TraceFormatConstants.NAME_FORMAT // Trace name |
|
169 + TraceFormatConstants.STATE_MACHINE_NAME_FORMAT |
|
170 + TraceFormatConstants.STATE_MACHINE_STATE_FORMAT |
|
171 + TraceFormatConstants.PARAMETERS_FORMAT // Trace parameters |
|
172 + " );"; //$NON-NLS-1$ |
|
173 |
|
174 /** |
|
175 * Performance event start formatting |
|
176 */ |
|
177 private static final String EVENT_START_FORMAT = OST_TRACE_EVENT_START_TAG |
|
178 + TraceFormatConstants.PARAM_COUNT_FORMAT + "( " //$NON-NLS-1$ |
|
179 + TraceFormatConstants.NAME_FORMAT // Trace name |
|
180 + ", " //$NON-NLS-1$ |
|
181 + TraceFormatConstants.EVENT_NAME_FORMAT // Event name |
|
182 + TraceFormatConstants.PARAMETERS_FORMAT // Trace parameters |
|
183 + " );"; //$NON-NLS-1$ |
|
184 |
|
185 /** |
|
186 * Performance event stop formatting |
|
187 */ |
|
188 private static final String EVENT_STOP_FORMAT = OST_TRACE_EVENT_STOP_TAG |
|
189 + "( " //$NON-NLS-1$ |
|
190 + TraceFormatConstants.NAME_FORMAT // Trace name |
|
191 + ", " //$NON-NLS-1$ |
|
192 + TraceFormatConstants.EVENT_NAME_FORMAT // Event name |
|
193 + ", " //$NON-NLS-1$ |
|
194 // Start Event Trace name |
|
195 + TraceFormatConstants.EVENT_START_TRACE_NAME_FORMAT |
|
196 + TraceFormatConstants.PARAMETERS_FORMAT // Trace parameters |
|
197 + " );"; //$NON-NLS-1$ |
|
198 |
|
199 /** |
|
200 * Ext-function declaration format |
|
201 */ |
|
202 private static final String HEADER_FORMAT = "OstTraceGen" //$NON-NLS-1$ |
|
203 + TraceFormatConstants.PARAM_COUNT_FORMAT // Number of parameters |
|
204 + "( TUint32 aTraceID" //$NON-NLS-1$ |
|
205 + TraceFormatConstants.PARAMETERS_FORMAT // Trace parameters |
|
206 + " )"; //$NON-NLS-1$ |
|
207 |
|
208 /** |
|
209 * Activation query formatting |
|
210 */ |
|
211 private static final String ACTIVATION_FORMAT = "BTrace8( " //$NON-NLS-1$ |
|
212 + TRACE_CATEGORY + ", " //$NON-NLS-1$ |
|
213 + "EOstTraceActivationQuery, KOstTraceComponentID, aTraceID )"; //$NON-NLS-1$ |
|
214 |
|
215 /** |
|
216 * Buffered trace format |
|
217 */ |
|
218 private static final String TRACE_BUFFER_FORMAT = "OstSendNBytes( " //$NON-NLS-1$ |
|
219 + TRACE_CATEGORY + ", " //$NON-NLS-1$ |
|
220 + "EOstTrace, KOstTraceComponentID, aTraceID, " //$NON-NLS-1$ |
|
221 + TraceFormatConstants.DATA_BUFFER_FORMAT // Trace data |
|
222 + ", " //$NON-NLS-1$ |
|
223 + TraceFormatConstants.DATA_LENGTH_FORMAT // Trace data length |
|
224 + " );"; //$NON-NLS-1$ |
|
225 |
|
226 /** |
|
227 * Packed trace format |
|
228 */ |
|
229 private static final String TRACE_PACKED_FORMAT = "BTraceContext12( " //$NON-NLS-1$ |
|
230 + TRACE_CATEGORY + ", " //$NON-NLS-1$ |
|
231 + "EOstTrace, KOstTraceComponentID, aTraceID, " //$NON-NLS-1$ |
|
232 + TraceFormatConstants.DATA_BUFFER_FORMAT // Trace data |
|
233 + " );"; //$NON-NLS-1$ |
|
234 |
|
235 /** |
|
236 * #include format |
|
237 */ |
|
238 private String INCLUDE_FORMAT = "#include \"OstTraceDefinitions.h\"\r\n" //$NON-NLS-1$ |
|
239 + "#ifdef OST_TRACE_COMPILER_IN_USE\r\n#include \"" //$NON-NLS-1$ |
|
240 + TraceFormatConstants.INCLUDE_FORMAT + "\"\r\n#endif"; //$NON-NLS-1$ |
|
241 |
|
242 /** |
|
243 * Template for the OstTraceDefinitions.h header file |
|
244 */ |
|
245 private static final String[] MAIN_HEADER_TEMPLATE = { "\r\n" //$NON-NLS-1$ |
|
246 + "// OST_TRACE_COMPILER_IN_USE flag has been added by Trace Compiler\r\n" //$NON-NLS-1$ |
|
247 + "// REMOVE BEFORE CHECK-IN TO VERSION CONTROL\r\n" //$NON-NLS-1$ |
|
248 + "#define OST_TRACE_COMPILER_IN_USE\r\n" //$NON-NLS-1$ |
|
249 + "#include <OpenSystemTrace.h>\r\n#endif\r\n" }; //$NON-NLS-1$ |
|
250 |
|
251 /* |
|
252 * (non-Javadoc) |
|
253 * |
|
254 * @see com.nokia.tracebuilder.project.TraceProjectAPI#getName() |
|
255 */ |
|
256 public String getName() { |
|
257 return STORAGE_NAME; |
|
258 } |
|
259 |
|
260 /* |
|
261 * (non-Javadoc) |
|
262 * |
|
263 * @see com.nokia.tracebuilder.project.TraceProjectAPI#getTitle() |
|
264 */ |
|
265 public String getTitle() { |
|
266 return UI_TITLE; |
|
267 } |
|
268 |
|
269 /* |
|
270 * (non-Javadoc) |
|
271 * |
|
272 * @see com.nokia.tracebuilder.engine.source.TraceFormattingRule# |
|
273 * getFormat(com.nokia.tracebuilder.model.Trace, |
|
274 * com.nokia.tracebuilder.plugin.TraceAPIFormatter.TraceFormatType) |
|
275 */ |
|
276 public String getFormat(Trace trace, TraceFormatType formatType) { // CodForChk_Dis_ComplexFunc |
|
277 String retval; |
|
278 if (formatType == TraceFormatType.NORMAL_TRACE |
|
279 || formatType == TraceFormatType.COMPLEX_TRACE) { |
|
280 if (trace.getExtension(PerformanceEventStartRule.class) != null) { |
|
281 retval = EVENT_START_FORMAT; |
|
282 } else if (trace.getExtension(PerformanceEventStopRule.class) != null) { |
|
283 retval = EVENT_STOP_FORMAT; |
|
284 } else if (trace.getExtension(EntryTraceRule.class) != null) { |
|
285 // If the trace is entry trace with function parameters, the |
|
286 // parameters are not inserted into source. Instead, only the |
|
287 // "this" pointer is added |
|
288 if (trace.getExtension(ComplexHeaderRule.class) != null) { |
|
289 retval = ENTRY_TRACE_EXT_FORMAT_THIS; |
|
290 } else { |
|
291 retval = ENTRY_TRACE_FORMAT; |
|
292 } |
|
293 } else if (trace.getExtension(ExitTraceRule.class) != null) { |
|
294 if (trace.getExtension(ComplexHeaderRule.class) != null) { |
|
295 retval = EXIT_TRACE_EXT_FORMAT; |
|
296 } else { |
|
297 retval = EXIT_TRACE_FORMAT; |
|
298 } |
|
299 } else if (trace.getExtension(StateTraceRule.class) != null) { |
|
300 retval = STATE_TRACE_FORMAT; |
|
301 } else { |
|
302 if (formatType == TraceFormatType.NORMAL_TRACE) { |
|
303 retval = TRACE_FORMAT; |
|
304 } else if (formatType == TraceFormatType.COMPLEX_TRACE) { |
|
305 retval = COMPLEX_TRACE_FORMAT; |
|
306 } else { |
|
307 retval = null; |
|
308 } |
|
309 } |
|
310 } else { |
|
311 if (formatType == TraceFormatType.HEADER) { |
|
312 retval = HEADER_FORMAT; |
|
313 } else if (formatType == TraceFormatType.TRACE_BUFFER) { |
|
314 retval = TRACE_BUFFER_FORMAT; |
|
315 } else if (formatType == TraceFormatType.TRACE_PACKED) { |
|
316 retval = TRACE_PACKED_FORMAT; |
|
317 } else if (formatType == TraceFormatType.TRACE_ACTIVATION) { |
|
318 retval = ACTIVATION_FORMAT; |
|
319 } else if (formatType == TraceFormatType.INCLUDE_FORMAT) { |
|
320 retval = INCLUDE_FORMAT; |
|
321 } else { |
|
322 retval = null; |
|
323 } |
|
324 } |
|
325 return retval; |
|
326 } |
|
327 |
|
328 /* |
|
329 * (non-Javadoc) |
|
330 * |
|
331 * @see com.nokia.tracebuilder.engine.source.SourceFormatRule# |
|
332 * mapParameterCountToSource(com.nokia.tracebuilder.model.Trace, int) |
|
333 */ |
|
334 @Override |
|
335 public String mapParameterCountToSource(Trace trace, int count) { |
|
336 String retval; |
|
337 ComplexHeaderRule rule = trace.getExtension(ComplexHeaderRule.class); |
|
338 if (rule != null && rule.getTraceIDDefineExtension() != null) { |
|
339 // Uses the extension tag with extension headers |
|
340 retval = OstConstants.EXTENSION_TRACE_TAG; |
|
341 } else { |
|
342 retval = String.valueOf(count); |
|
343 } |
|
344 return retval; |
|
345 } |
|
346 |
|
347 /* |
|
348 * (non-Javadoc) |
|
349 * |
|
350 * @see com.nokia.tracebuilder.project.TraceHeaderContribution# |
|
351 * getContribution(com.nokia.tracebuilder.project.TraceHeaderContribution.TraceHeaderContributionType) |
|
352 */ |
|
353 public String[] getContribution(TraceHeaderContributionType type) { |
|
354 String[] retval = null; |
|
355 if (type == TraceHeaderContributionType.GLOBAL_DEFINES) { |
|
356 retval = new String[] { "KOstTraceComponentID 0x" //$NON-NLS-1$ |
|
357 + Integer.toHexString(getOwner().getModel().getID()) }; |
|
358 } else if (type == TraceHeaderContributionType.MAIN_HEADER_CONTENT) { |
|
359 retval = MAIN_HEADER_TEMPLATE; |
|
360 } |
|
361 return retval; |
|
362 } |
|
363 |
|
364 /* |
|
365 * (non-Javadoc) |
|
366 * |
|
367 * @see com.nokia.tracebuilder.project.TraceProjectAPI#isVisibleInConfiguration() |
|
368 */ |
|
369 public boolean isVisibleInConfiguration() { |
|
370 return true; |
|
371 } |
|
372 |
|
373 /* |
|
374 * (non-Javadoc) |
|
375 * |
|
376 * @see com.nokia.tracebuilder.engine.rules.ExtensionBase#setOwner(com.nokia.tracebuilder.model.TraceObject) |
|
377 */ |
|
378 @Override |
|
379 public void setOwner(TraceObject owner) { |
|
380 if (getOwner() != null) { |
|
381 getOwner().getModel().removeModelListener(this); |
|
382 } |
|
383 super.setOwner(owner); |
|
384 if (owner != null) { |
|
385 owner.getModel().addModelListener(this); |
|
386 } |
|
387 } |
|
388 |
|
389 /* |
|
390 * (non-Javadoc) |
|
391 * |
|
392 * @see com.nokia.tracebuilder.model.TraceModelListener# |
|
393 * objectAdded(com.nokia.tracebuilder.model.TraceObject, |
|
394 * com.nokia.tracebuilder.model.TraceObject) |
|
395 */ |
|
396 public void objectAdded(TraceObject owner, TraceObject object) { |
|
397 } |
|
398 |
|
399 /* |
|
400 * (non-Javadoc) |
|
401 * |
|
402 * @see com.nokia.tracebuilder.model.TraceModelListener# |
|
403 * objectCreationComplete(com.nokia.tracebuilder.model.TraceObject) |
|
404 */ |
|
405 public void objectCreationComplete(TraceObject object) { |
|
406 // Model must be valid and converter not running |
|
407 // -> Parameter was added via UI |
|
408 // Also, parameter must not be hidden, otherwise fillers would update |
|
409 // the trace |
|
410 if (object.getModel().isValid() |
|
411 && object instanceof TraceParameter |
|
412 && !TraceBuilderGlobals.getSourceContextManager() |
|
413 .isConverting() |
|
414 && object.getExtension(HiddenTraceObjectRule.class) == null) { |
|
415 TraceParameter param = (TraceParameter) object; |
|
416 Trace parent = param.getTrace(); |
|
417 |
|
418 // In case of performance event trace we do not add parameter to |
|
419 // trace text |
|
420 GroupNameHandlerBase groupNameHandler = TraceBuilderGlobals.getGroupNameHandler(); |
|
421 if (!(parent.getGroup().getName() |
|
422 .equals(groupNameHandler.getDefaultGroups()[groupNameHandler.getPerformanceGroupIdIndex()]))) { |
|
423 addParameterToTraceText(param); |
|
424 } |
|
425 } |
|
426 } |
|
427 |
|
428 /** |
|
429 * Adds parameter formatting to trace text |
|
430 * |
|
431 * @param param |
|
432 * the parameter |
|
433 */ |
|
434 private void addParameterToTraceText(TraceParameter param) { |
|
435 // Adds the parameter format to the trace text |
|
436 // Auto-text traces are not updated |
|
437 String text; |
|
438 Trace parent = param.getTrace(); |
|
439 |
|
440 if (parent.getExtension(AutomaticTraceTextRule.class) == null) { |
|
441 text = parent.getTrace() + PARAMETER_SEPARATOR + param.getName() |
|
442 + PARAMETER_VALUE_SEPARATOR |
|
443 + SourceUtils.mapParameterTypeToFormat(param); |
|
444 |
|
445 parent.setTrace(text); |
|
446 } |
|
447 } |
|
448 |
|
449 /* |
|
450 * (non-Javadoc) |
|
451 * |
|
452 * @see com.nokia.tracebuilder.model.TraceModelListener# |
|
453 * objectRemoved(com.nokia.tracebuilder.model.TraceObject, |
|
454 * com.nokia.tracebuilder.model.TraceObject) |
|
455 */ |
|
456 public void objectRemoved(TraceObject owner, TraceObject object) { |
|
457 } |
|
458 |
|
459 /* |
|
460 * (non-Javadoc) |
|
461 * |
|
462 * @see com.nokia.tracebuilder.engine.rules.TraceFormatRuleBase# |
|
463 * parameterAboutToBeRemoved(com.nokia.tracebuilder.model.TraceParameter, |
|
464 * int) |
|
465 */ |
|
466 @Override |
|
467 public void parameterAboutToBeRemoved(TraceParameter parameter, int index) { |
|
468 Trace trace = parameter.getTrace(); |
|
469 String tracetext = trace.getTrace(); |
|
470 |
|
471 if (tracetext != "") { //$NON-NLS-1$ |
|
472 Matcher matcher = SourceUtils.traceTextPattern.matcher(tracetext); |
|
473 |
|
474 boolean found = true; |
|
475 int i = -1; |
|
476 int previousmatchend = 0; |
|
477 |
|
478 do { |
|
479 found = matcher.find(); |
|
480 i++; |
|
481 // Store end location of the previous match |
|
482 if (i < index) { |
|
483 previousmatchend = matcher.start() |
|
484 + matcher.group().length(); |
|
485 } |
|
486 } while (i < index); |
|
487 |
|
488 if (found) { |
|
489 int matchstart = matcher.start(); |
|
490 String group = matcher.group(); |
|
491 |
|
492 if (index == 0) { |
|
493 // Fist parameter is going to be removed |
|
494 int firstpartend = tracetext.lastIndexOf(';', matchstart); |
|
495 if (firstpartend < 0) { |
|
496 // Trace text is not TB in format, so remove only |
|
497 // parameter tag. |
|
498 firstpartend = matchstart; |
|
499 |
|
500 // If trace group is TRACE_PERFORMANCE, trace could be |
|
501 // in LocigAnalyzer format. Remove also extra space |
|
502 // before parameter tag |
|
503 String traceGroupName = trace.getGroup().getName(); |
|
504 GroupNameHandlerBase groupNameHandler = TraceBuilderGlobals.getGroupNameHandler(); |
|
505 int performanceGroupIndex = groupNameHandler.getPerformanceGroupIdIndex(); |
|
506 String performanceGroupName = groupNameHandler.getDefaultGroups()[performanceGroupIndex]; |
|
507 if (traceGroupName.equals(performanceGroupName)) { |
|
508 if (tracetext.charAt(firstpartend - 1) == SourceConstants.SPACE_CHAR) { |
|
509 firstpartend--; |
|
510 } |
|
511 } |
|
512 } |
|
513 trace.setTrace(tracetext.substring(0, firstpartend) |
|
514 + tracetext.substring(matchstart + group.length())); |
|
515 } else { |
|
516 // Some other than first parameter is going to be removed |
|
517 if (tracetext.charAt(previousmatchend) == ';') { |
|
518 // Trace text is TB in format, so remove also some text |
|
519 // before parameter tag. |
|
520 trace.setTrace(tracetext.substring(0, previousmatchend) |
|
521 + tracetext.substring(matchstart |
|
522 + group.length())); |
|
523 } else { |
|
524 // Trace text is not TB in format, so remove only |
|
525 // parameter tag. |
|
526 trace.setTrace(tracetext.substring(0, matchstart) |
|
527 + tracetext.substring(matchstart |
|
528 + group.length())); |
|
529 } |
|
530 } |
|
531 } |
|
532 } |
|
533 } |
|
534 |
|
535 /* |
|
536 * (non-Javadoc) |
|
537 * |
|
538 * @see com.nokia.tracebuilder.model.TraceModelListener# |
|
539 * propertyUpdated(com.nokia.tracebuilder.model.TraceObject, int) |
|
540 */ |
|
541 public void propertyUpdated(TraceObject object, int property) { |
|
542 } |
|
543 |
|
544 /* |
|
545 * (non-Javadoc) |
|
546 * |
|
547 * @see com.nokia.tracebuilder.project.TraceProjectAPI# |
|
548 * formatTraceForExport(com.nokia.tracebuilder.model.Trace, |
|
549 * com.nokia.tracebuilder.project.TraceProjectAPI.TraceFormatFlags) |
|
550 */ |
|
551 public String formatTraceForExport(Trace trace, TraceFormatFlags flags) { |
|
552 // TODO: This uses default formats |
|
553 // -> Should be configurable |
|
554 // > for entry traces |
|
555 // < for exit traces |
|
556 // Logic analyzer format for performance traces |
|
557 String retval = trace.getTrace(); |
|
558 AutomaticTraceTextRule rule = trace |
|
559 .getExtension(AutomaticTraceTextRule.class); |
|
560 int parameterCount = trace.getParameterCount(); |
|
561 if (rule != null) { |
|
562 if (rule instanceof EntryTraceRule) { |
|
563 retval = "> " //$NON-NLS-1$ |
|
564 + retval; |
|
565 } else if (rule instanceof ExitTraceRule) { |
|
566 retval = "< " //$NON-NLS-1$ |
|
567 + retval; |
|
568 } else if (rule instanceof StateTraceRule) { |
|
569 if (parameterCount == 2) { // CodForChk_Dis_Magic |
|
570 retval = retval + "Machine" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
571 + STRING_PARAMETER_TAG + PARAMETER_SEPARATOR |
|
572 + "State" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
573 + STRING_PARAMETER_TAG; |
|
574 } else { |
|
575 retval = retval |
|
576 + "Machine" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
577 + STRING_PARAMETER_TAG + PARAMETER_SEPARATOR |
|
578 + "State" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
579 + STRING_PARAMETER_TAG + PARAMETER_SEPARATOR |
|
580 + "Instance" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
581 + HEX_PARAMETER_TAG; |
|
582 } |
|
583 } |
|
584 |
|
585 if (parameterCount >= 1 && !(rule instanceof StateTraceRule)) { |
|
586 TraceParameter param; |
|
587 for (int i = 0; i < parameterCount; i++) { |
|
588 param = trace.getParameter(i); |
|
589 retval += PARAMETER_SEPARATOR + param.getName() |
|
590 + PARAMETER_VALUE_SEPARATOR |
|
591 + SourceUtils.mapParameterTypeToFormat(param); |
|
592 } |
|
593 } |
|
594 } else { |
|
595 PerformanceEventRuleBase perf = trace |
|
596 .getExtension(PerformanceEventRuleBase.class); |
|
597 if (perf != null) { |
|
598 if (perf instanceof PerformanceEventStartRule) { |
|
599 retval = retval + "> " + PARAMETER_SEPARATOR //$NON-NLS-1$ |
|
600 + "Value" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
601 + SDEC_PARAMETER_TAG; |
|
602 } else if (perf instanceof PerformanceEventStopRule) { |
|
603 retval = retval + "< " //$NON-NLS-1$ |
|
604 + PARAMETER_SEPARATOR |
|
605 + "Value" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
606 + SDEC_PARAMETER_TAG |
|
607 + PARAMETER_SEPARATOR |
|
608 + "Start Event Trace ID" + PARAMETER_VALUE_SEPARATOR //$NON-NLS-1$ |
|
609 + SDEC_PARAMETER_TAG; |
|
610 } |
|
611 } |
|
612 } |
|
613 // If formatting is not supported the format characters and parameters |
|
614 // are removed. |
|
615 if (!flags.isFormattingSupported) { |
|
616 int index = retval.indexOf(PARAMETER_SEPARATOR); |
|
617 if (index > 0) { |
|
618 retval = retval.substring(0, index); |
|
619 } |
|
620 retval = SourceUtils.removePrintfFormatting(retval).trim(); |
|
621 } |
|
622 return retval; |
|
623 } |
|
624 } |