Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f226e4e60324d56e87f53300a6988b513412b805 (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
/*******************************************************************************
 * Copyright (c) 2004,2009 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Keith Seitz <keiths@redhat.com> - initial API and implementation
 *    Kent Sebastian <ksebasti@redhat.com>
 *******************************************************************************/ 
package org.eclipse.linuxtools.internal.oprofile.core.opxml.info;

import org.eclipse.linuxtools.internal.oprofile.core.daemon.OpInfo;
import org.eclipse.linuxtools.internal.oprofile.core.opxml.OprofileSAXHandler;
import org.eclipse.linuxtools.internal.oprofile.core.opxml.XMLProcessor;
import org.xml.sax.Attributes;


/**
 * Opxml processor for the "info" command.
 * @see org.eclipse.linuxtools.internal.oprofile.core.opxml.OpxmlRunner
 */
public class OpInfoProcessor extends XMLProcessor {
	// Other XMLProcessors used by this processor
	private DefaultsProcessor _defaultsProc;
	private EventListProcessor _eventListProc;
	
	// XML tags processed by this processor
	public static final String NUM_COUNTERS_TAG = "num-counters"; //$NON-NLS-1$
	public static final String DEFAULTS_TAG = "defaults"; //$NON-NLS-1$
	public static final String EVENT_LIST_TAG = "event-list"; //$NON-NLS-1$
	public static final String CPU_FREQUENCY_TAG = "cpu-frequency"; //$NON-NLS-1$
	public static final String TIMER_MODE = "timer-mode";  //$NON-NLS-1$

	public OpInfoProcessor() {
		_defaultsProc = new DefaultsProcessor();
		_eventListProc = new EventListProcessor();
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.linuxtools.internal.oprofile.core.opxml.XMLProcessor#startElement(java.lang.String, org.xml.sax.Attributes, java.lang.Object)
	 */
	public void startElement(String name, Attributes attrs, Object callData) {
		if (name.equals(DEFAULTS_TAG)) {
			OprofileSAXHandler.getInstance(callData).push(_defaultsProc);
		} else if (name.equals(EVENT_LIST_TAG)) {
			OprofileSAXHandler.getInstance(callData).push(_eventListProc);
			_eventListProc.startElement(name, attrs, callData);
		} else {
			super.startElement(name, attrs, callData);
		}
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.linuxtools.internal.oprofile.core.opxml.XMLProcessor#endElement(java.lang.String, java.lang.Object)
	 */
	public void endElement(String name, Object callData) {
		if (name.equals(CPU_FREQUENCY_TAG)) {
			double speed = Double.parseDouble(characters);
			OpInfo info = (OpInfo) callData;
			info.setCPUSpeed(speed);
		} else if (name.equals(TIMER_MODE)) {
			boolean timerMode = Boolean.parseBoolean(characters);
			OpInfo info = (OpInfo) callData;
			info.setTimerMode(timerMode);
		} else if (name.equals(NUM_COUNTERS_TAG)) {
			int numCounters = 0;
			try {
				numCounters = Integer.parseInt(characters);
			} catch (NumberFormatException nfe) {
			}
			OpInfo info = (OpInfo) callData;
			info.setNrCounters(numCounters);
		} else if (name.equals(EVENT_LIST_TAG)) {
			OpInfo info = (OpInfo) callData;
			info.setEvents(_eventListProc.getCounterNum(), _eventListProc.getEvents());
		}
	}
}

Back to the top