|
1 /* |
|
2 * Copyright (c) 2007-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 * VariableTracingProcessor DataProcessor |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.engine.dataprocessor; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.List; |
|
23 |
|
24 import com.nokia.traceviewer.TraceViewerPlugin; |
|
25 import com.nokia.traceviewer.action.TraceViewerActionUtils; |
|
26 import com.nokia.traceviewer.dialog.VariableTracingDialog; |
|
27 import com.nokia.traceviewer.dialog.treeitem.TreeItem; |
|
28 import com.nokia.traceviewer.dialog.treeitem.TreeItemContentProvider; |
|
29 import com.nokia.traceviewer.dialog.treeitem.TreeItemListener; |
|
30 import com.nokia.traceviewer.dialog.treeitem.VariableTracingTreeBaseItem; |
|
31 import com.nokia.traceviewer.dialog.treeitem.VariableTracingTreeItem; |
|
32 import com.nokia.traceviewer.dialog.treeitem.VariableTracingTreeTextItem; |
|
33 import com.nokia.traceviewer.engine.TraceProperties; |
|
34 import com.nokia.traceviewer.engine.TraceViewerGlobals; |
|
35 import com.nokia.traceviewer.engine.TraceViewerPropertyViewInterface; |
|
36 import com.nokia.traceviewer.engine.TraceViewerDialogInterface.Dialog; |
|
37 import com.nokia.traceviewer.engine.preferences.PreferenceConstants; |
|
38 import com.nokia.traceviewer.engine.preferences.XMLVariableTracingConfigurationImporter; |
|
39 |
|
40 /** |
|
41 * VariableTracing DataProcessor |
|
42 * |
|
43 */ |
|
44 public final class VariableTracingProcessor implements DataProcessor { |
|
45 |
|
46 /** |
|
47 * Interval how often to update progressbar |
|
48 */ |
|
49 private static final int PROGRESSBAR_UPDATE_INTERVAL = 100; |
|
50 |
|
51 /** |
|
52 * Variable Tracing dialog used in setting rules |
|
53 */ |
|
54 private VariableTracingDialog variableTracingDialog; |
|
55 |
|
56 /** |
|
57 * Content provider for the dialog |
|
58 */ |
|
59 private TreeItemContentProvider contentProvider; |
|
60 |
|
61 /** |
|
62 * First visible object in the dialog tree |
|
63 */ |
|
64 private TreeItem root; |
|
65 |
|
66 /** |
|
67 * List of variable tracing items |
|
68 */ |
|
69 private final List<VariableTracingItem> variableTracingItems; |
|
70 |
|
71 /** |
|
72 * Text rules that are applied |
|
73 */ |
|
74 private final List<VariableTracingTreeTextItem> textRules; |
|
75 |
|
76 /** |
|
77 * Constructor |
|
78 */ |
|
79 public VariableTracingProcessor() { |
|
80 createInitialTree(); |
|
81 variableTracingItems = new ArrayList<VariableTracingItem>(); |
|
82 textRules = new ArrayList<VariableTracingTreeTextItem>(); |
|
83 |
|
84 } |
|
85 |
|
86 /** |
|
87 * Creates initial tree |
|
88 */ |
|
89 public void createInitialTree() { |
|
90 contentProvider = new TreeItemContentProvider(); |
|
91 // Create root node |
|
92 TreeItem treeRoot = new VariableTracingTreeBaseItem(contentProvider, |
|
93 null, "root", VariableTracingTreeItem.Rule.GROUP); //$NON-NLS-1$ |
|
94 root = new VariableTracingTreeBaseItem(contentProvider, treeRoot, |
|
95 TraceViewerPlugin.getDefault().getPreferenceStore().getString( |
|
96 PreferenceConstants.CONFIGURATION_FILE), |
|
97 VariableTracingTreeItem.Rule.GROUP); |
|
98 treeRoot.addChild(root); |
|
99 } |
|
100 |
|
101 /** |
|
102 * Imports line count rules from configuration file |
|
103 */ |
|
104 public void importVariableTracingRules() { |
|
105 // Import rules |
|
106 XMLVariableTracingConfigurationImporter importer = new XMLVariableTracingConfigurationImporter( |
|
107 root, TraceViewerPlugin.getDefault().getPreferenceStore() |
|
108 .getString(PreferenceConstants.CONFIGURATION_FILE), |
|
109 true); |
|
110 importer.importData(); |
|
111 } |
|
112 |
|
113 /* |
|
114 * (non-Javadoc) |
|
115 * |
|
116 * @see |
|
117 * com.nokia.traceviewer.engine.DataProcessor#processData(com.nokia.traceviewer |
|
118 * .engine.TraceProperties) |
|
119 */ |
|
120 public void processData(TraceProperties properties) { |
|
121 if (!properties.traceConfiguration.isScrolledTrace() |
|
122 && !properties.traceConfiguration.isFilteredOut() |
|
123 && !properties.traceConfiguration.isTriggeredOut()) { |
|
124 int len = variableTracingItems.size(); |
|
125 if (len > 0) { |
|
126 |
|
127 // Loop through variable tracing items |
|
128 VariableTracingItem item; |
|
129 for (int i = 0; i < len; i++) { |
|
130 item = variableTracingItems.get(i); |
|
131 |
|
132 String traceLine = ""; //$NON-NLS-1$ |
|
133 |
|
134 // Traces missing |
|
135 if (properties.bTraceInformation.isTraceMissing()) { |
|
136 traceLine = TraceViewerActionUtils.TRACES_DROPPED_MSG; |
|
137 } |
|
138 if (properties.traceString != null) { |
|
139 traceLine += properties.traceString; |
|
140 } |
|
141 |
|
142 String rule = item.getTextToCompare(); |
|
143 if (rule == null) { |
|
144 break; |
|
145 } |
|
146 |
|
147 String checkString = traceLine; |
|
148 if (!item.isMatchCase()) { |
|
149 checkString = checkString.toLowerCase(); |
|
150 } |
|
151 |
|
152 // Line hits |
|
153 if (checkString.contains(rule)) { |
|
154 VariableTracingEvent event = new VariableTracingEvent( |
|
155 item, |
|
156 properties.timestampString, |
|
157 traceLine.substring(checkString.indexOf(rule) |
|
158 + rule.length()), |
|
159 TraceViewerGlobals.getTraceViewer() |
|
160 .getDataReaderAccess() |
|
161 .getCurrentDataReader().getTraceCount(), |
|
162 properties.information); |
|
163 item.addEvent(event); |
|
164 item.setChanged(true); |
|
165 TraceViewerPropertyViewInterface view = TraceViewerGlobals |
|
166 .getTraceViewer().getPropertyView(); |
|
167 if (view != null) { |
|
168 view.setVariableTracingTableChanged(); |
|
169 } |
|
170 } |
|
171 } |
|
172 |
|
173 // Update progressbar if needed |
|
174 updateProgressBar(); |
|
175 } |
|
176 } |
|
177 } |
|
178 |
|
179 /** |
|
180 * Update progressbar if needed |
|
181 */ |
|
182 private void updateProgressBar() { |
|
183 // Update possible progressBar |
|
184 if (isProcessingTracing() |
|
185 && TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
186 .getCurrentDataReader().getTraceCount() |
|
187 % PROGRESSBAR_UPDATE_INTERVAL == 0) { |
|
188 |
|
189 variableTracingDialog.getProgressBar().updateProgressBar( |
|
190 TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
191 .getCurrentDataReader().getTraceCount()); |
|
192 } |
|
193 } |
|
194 |
|
195 /** |
|
196 * Tells if initial tracing is in process |
|
197 * |
|
198 * @return true if initial tracing is in progress |
|
199 */ |
|
200 public boolean isProcessingTracing() { |
|
201 return (variableTracingDialog != null |
|
202 && variableTracingDialog.getProgressBar() != null |
|
203 && variableTracingDialog.getProgressBar().getShell() != null && !variableTracingDialog |
|
204 .getProgressBar().getShell().isDisposed()); |
|
205 } |
|
206 |
|
207 /** |
|
208 * Gets variable tracing dialog |
|
209 * |
|
210 * @return variable tracing dialog |
|
211 */ |
|
212 public VariableTracingDialog getVariableTracingDialog() { |
|
213 if (variableTracingDialog == null) { |
|
214 variableTracingDialog = (VariableTracingDialog) TraceViewerGlobals |
|
215 .getTraceViewer().getDialogs().createDialog( |
|
216 Dialog.VARIABLETRACING); |
|
217 } |
|
218 return variableTracingDialog; |
|
219 } |
|
220 |
|
221 /** |
|
222 * Gets root of the tree |
|
223 * |
|
224 * @return root |
|
225 */ |
|
226 public TreeItem getRoot() { |
|
227 return root; |
|
228 } |
|
229 |
|
230 /** |
|
231 * Gets item listener |
|
232 * |
|
233 * @return the contentProvider |
|
234 */ |
|
235 public TreeItemListener getTreeItemListener() { |
|
236 return contentProvider; |
|
237 } |
|
238 |
|
239 /** |
|
240 * Gets VariableTracingItems |
|
241 * |
|
242 * @return the VariableTracingItems |
|
243 */ |
|
244 public List<VariableTracingItem> getVariableTracingItems() { |
|
245 return variableTracingItems; |
|
246 } |
|
247 |
|
248 /** |
|
249 * Empty variablesTracingItems |
|
250 */ |
|
251 public void emptyVariableTracingItems() { |
|
252 for (int i = 0; i < variableTracingItems.size(); i++) { |
|
253 variableTracingItems.get(i).clear(); |
|
254 variableTracingItems.get(i).setChanged(true); |
|
255 } |
|
256 } |
|
257 |
|
258 /** |
|
259 * Gets text rules |
|
260 * |
|
261 * @return text rules |
|
262 */ |
|
263 public List<VariableTracingTreeTextItem> getTextRules() { |
|
264 return textRules; |
|
265 } |
|
266 |
|
267 /** |
|
268 * Enable variabletracing rule |
|
269 * |
|
270 * @param item |
|
271 * the rule item |
|
272 */ |
|
273 public void enableRule(VariableTracingTreeItem item) { |
|
274 if (item instanceof VariableTracingTreeTextItem) { |
|
275 VariableTracingTreeTextItem item2 = (VariableTracingTreeTextItem) item; |
|
276 VariableTracingItem newItem = new VariableTracingItem(item2 |
|
277 .getName(), item2.getText(), item2.isMatchCase(), item2 |
|
278 .getHistoryCount()); |
|
279 textRules.add((VariableTracingTreeTextItem) item); |
|
280 variableTracingItems.add(newItem); |
|
281 } |
|
282 |
|
283 if (TraceViewerGlobals.getTraceViewer().getPropertyView() != null) { |
|
284 TraceViewerGlobals.getTraceViewer().getPropertyView() |
|
285 .createNewPropertyTableItems(); |
|
286 } |
|
287 } |
|
288 } |