1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
;
15 import java
.util
.regex
.Matcher
;
17 import org
.eclipse
.jdt
.annotation
.NonNull
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEvent
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventType
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
.Tag
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.InputData
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.InputLine
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
28 * Trace event for custom text parsers.
30 * @author Patrick Tassé
32 public class CustomTxtEvent
extends CustomEvent
{
34 private String fLastExtraFieldName
= null;
42 public CustomTxtEvent(CustomTxtTraceDefinition definition
) {
47 * Construct a custom text event from an existing TmfEvent.
52 * The TmfEvent object to copy
54 public CustomTxtEvent(CustomTxtTraceDefinition definition
, @NonNull TmfEvent other
) {
55 super(definition
, other
);
66 * Timestamp of this event
70 public CustomTxtEvent(CustomTxtTraceDefinition definition
,
71 ITmfTrace parentTrace
, ITmfTimestamp timestamp
, TmfEventType type
) {
72 super(definition
, parentTrace
, timestamp
, type
);
76 public void setContent(ITmfEventField content
) {
77 super.setContent(content
);
81 * Process an entry in the trace file
84 * The input line to read
86 * The regex matcher to use
88 public void processGroups(InputLine input
, Matcher matcher
) {
89 if (input
.eventType
!= null) {
90 fData
.put(Tag
.EVENT_TYPE
, input
.eventType
);
92 if (input
.columns
== null) {
95 for (int i
= 0; i
< input
.columns
.size(); i
++) {
96 InputData column
= input
.columns
.get(i
);
97 if (i
< matcher
.groupCount() && matcher
.group(i
+ 1) != null) {
98 String value
= matcher
.group(i
+ 1).trim();
99 if (value
.length() == 0) {
102 Object key
= (column
.tag
.equals(Tag
.OTHER
) ? column
.name
: column
.tag
);
103 if (key
.equals(Tag
.EXTRA_FIELD_NAME
)) {
104 // If tag extra field name, save the extra field name for
105 // the next extra field value and add the field to the map
106 fLastExtraFieldName
= value
;
107 if (!fData
.containsKey(value
)) {
108 fData
.put(value
, null);
111 } else if (key
.equals(Tag
.EXTRA_FIELD_VALUE
)) {
112 // If tag extra field value, use the extra field name as key
113 if (fLastExtraFieldName
== null) {
116 key
= fLastExtraFieldName
;
118 if (column
.action
== CustomTraceDefinition
.ACTION_SET
) {
119 fData
.put(key
, value
);
120 if (key
.equals(Tag
.TIMESTAMP
)) {
121 fData
.put(Key
.TIMESTAMP_INPUT_FORMAT
, column
.format
);
123 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
124 String s
= fData
.get(key
);
126 fData
.put(key
, s
+ value
);
128 fData
.put(key
, value
);
130 if (key
.equals(Tag
.TIMESTAMP
)) {
131 String timeStampInputFormat
= fData
.get(Key
.TIMESTAMP_INPUT_FORMAT
);
132 if (timeStampInputFormat
!= null) {
133 fData
.put(Key
.TIMESTAMP_INPUT_FORMAT
, timeStampInputFormat
+ column
.format
);
135 fData
.put(Key
.TIMESTAMP_INPUT_FORMAT
, column
.format
);
138 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
139 String s
= fData
.get(key
);
141 fData
.put(key
, s
+ CustomTraceDefinition
.SEPARATOR
+ value
);
143 fData
.put(key
, value
);
145 if (key
.equals(Tag
.TIMESTAMP
)) {
146 String timeStampInputFormat
= fData
.get(Key
.TIMESTAMP_INPUT_FORMAT
);
147 if (timeStampInputFormat
!= null) {
148 fData
.put(Key
.TIMESTAMP_INPUT_FORMAT
, timeStampInputFormat
+ " | " + column
.format
); //$NON-NLS-1$
150 fData
.put(Key
.TIMESTAMP_INPUT_FORMAT
, column
.format
);