Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f5d19dfab470c55a2c5907d23fdba9207612ec15 (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
/*******************************************************************************
 * Copyright (c) 2008 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:
 *    Kent Sebastian <ksebasti@redhat.com> - initial API and implementation 
 *******************************************************************************/ 
package org.eclipse.linuxtools.internal.oprofile.ui.model;

import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage;
import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelSymbol;
import org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiMessages;
import org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiPlugin;
import org.eclipse.swt.graphics.Image;

/**
 * Children of sessions in the view -- the binary which was profiled. 
 * May or may not have child symbols. Note that although the dependent
 * images are children of OpModelImages in the data model, for usability's
 * sake they are children of the parent session in the tree.
 */
public class UiModelImage implements IUiModelElement {
	private IUiModelElement _parent;		//parent element, may be UiModelSession or UiModelDependent
	private OpModelImage _image;			//the node in the data model
	private UiModelSymbol _symbols[];		//this node's child (symbols)
	private int _totalCount;				//total number of samples 
	private int _depCount;					//number of samples from dependent images

	public UiModelImage(IUiModelElement parent, OpModelImage image, int totalCount, int depCount) {
		_parent = parent;
		_image = image;
		_symbols = null;
		_totalCount = totalCount;
		_depCount = depCount;
		refreshModel();
	}

	private void refreshModel() {
		OpModelSymbol[] dataModelSymbols = _image.getSymbols();
		
		//dependent images may not have symbols
		if (dataModelSymbols != null) {
			_symbols = new UiModelSymbol[dataModelSymbols.length];
	
			for (int i = 0; i < dataModelSymbols.length; i++) {
				_symbols[i] = new UiModelSymbol(this, dataModelSymbols[i], _totalCount);
			}
		}
	}
	
	@Override
	public String toString() {
		if (_image.getCount() == OpModelImage.IMAGE_PARSE_ERROR) {
			return OprofileUiMessages.getString("opxmlParse.error.multipleImages"); //$NON-NLS-1$
		} else {
			double countPercentage = (double)(_image.getCount() - _depCount) / (double)_totalCount;
			String percentage = OprofileUiPlugin.getPercentageString(countPercentage);
			
			return percentage + " " + OprofileUiMessages.getString("uimodel.percentage.in") + _image.getName(); //$NON-NLS-1$ //$NON-NLS-2$
		}
	}
	
	/** IUiModelElement functions **/
	public String getLabelText() {
		return toString();
	}

	public IUiModelElement[] getChildren() {
		IUiModelElement children[] = null;
		
		if (_symbols != null) {
			children = new IUiModelElement[_symbols.length];
			
			for (int i = 0; i < _symbols.length; i++) {
				children[i] = _symbols[i];
			}
		}
		
		return children;
	}

	public boolean hasChildren() {
		return (_symbols == null || _symbols.length == 0 ? false : true);
	}

	public IUiModelElement getParent() {
		return _parent;
	}

	public Image getLabelImage() {
		return OprofileUiPlugin.getImageDescriptor(OprofileUiPlugin.IMAGE_ICON).createImage();
	}
}

Back to the top