blob: d44a510786470564665378e083d08c3db8fe1f02 (
plain) (
blame)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*******************************************************************************
* Copyright (c) 2004, 2018 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Keith Seitz <keiths@redhat.com> - initial API and implementation
* Kent Sebastian <ksebasti@redhat.com> -
*******************************************************************************/
package org.eclipse.linuxtools.internal.oprofile.core.opxml.modeldata;
import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage;
import org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler;
import org.eclipse.linuxtools.internal.oprofile.core.opxml.XMLProcessor;
import org.xml.sax.Attributes;
/**
* A processor for `opxml samples`.
*/
public class ModelDataProcessor extends XMLProcessor {
// The resulting image compiled by the processor to be used by the caller.
public static class CallData {
public OpModelImage opModelImage;
public CallData(OpModelImage im) {
opModelImage = im;
}
}
// XML tags parsed by this processor
private static final String IMAGE_TAG = "image"; //$NON-NLS-1$
private static final String SYMBOLS_TAG = "symbols"; //$NON-NLS-1$
private static final String DEPENDENT_TAG = "dependent"; //$NON-NLS-1$
// attribute tags
private static final String ATTR_IMAGENAME = "name"; //$NON-NLS-1$
private static final String ATTR_COUNT = "count"; //$NON-NLS-1$
private static final String ATTR_DEPCOUNT = "count"; //$NON-NLS-1$
// the current image being constructed
private OpModelImage image;
private int imgSeen; // for ensuring image singleton-ness
// processors used for symbols and dependent images
private SymbolsProcessor _symbolsProcessor = new SymbolsProcessor();
private DependentProcessor _dependentProcessor = new DependentProcessor();
@Override
public void reset(Object callData) {
image = ((CallData) callData).opModelImage;
imgSeen = 0;
}
@Override
public void startElement(String name, Attributes attrs, Object callData) {
if (name.equals(IMAGE_TAG)) {
if (imgSeen == 0) {
image.setName(validString(attrs.getValue(ATTR_IMAGENAME)));
image.setCount(Integer.parseInt(attrs.getValue(ATTR_COUNT)));
}
imgSeen++;
} else if (name.equals(SYMBOLS_TAG)) {
OprofileSAXHandler.getInstance(callData).push(_symbolsProcessor);
} else if (name.equals(DEPENDENT_TAG)) {
image.setDepCount(Integer.parseInt(attrs.getValue(ATTR_DEPCOUNT)));
OprofileSAXHandler.getInstance(callData).push(_dependentProcessor);
} else {
super.startElement(name, attrs, callData);
}
}
@Override
public void endElement(String name, Object callData) {
if (name.equals(IMAGE_TAG)) {
if (imgSeen > 1) {
// should only ever be one image, otherwise oprofile was run
// outside of eclipse and the ui would not handle it properly
image.setCount(OpModelImage.IMAGE_PARSE_ERROR);
image.setDepCount(0);
image.setDependents(null);
image.setSymbols(null);
image.setName(""); //$NON-NLS-1$
}
} else if (name.equals(SYMBOLS_TAG)) {
image.setSymbols(_symbolsProcessor.getSymbols());
} else if (name.equals(DEPENDENT_TAG)) {
image.setDependents(_dependentProcessor.getImages());
} else {
super.endElement(name, callData);
}
}
}
|