Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1985d481d5cc66a733c3843d7a78c1ea5e652d11 (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
/*******************************************************************************
 * Copyright (c) 2010-2013 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:
 *     Red Hat - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.internal.threadprofiler.graphs;

import java.util.Iterator;

import org.eclipse.linuxtools.internal.threadprofiler.DataPoint;
import org.eclipse.swt.graphics.GC;

public class ThreadGraph extends GraphModel{

	private int tid;
	private DataPoint dp;
	private boolean empty;
	
	public ThreadGraph(String name, int tid) {
		super(name, "", 0, 0, 0);
		this.tid = tid;
		empty = false;
	}
 	
	public ThreadGraph(String name, String units, int x, int y, int type, int tid) {
		super(name, units, x, y, type);
 		this.tid = tid;
		empty = false;
 	}
 	
 	public int getTid() {
 		return tid;
 	}
	
	/**
	 * Returns true if this graph has data points and they are all empty
	 * 
	 * @return
	 */
	public boolean isEmpty() {
		return empty;
	}
	
	@Override
	public void draw(GC gc) {
		double increment = getXIncrement(gc);

		//Each thread should only have one buffer
		Iterator<DataPoint> buffer = data.get(0).getIterator();
		double xPos = this.getXOffset();
		empty = true;
		if (!buffer.hasNext())
			empty = false;
		double temp = 0;
		while (buffer.hasNext()) {
			DataPoint p = buffer.next();
			if (p.getType() == DataPoint.THREAD_ACTIVE) {
				temp += increment;
				empty = false;
			} else {
				if (temp != 0) {
					gc.drawLine((int) (xPos + 0.5), getYOffset(), (int) (xPos + temp + 0.5), getYOffset());
					xPos += temp;
					temp = 0;
				} else {
					xPos += increment;
				}
			}
		}
		gc.drawLine((int) (xPos + 0.5), getYOffset(), (int) (xPos + temp + 0.5), getYOffset());
	}

	public void addPoint() {
		dp = new DataPoint(0, 0, DataPoint.THREAD_ACTIVE);
	}
	
	public void tick() {
		//TODO: This method of updating requires passing around a bulky datapoint variable
		if (dp != null)
			add(dp, 0);
		else {
			add(new DataPoint(0, 0, DataPoint.THREAD_INACTIVE), 0);
		}
		dp = null;
 	}
 
 }

Back to the top