Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9332112ce33a23edf617eb1e45543bf3ebb3e3ae (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
/*******************************************************************************
 * Copyright (c) 2008, 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:
 *    Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
 *******************************************************************************/

package org.eclipse.linuxtools.internal.oprofile.core.model;

import org.eclipse.linuxtools.internal.oprofile.core.Oprofile;

/**
 * A root node for the data model. Only one instance exists at any time,
 * although the contents will change. On instantiation the events and sessions
 * are gathered.
 *
 * Note that this data model does not map 1:1 to the oprofile data model. This
 * model is for use in profiling one application compiled with debug info, from
 * within eclipse.
 */

public class OpModelRoot {
	// single instance
	private static OpModelRoot modelRoot = new OpModelRoot();

	private OpModelSession[] session;

	protected OpModelRoot() {
		session = null;
	}

	public static OpModelRoot getDefault() {
		return modelRoot;
	}

	public void refreshModel() {
		// TODO-performance/interactivity: some persistence for events/sessions
		// that dont change from run to run (non default sessions)

		session = getNewSessions();
		if (session != null) {
			for (int i = 0; i < session.length; i++) {
				if (session[i] != null)
					session[i].refreshModel();
			}
		}
	}

	/**
	 * return list of session collected on this system as well as events under each
	 * of them.
	 * 
	 * @return collected sessions list
	 * @since 3.0
	 */
	protected OpModelSession[] getNewSessions() {
		// launch `opxml sessions`, gather up events & the sessions under them
		return Oprofile.getSessions();
	}

	public OpModelSession[] getSessions() {
		return session;
	}

	@Override
	public String toString() {
		String s = ""; //$NON-NLS-1$
		if (session != null) {
			for (int i = 0; i < session.length; i++) {
				if (session[i] != null) {
					s += "Session: "; //$NON-NLS-1$
					s += session[i].toString("\t"); //$NON-NLS-1$
				}
			}
		}
		return s;
	}
}

Back to the top