1
diff --git a/ThreadProfile.stp b/ThreadProfile.stp
2
index 4d7fe50..daab497 100644
3
--- a/ThreadProfile.stp
4
+++ b/ThreadProfile.stp
5
@@ -39,31 +39,30 @@ probe process(@1).function("*").call {
9
+ if (! threadcounters[tid()] ) {
10
+ threadstacks[tid()] = probefunc();
12
threadcounters[tid()]++;
13
- threadstacks[tid(),threadcounters[tid()]] = probefunc();
16
probe process(@1).function("*").return {
17
- delete(threadstacks[tid(),threadcounters[tid()]]);
18
- if (threadcounters[tid()] == 1) {
19
+ threadcounters[tid()]--;
20
+ if (! threadcounters[tid()]) {
21
delete(threadcounters[tid()]);
22
- delete(threadstacks[tid(),0]);
23
+ delete(threadstacks[tid()]);
26
- threadcounters[tid()]--;
30
# ------------------------------------------------------------------------
31
# general gnuplot graphical report generation
33
-probe timer.ms(500) {
34
+probe timer.ms(100) {
36
printf("%d, %d, %d, %d, %d, %d, %d, %d\n", counter, qsq_util_reset("cpu"), qsq_util_reset("ioblock"), proc_mem_size() * mem_page_size(), proc_mem_data() * mem_page_size(), reads + writes, reads, writes);
37
foreach (tid in threadcounters) {
38
- printf("%d:%s\n", tid, threadstacks[tid, 1]);
39
+ printf("%d:%s\n", tid, threadstacks[tid]);
45
diff --git a/bin/org/eclipse/linuxtools/threadprofiler/DataPoint.class b/bin/org/eclipse/linuxtools/threadprofiler/DataPoint.class
46
index a620579..9f26a69 100644
47
Binary files a/bin/org/eclipse/linuxtools/threadprofiler/DataPoint.class and b/bin/org/eclipse/linuxtools/threadprofiler/DataPoint.class differ
48
diff --git a/bin/org/eclipse/linuxtools/threadprofiler/ThreadProfilerParser.class b/bin/org/eclipse/linuxtools/threadprofiler/ThreadProfilerParser.class
49
index 2876d9d..a35972d 100644
50
Binary files a/bin/org/eclipse/linuxtools/threadprofiler/ThreadProfilerParser.class and b/bin/org/eclipse/linuxtools/threadprofiler/ThreadProfilerParser.class differ
51
diff --git a/bin/org/eclipse/linuxtools/threadprofiler/ThreadProfilerView.class b/bin/org/eclipse/linuxtools/threadprofiler/ThreadProfilerView.class
52
index 2015b3b..924310a 100644
53
Binary files a/bin/org/eclipse/linuxtools/threadprofiler/ThreadProfilerView.class and b/bin/org/eclipse/linuxtools/threadprofiler/ThreadProfilerView.class differ
54
diff --git a/src/org/eclipse/linuxtools/threadprofiler/DataPoint.java b/src/org/eclipse/linuxtools/threadprofiler/DataPoint.java
55
index 8deb632..cac1b2d 100644
56
--- a/src/org/eclipse/linuxtools/threadprofiler/DataPoint.java
57
+++ b/src/org/eclipse/linuxtools/threadprofiler/DataPoint.java
59
package org.eclipse.linuxtools.internal.threadprofiler;
61
public class DataPoint {
63
+ /** Indicates that this is a raw data point */
64
public static final int DATA_POINT = 0;
66
+ /** Indicates that this is a point relative to the axis */
67
public static final int AXIS_POINT = 1;
69
+ /** Indicates that this is an absolute pixel point */
70
public static final int PIXEL_POINT = 2;
72
+ /** Inactive, do not draw this point */
73
+ public static final int INACTIVE = 0;
75
+ /** Active, draw this point */
76
+ public static final int ACTIVE = 1;
81
diff --git a/src/org/eclipse/linuxtools/threadprofiler/ThreadGraph.java b/src/org/eclipse/linuxtools/threadprofiler/ThreadGraph.java
82
index 9cc6ec7..f6c5dec 100644
83
--- a/src/org/eclipse/linuxtools/threadprofiler/ThreadGraph.java
84
+++ b/src/org/eclipse/linuxtools/threadprofiler/ThreadGraph.java
86
package org.eclipse.linuxtools.internal.threadprofiler;
88
-public class ThreadGraph {
90
- private final String name;
91
- private final int tid;
92
+import java.util.Iterator;
94
+import org.eclipse.linuxtools.internal.threadprofiler.graphs.GraphModel;
95
+import org.eclipse.swt.graphics.GC;
96
+import org.eclipse.swt.widgets.Composite;
98
+public class ThreadGraph extends GraphModel{
101
+ private DataPoint dp;
102
+ private boolean empty;
104
- public ThreadGraph(int tid, String name) {
106
+ public ThreadGraph(String name, int x, int y, int type, String units, int tid) {
107
+ super(name, x, y, type, units);
112
public int getTid() {
116
- public String getName() {
118
+ private void setEmpty(boolean val) {
123
+ * Returns true if this graph has data points and they are all empty
127
+ public boolean isEmpty() {
132
+ public void drawOn(GC gc, Composite graphCanvas) {
133
+ int increment = (graphCanvas.getSize().x - this.getXOffset())/GraphModel.BUFFER_SIZE;
135
+ //Each thread should only have one buffer
136
+ Iterator<DataPoint> buffer = data.get(0).getIterator();
137
+ int xPos = this.getXOffset();
139
+ if (!buffer.hasNext())
141
+ while (buffer.hasNext()) {
142
+ DataPoint p = buffer.next();
143
+ if (p.getType() == DataPoint.ACTIVE) {
145
+ gc.drawLine(xPos, getYOffset(), xPos + increment, getYOffset());
153
+ public void prep(DataPoint dataPoint, int i) {
157
+ public void tick() {
158
+ //TODO: This method if updating requires passing around a bulky datapoint variable
162
+ add(new DataPoint(0, 0, DataPoint.INACTIVE), 0);
168
diff --git a/src/org/eclipse/linuxtools/threadprofiler/ThreadProfilerParser.java b/src/org/eclipse/linuxtools/threadprofiler/ThreadProfilerParser.java
169
index d9dac71..6fcd306 100644
170
--- a/src/org/eclipse/linuxtools/threadprofiler/ThreadProfilerParser.java
171
+++ b/src/org/eclipse/linuxtools/threadprofiler/ThreadProfilerParser.java
172
@@ -33,21 +33,20 @@ public class ThreadProfilerParser extends SystemTapParser {
173
boolean changed = false;
175
while ((line = buff.readLine()) != null) {
176
- System.out.println("Parsed: " + line);
177
+// System.out.println("Parsed: " + line);
179
- if (line.equals("--"))
180
+ if (line.equals("--")) {
181
+ ((ThreadProfilerView) view).closeThreads();
184
if (line.contains(", ")) {
185
String[] blargh = line.split(", ");
186
- ((ThreadProfilerView) view).addNextCPUPoint(counter, blargh);
187
- ((ThreadProfilerView) view).addNextMemoryPoint(counter++, blargh);
188
- ((ThreadProfilerView) view).addNextDiskPoint(counter++, blargh);
189
+ ((ThreadProfilerView) view).addDataPoints(counter++, blargh);
191
String[] data = line.split(":");
192
int tid = Integer.parseInt(data[0]);
193
((ThreadProfilerView) view).addThread(tid, data[1]);
197
if (changed) view.update();
198
} catch (NumberFormatException e) {
199
diff --git a/src/org/eclipse/linuxtools/threadprofiler/ThreadProfilerView.java b/src/org/eclipse/linuxtools/threadprofiler/ThreadProfilerView.java
200
index 2dbaaf7..40b7460 100644
201
--- a/src/org/eclipse/linuxtools/threadprofiler/ThreadProfilerView.java
202
+++ b/src/org/eclipse/linuxtools/threadprofiler/ThreadProfilerView.java
204
-package org.eclipse.linuxtools.internal.threadprofiler;
206
-import java.util.ArrayList;
208
-import org.eclipse.core.runtime.IProgressMonitor;
209
-import org.eclipse.core.runtime.IStatus;
210
-import org.eclipse.core.runtime.Status;
211
-import org.eclipse.linuxtools.callgraph.core.SystemTapView;
212
-import org.eclipse.linuxtools.internal.threadprofiler.graphs.GraphModel;
213
-import org.eclipse.linuxtools.internal.threadprofiler.graphs.MultiGraph;
214
-import org.eclipse.swt.SWT;
215
-import org.eclipse.swt.custom.ScrolledComposite;
216
-import org.eclipse.swt.events.MouseEvent;
217
-import org.eclipse.swt.events.MouseListener;
218
-import org.eclipse.swt.events.PaintEvent;
219
-import org.eclipse.swt.events.PaintListener;
220
-import org.eclipse.swt.graphics.Color;
221
-import org.eclipse.swt.graphics.GC;
222
-import org.eclipse.swt.layout.GridData;
223
-import org.eclipse.swt.layout.GridLayout;
224
-import org.eclipse.swt.widgets.Button;
225
-import org.eclipse.swt.widgets.Canvas;
226
-import org.eclipse.swt.widgets.Composite;
227
-import org.eclipse.swt.widgets.Display;
229
-public class ThreadProfilerView extends SystemTapView {
230
- private static final int CPU_BUFFER = 0;
231
- private static final int MEM_BUFFER = 1;
232
- private static final int DISK_BUFFER = 2;
233
- private ArrayList<GraphModel> graphs;
234
- private ArrayList<ThreadGraph> threads;
236
- private Composite graphCanvas;
237
- private Canvas threadCanvas;
238
- private final long REFRESH_TIME_MS = 700;
239
- private final static int GRAPH_SEPARATION = 40;
241
- private int segments;
244
- * We have two frames of reference:
246
- * 1. Pixel frame (absolute frame)
247
- * 2. Axis frame (relative frame)
249
- * The transformation from 1 to 2 is a coordinate shift and scale
255
- protected boolean createOpenAction() {
260
- protected boolean createOpenDefaultAction() {
265
- public IStatus initializeView(Display targetDisplay,
266
- IProgressMonitor monitor) {
267
- if (graphs == null)
268
- graphs = new ArrayList<GraphModel>();
269
- if (threads == null)
270
- threads = new ArrayList<ThreadGraph>();
275
- //Create dataSet for CPU
276
- createNewDataSet("CPU", GraphModel.CONSTANT_Y, "%");
277
- ((MultiGraph) graphs.get(0)).addBuffer(GraphModel.BUFFER_SIZE, "Total");
278
- ((MultiGraph) graphs.get(0)).addBuffer(GraphModel.BUFFER_SIZE, "IO Block");
280
- //Create dataSet for memory
281
- createNewDataSet("Memory", GraphModel.FLEXIBLE_Y, "bytes");
282
- ((MultiGraph) graphs.get(1)).addBuffer(GraphModel.BUFFER_SIZE, "Total");
283
- ((MultiGraph) graphs.get(1)).addBuffer(GraphModel.BUFFER_SIZE, "Data");
285
- //Create dataSet for disk usage
286
- createNewDataSet("Disk", GraphModel.FLEXIBLE_Y, "bytes");
287
- ((MultiGraph) graphs.get(2)).addBuffer(GraphModel.BUFFER_SIZE, "Total");
288
- ((MultiGraph) graphs.get(2)).addBuffer(GraphModel.BUFFER_SIZE, "Read");
289
- ((MultiGraph) graphs.get(2)).addBuffer(GraphModel.BUFFER_SIZE, "Write");
290
- ((MultiGraph) graphs.get(2)).addStyle(MultiGraph.GRAPH_STYLE_FILL);
291
- ((MultiGraph) graphs.get(2)).addStyle(MultiGraph.GRAPH_STYLE_LINE);
292
- ((MultiGraph) graphs.get(2)).addStyle(MultiGraph.GRAPH_STYLE_LINE);
294
- time = System.currentTimeMillis();
296
- graphCanvas.addMouseListener(new MouseListener() {
299
- public void mouseDoubleClick(MouseEvent e) {
304
- public void mouseDown(MouseEvent e) {
305
- System.out.println("LOCATION: " + e.x + "," + e.y);
309
- public void mouseUp(MouseEvent e) {
310
- // TODO Auto-generated method stub
316
- graphCanvas.addPaintListener(new PaintListener() {
317
- public void paintControl(PaintEvent e) {
318
-// if (!graphs.get(0).isChanged())
322
- for (int i = 0; i < graphs.size(); i ++) {
323
- GraphModel graph = graphs.get(i);
324
- GC gc = new GC(graphCanvas);
325
- gc.setLineWidth(2);
326
- graph.setHeight((int) (graphCanvas.getSize().y/(2.5*graphs.size())));
327
- graph.setYAxisCoordinate((graph.getHeight() + GRAPH_SEPARATION) *(i + 1));
328
- graph.drawOn(gc, graphCanvas);
335
- threadCanvas.addPaintListener(new PaintListener() {
338
- public void paintControl(PaintEvent e) {
339
- if (threads == null)
343
- GC gc = new GC(threadCanvas);
344
- gc.setLineWidth(4);
345
- gc.setForeground(new Color(Display.getCurrent(), 0, 0, 200));
346
- int increment = (graphCanvas.getSize().x - 40)/GraphModel.BUFFER_SIZE;
348
- for (ThreadGraph tg : threads) {
349
- gc.drawText(tg.getName(), 40, yOffset);
350
- gc.drawLine(40, yOffset, 40 + increment*segments, yOffset);
356
- return Status.OK_STATUS;
359
- private void createNewDataSet(String name, int type, String units) {
360
- GraphModel graph = new MultiGraph(name, 50, (GraphModel.DEFAULT_HEIGHT + GRAPH_SEPARATION) *(graphs.size() + 1), type, units);
365
- public void setViewID() {
366
- viewID = "org.eclipse.linuxtools.internal.threadprofiler.ThreadProfilerView";
370
- public void updateMethod() {
371
- if (System.currentTimeMillis() - time < REFRESH_TIME_MS)
373
- time = System.currentTimeMillis();
374
- graphCanvas.redraw();
378
- public void createPartControl(Composite parent) {
379
- GridLayout gl = new GridLayout(1, true);
380
- parent.setLayout(gl);
381
- Color white = new Color(Display.getCurrent(), 255, 255, 255);
383
- graphCanvas = new Composite(parent, SWT.BORDER);
384
- graphCanvas.setBackground(white);
385
- GridData gd = new GridData(GridData.FILL_BOTH);
386
- gd.grabExcessHorizontalSpace = true;
387
- graphCanvas.setLayoutData(gd);
389
- threadCanvas = new Canvas(parent, SWT.BORDER);
390
- threadCanvas.setBackground(white);
391
- gd = new GridData(GridData.FILL_BOTH);
392
- gd.grabExcessHorizontalSpace = true;
393
- threadCanvas.setLayoutData(gd);
397
- public void setFocus() {
402
- public void addNextCPUPoint(int counter, String[] blargh) {
403
- if (blargh.length < 2)
405
- this.addPoint(new DataPoint(counter, Integer.parseInt(blargh[1]), 1), CPU_BUFFER, 0);
407
- if (blargh.length < 3)
409
- this.addPoint(new DataPoint(counter, Integer.parseInt(blargh[2]), 1), CPU_BUFFER, 1);
412
- public void addNextMemoryPoint(int counter, String[] blargh) {
413
- if (blargh.length < 4)
415
- this.addPoint(new DataPoint(counter, Integer.parseInt(blargh[3]), 1), MEM_BUFFER, 0);
416
- if (blargh.length < 5)
418
- this.addPoint(new DataPoint(counter, Integer.parseInt(blargh[4]), 1), MEM_BUFFER, 1);
421
- public void addNextDiskPoint(int counter, String[] blargh) {
422
- if (blargh.length < 6)
424
- addPoint(new DataPoint(counter, Integer.parseInt(blargh[5]), 1), DISK_BUFFER, 0);
426
- if (blargh.length < 7)
428
- addPoint(new DataPoint(counter, Integer.parseInt(blargh[6]), 1), DISK_BUFFER, 1);
430
- if (blargh.length < 8)
432
- addPoint(new DataPoint(counter, Integer.parseInt(blargh[7]), 1), DISK_BUFFER, 2);
435
- private void addPoint(DataPoint point, int dataSet, int subIndex) {
436
- if (graphs.size() < 1)
438
- if (segments < GraphModel.BUFFER_SIZE)
440
- graphs.get(dataSet).add(point, subIndex);
443
- public void addThread(int tid, String line) {
444
- if (!threadExists(tid)) {
445
- ThreadGraph tg = new ThreadGraph(tid, line);
451
- * Returns true if a thread with the given tid exists
456
- private boolean threadExists(int tid) {
457
- boolean exists = false;
458
- for (ThreadGraph g : threads) {
459
- if (g.getTid() == tid) {
468
+package org.eclipse.linuxtools.internal.threadprofiler;
470
+import java.util.ArrayList;
472
+import org.eclipse.core.resources.IContainer;
473
+import org.eclipse.core.runtime.IProgressMonitor;
474
+import org.eclipse.core.runtime.IStatus;
475
+import org.eclipse.core.runtime.Status;
476
+import org.eclipse.linuxtools.callgraph.core.SystemTapView;
477
+import org.eclipse.linuxtools.internal.threadprofiler.graphs.GraphModel;
478
+import org.eclipse.linuxtools.internal.threadprofiler.graphs.MultiGraph;
479
+import org.eclipse.swt.SWT;
480
+import org.eclipse.swt.custom.ScrolledComposite;
481
+import org.eclipse.swt.events.MouseEvent;
482
+import org.eclipse.swt.events.MouseListener;
483
+import org.eclipse.swt.events.PaintEvent;
484
+import org.eclipse.swt.events.PaintListener;
485
+import org.eclipse.swt.graphics.Color;
486
+import org.eclipse.swt.graphics.GC;
487
+import org.eclipse.swt.layout.GridData;
488
+import org.eclipse.swt.layout.GridLayout;
489
+import org.eclipse.swt.widgets.Canvas;
490
+import org.eclipse.swt.widgets.Composite;
491
+import org.eclipse.swt.widgets.Display;
493
+public class ThreadProfilerView extends SystemTapView {
494
+ private static final int CPU_BUFFER = 0;
495
+ private static final int MEM_BUFFER = 1;
496
+ private static final int DISK_BUFFER = 2;
498
+ private static final int START_X_POS = 50;
499
+ private ArrayList<GraphModel> graphs;
500
+ private ArrayList<ThreadGraph> threads;
502
+ private Composite graphCanvas;
503
+ private Canvas threadCanvas;
504
+ private final static int GRAPH_SEPARATION = 40;
505
+ private int segments;
508
+ * We have two frames of reference:
510
+ * 1. Pixel frame (absolute frame)
511
+ * 2. Axis frame (relative frame)
513
+ * The transformation from 1 to 2 is a coordinate shift and scale
519
+ protected boolean createOpenAction() {
524
+ protected boolean createOpenDefaultAction() {
529
+ public IStatus initializeView(Display targetDisplay,
530
+ IProgressMonitor monitor) {
531
+ if (graphs == null)
532
+ graphs = new ArrayList<GraphModel>();
533
+ if (threads == null)
534
+ threads = new ArrayList<ThreadGraph>();
539
+ //Create dataSet for CPU
540
+ createNewDataSet("CPU", GraphModel.CONSTANT_Y, "%");
541
+ ((MultiGraph) graphs.get(0)).addBuffer(GraphModel.BUFFER_SIZE, "Total");
542
+ ((MultiGraph) graphs.get(0)).addBuffer(GraphModel.BUFFER_SIZE, "IO Block");
544
+ //Create dataSet for memory
545
+ createNewDataSet("Memory", GraphModel.FLEXIBLE_Y, "bytes");
546
+ ((MultiGraph) graphs.get(1)).addBuffer(GraphModel.BUFFER_SIZE, "Total");
547
+ ((MultiGraph) graphs.get(1)).addBuffer(GraphModel.BUFFER_SIZE, "Data");
549
+ //Create dataSet for disk usage
550
+ createNewDataSet("Disk", GraphModel.FLEXIBLE_Y, "bytes");
551
+ ((MultiGraph) graphs.get(2)).addBuffer(GraphModel.BUFFER_SIZE, "Total");
552
+ ((MultiGraph) graphs.get(2)).addBuffer(GraphModel.BUFFER_SIZE, "Read");
553
+ ((MultiGraph) graphs.get(2)).addBuffer(GraphModel.BUFFER_SIZE, "Write");
554
+ ((MultiGraph) graphs.get(2)).addStyle(MultiGraph.GRAPH_STYLE_FILL);
555
+ ((MultiGraph) graphs.get(2)).addStyle(MultiGraph.GRAPH_STYLE_LINE);
556
+ ((MultiGraph) graphs.get(2)).addStyle(MultiGraph.GRAPH_STYLE_LINE);
558
+ graphCanvas.addMouseListener(new MouseListener() {
561
+ public void mouseDoubleClick(MouseEvent e) {
566
+ public void mouseDown(MouseEvent e) {
567
+ System.out.println("LOCATION: " + e.x + "," + e.y);
571
+ public void mouseUp(MouseEvent e) {
572
+ // TODO Auto-generated method stub
578
+ graphCanvas.addPaintListener(new PaintListener() {
579
+ public void paintControl(PaintEvent e) {
580
+ //TODO: If the script is running and the graph is not changed,
581
+ //there is no need to update yet.
582
+ for (int i = 0; i < graphs.size(); i ++) {
583
+ GraphModel graph = graphs.get(i);
584
+ GC gc = new GC(graphCanvas);
585
+ gc.setLineWidth(2);
586
+ graph.setHeight((int) (graphCanvas.getSize().y/(2.5*graphs.size())));
587
+ graph.setYAxisCoordinate((graph.getHeight() + GRAPH_SEPARATION) *(i + 1));
588
+ graph.drawOn(gc, graphCanvas);
595
+ threadCanvas.addPaintListener(new PaintListener() {
599
+ public void paintControl(PaintEvent e) {
600
+ if (threads == null)
602
+ int yOffset = GRAPH_SEPARATION;
604
+ GC gc = new GC(threadCanvas);
605
+ Color fg = new Color(Display.getCurrent(), 0, 0, 200);
606
+ gc.setForeground(fg);
609
+ ArrayList<ThreadGraph> toRemove = new ArrayList<ThreadGraph>();
610
+ for (ThreadGraph tg : threads) {
612
+ tg.setYAxisCoordinate(counter*yOffset);
613
+ gc.setLineWidth(2);
614
+ tg.drawOn(gc, graphCanvas);
615
+ gc.setLineWidth(0);
616
+ gc.drawText(tg.getTitle(), START_X_POS, counter*yOffset, true);
620
+ //TODO: O(N^2) operation
621
+ threads.removeAll(toRemove);
627
+ return Status.OK_STATUS;
630
+ private void createNewDataSet(String name, int type, String units) {
631
+ GraphModel graph = new MultiGraph(name, START_X_POS, (GraphModel.DEFAULT_HEIGHT + GRAPH_SEPARATION) *(graphs.size() + 1), type, units);
636
+ public void setViewID() {
637
+ viewID = "org.eclipse.linuxtools.internal.threadprofiler.ThreadProfilerView";
641
+ public void updateMethod() {
642
+ graphCanvas.redraw();
643
+ threadCanvas.redraw();
647
+ public void createPartControl(Composite parent) {
648
+ GridLayout gl = new GridLayout(1, true);
649
+ parent.setLayout(gl);
650
+ Color white = new Color(Display.getCurrent(), 255, 255, 255);
652
+ ScrolledComposite graphComp =new ScrolledComposite(parent, SWT.BORDER | SWT.V_SCROLL);
653
+ graphComp.setLayout (new GridLayout(1, true));
654
+ graphComp.setBackground(white);
655
+ GridData gd = new GridData(GridData.FILL_BOTH);
656
+ gd.grabExcessHorizontalSpace = true;
657
+ graphComp.setLayoutData(gd);
659
+ graphCanvas = new Canvas(graphComp, SWT.BORDER | SWT.V_SCROLL);
660
+ graphCanvas.setBackground(white);
661
+ gd = new GridData(GridData.FILL_BOTH);
662
+ gd.grabExcessHorizontalSpace = true;
663
+ graphCanvas.setLayoutData(gd);
665
+ ScrolledComposite threadComp =new ScrolledComposite(parent, SWT.BORDER | SWT.V_SCROLL);
666
+ threadComp.setLayout (new GridLayout(1, true));
667
+ threadComp.setBackground(white);
668
+ gd = new GridData(GridData.FILL_BOTH);
669
+ gd.grabExcessHorizontalSpace = true;
670
+ threadComp.setLayoutData(gd);
672
+ threadCanvas = new Canvas(graphComp, SWT.BORDER | SWT.V_SCROLL);
673
+ threadCanvas.setBackground(white);
674
+ gd = new GridData(GridData.FILL_BOTH);
675
+ gd.grabExcessHorizontalSpace = true;
676
+ threadCanvas.setLayoutData(gd);
680
+ public void setFocus() {
686
+ public void addDataPoints(int counter, String[] blargh) {
687
+ if (segments < GraphModel.BUFFER_SIZE)
689
+ if (blargh.length < 2)
691
+ this.addPoint(new DataPoint(counter, Integer.parseInt(blargh[1]), 1), CPU_BUFFER, 0);
693
+ if (blargh.length < 3)
695
+ this.addPoint(new DataPoint(counter, Integer.parseInt(blargh[2]), 1), CPU_BUFFER, 1);
697
+ if (blargh.length < 4)
699
+ this.addPoint(new DataPoint(counter, Integer.parseInt(blargh[3]), 1), MEM_BUFFER, 0);
701
+ if (blargh.length < 5)
703
+ this.addPoint(new DataPoint(counter, Integer.parseInt(blargh[4]), 1), MEM_BUFFER, 1);
705
+ if (blargh.length < 6)
707
+ addPoint(new DataPoint(counter, Integer.parseInt(blargh[5]), 1), DISK_BUFFER, 0);
709
+ if (blargh.length < 7)
711
+ addPoint(new DataPoint(counter, Integer.parseInt(blargh[6]), 1), DISK_BUFFER, 1);
713
+ if (blargh.length < 8)
715
+ addPoint(new DataPoint(counter, Integer.parseInt(blargh[7]), 1), DISK_BUFFER, 2);
719
+ private void addPoint(DataPoint point, int dataSet, int subIndex) {
720
+ if (graphs.size() < 1)
722
+ graphs.get(dataSet).add(point, subIndex);
725
+ public void addThread(int tid, String line) {
726
+ int i = threadExists(tid);
728
+ ThreadGraph tg = new ThreadGraph(line, START_X_POS, GRAPH_SEPARATION, 0, "", tid);
729
+ for (int j = 0; j < segments; j++) {
730
+ //Fill with empty segments
731
+ tg.add(new DataPoint(0, 0, DataPoint.INACTIVE), 0);
734
+ i = threads.size() - 1;
736
+ threads.get(i).prep(new DataPoint(0, 0, DataPoint.ACTIVE), 0);
740
+ public void closeThreads() {
741
+ // TODO Auto-generated method stub
742
+ for (ThreadGraph tg : threads) {
748
+ * Returns true if a thread with the given tid exists
753
+ private int threadExists(int tid) {
754
+ for (int i = 0; i < threads.size(); i++) {
755
+ if (threads.get(i).getTid() == tid) {
765
\ No newline at end of file
766
diff --git a/src/org/eclipse/linuxtools/threadprofiler/graphs/GraphModel.java b/src/org/eclipse/linuxtools/threadprofiler/graphs/GraphModel.java
767
index 5bf0531..1b07e18 100644
768
--- a/src/org/eclipse/linuxtools/threadprofiler/graphs/GraphModel.java
769
+++ b/src/org/eclipse/linuxtools/threadprofiler/graphs/GraphModel.java
771
-package org.eclipse.linuxtools.internal.threadprofiler.graphs;
773
-import java.util.ArrayList;
774
-import java.util.Iterator;
776
-import org.eclipse.linuxtools.internal.threadprofiler.CircularPointBuffer;
777
-import org.eclipse.linuxtools.internal.threadprofiler.CoordinateSystem;
778
-import org.eclipse.linuxtools.internal.threadprofiler.DataPoint;
779
-import org.eclipse.linuxtools.internal.threadprofiler.GraphAxis;
780
-import org.eclipse.swt.graphics.Color;
781
-import org.eclipse.swt.graphics.GC;
782
-import org.eclipse.swt.widgets.Canvas;
783
-import org.eclipse.swt.widgets.Composite;
784
-import org.eclipse.swt.widgets.Display;
786
-public abstract class GraphModel {
789
- public static final int CONSTANT_Y = 0;
790
- //Change Y scale as the maximum y point increases
791
- public static final int FLEXIBLE_Y = 1;
792
- //Maximum buffer size
793
- public static final int BUFFER_SIZE = 30;
795
- public static final int DEFAULT_HEIGHT = 100;
797
- private final CoordinateSystem coordinates;
798
- private final DataPoint startPoint;
799
- private final int graphType;
800
- private final String title;
801
- private final String units;
802
- private boolean changed;
803
- protected final ArrayList<CircularPointBuffer> data;
805
- private int height;
810
- public GraphModel(String name, int x, int y, int type, String units) {
813
- data = new ArrayList<CircularPointBuffer>();
815
- this.units = units;
816
- height = DEFAULT_HEIGHT;
818
- coordinates = new CoordinateSystem(x, y);
819
- coordinates.setYScale(0.2);
820
- coordinates.getAxis().setTopLabel(DEFAULT_HEIGHT + units);
822
- startPoint = new DataPoint(coordinates.getXOffset(), coordinates.getYOffset(), 1);
825
- public void setMaxY(int max) {
829
- public int getXOffset() {
830
- return (int) coordinates.getAxisToPixel().entries[0][2];
833
- public int getYOffset() {
834
- return (int) coordinates.getAxisToPixel().entries[1][2];
841
- * First available point buffer if any is available, else null
843
- public Iterator<DataPoint> getPointBuffer() {
844
- if (data.size() > 1)
845
- return getPointBuffer(0);
849
- public Iterator<DataPoint> getPointBuffer(int index) {
850
- return data.get(index).getIterator();
853
- public GraphAxis getAxis() {
854
- return coordinates.getAxis();
857
- public DataPoint getStartPoint() {
861
- public void add(DataPoint point, int subIndex) {
862
- if (subIndex >= data.size()) {
863
- data.add(new CircularPointBuffer(BUFFER_SIZE));
865
- if (graphType == FLEXIBLE_Y) {
866
- if (point.getY() > maxY ) {
867
- maxY = point.getY();
868
- coordinates.getAxis().setTopLabel(maxY + " " + units);
869
- if ( point.getY() > height) {
870
- double newScale = (double) height/maxY;
871
- coordinates.setYScale(newScale);
875
- data.get(subIndex).add(point);
879
- public DataPoint transform(DataPoint toTransform) {
880
- return coordinates.dataToPixel(toTransform);
883
- public boolean isChanged() {
887
- public void setChanged(boolean val) {
891
- public String getTitle() {
895
- public int getHeight() {
899
- public void setHeight(int value) {
900
- if (height == value)
903
- double newScale = (double) height/maxY;
904
- coordinates.setYScale(newScale);
908
- public void setYAxisCoordinate(int value) {
909
- coordinates.setYAxisCoordinate(value);
910
- startPoint.setY(value);
913
- public void setXAxisCoordinate(int value) {
914
- coordinates.setXAxisCoordinate(value);
915
- startPoint.setX(value);
919
- public CoordinateSystem getCoordinates() {
920
- return coordinates;
924
- * The main draw function -- implement this method to change
925
- * the way things are graphed
928
- * @param graphCanvas
930
- public abstract void drawOn(GC gc, Composite graphCanvas);
933
- protected void drawLine(GC gc, DataPoint p1, DataPoint p2) {
934
- gc.drawLine(p1.getX(), p1.getY(), p2.getX(), p2.getY());
940
- * Number of data buffers in this model
942
- public int getBufferCount() {
943
- return data.size();
947
- * Draws the x-axis and sets up the graph's title.
948
- * Also draws graduations for the x-axis
953
- protected void drawAxis(GC gc, int width) {
954
- gc.setLineWidth(2);
955
- gc.drawLine(getXOffset(), getYOffset(), width, getYOffset());
956
- int xSeg = getXOffset();
957
- int increment = width/BUFFER_SIZE;
958
- while (xSeg < width) {
959
- gc.drawLine(xSeg, getYOffset(), xSeg, getYOffset() - getHeight());
962
- gc.setForeground(new Color(Display.getCurrent(), 10, 10, 10));
963
- gc.drawText(getTitle(), getXOffset(), getYOffset() + 5, true);
964
-// gc.drawText(this.getCoordinates().getAxis().getTopLabel(), this.getXOffset(), this.getYOffset() - this.getHeight(), true);
967
- protected void drawFillPolygons(GC gc, Composite graphCanvas, Iterator<DataPoint> nextPointBuffer) {
968
- DataPoint pp = this.getStartPoint();
969
- int xSeg = this.getXOffset();
970
- int increment = (graphCanvas.getSize().x - this.getXOffset())/GraphModel.BUFFER_SIZE;
972
- gc.setLineWidth(0);
973
- while (nextPointBuffer.hasNext()) {
975
- DataPoint nextPoint = new DataPoint(xSeg, this.transform(nextPointBuffer.next()).getY(), 0);
976
- //Use old point, new point, and the corresponding intersections with the x-axis to fill
977
- gc.fillPolygon(new int[] {pp.getX(), pp.getY(), nextPoint.getX(), nextPoint.getY(), nextPoint.getX(), getStartPoint().getY(), pp.getX(), getStartPoint().getY()});
983
- protected void drawLines(GC gc, Composite graphCanvas, Iterator<DataPoint> nextPointBuffer) {
984
- DataPoint pp = this.getStartPoint();
985
- int xSeg = this.getXOffset();
986
- int increment = (graphCanvas.getSize().x - this.getXOffset())/GraphModel.BUFFER_SIZE;
988
- while (nextPointBuffer.hasNext()) {
989
- DataPoint nextPoint = new DataPoint(xSeg, this.transform(nextPointBuffer.next()).getY(), 0);
991
- drawLine(gc, pp, nextPoint);
997
+package org.eclipse.linuxtools.internal.threadprofiler.graphs;
999
+import java.util.ArrayList;
1000
+import java.util.Iterator;
1002
+import org.eclipse.linuxtools.internal.threadprofiler.CircularPointBuffer;
1003
+import org.eclipse.linuxtools.internal.threadprofiler.CoordinateSystem;
1004
+import org.eclipse.linuxtools.internal.threadprofiler.DataPoint;
1005
+import org.eclipse.linuxtools.internal.threadprofiler.GraphAxis;
1006
+import org.eclipse.swt.graphics.Color;
1007
+import org.eclipse.swt.graphics.GC;
1008
+import org.eclipse.swt.widgets.Canvas;
1009
+import org.eclipse.swt.widgets.Composite;
1010
+import org.eclipse.swt.widgets.Display;
1012
+public abstract class GraphModel {
1014
+ //Constant Y scale
1015
+ public static final int CONSTANT_Y = 0;
1016
+ //Change Y scale as the maximum y point increases
1017
+ public static final int FLEXIBLE_Y = 1;
1018
+ /** Maximum buffer size. This affects the number of data points*/
1019
+ public static final int BUFFER_SIZE = 100;
1021
+ public static final int DEFAULT_HEIGHT = 100;
1023
+ /** Number of spaces between graduations on the axis */
1024
+ private static final int GRADUATION_SEPARATION = 5;
1026
+ private final CoordinateSystem coordinates;
1027
+ private final DataPoint startPoint;
1028
+ private final int graphType;
1029
+ private final String title;
1030
+ private final String units;
1031
+ private boolean changed;
1032
+ protected final ArrayList<CircularPointBuffer> data;
1034
+ private int height;
1037
+ //Height in pixels
1039
+ public GraphModel(String name, int x, int y, int type, String units) {
1042
+ data = new ArrayList<CircularPointBuffer>();
1044
+ this.units = units;
1045
+ height = DEFAULT_HEIGHT;
1047
+ coordinates = new CoordinateSystem(x, y);
1048
+ coordinates.setYScale(0.2);
1049
+ coordinates.getAxis().setTopLabel(DEFAULT_HEIGHT + units);
1051
+ startPoint = new DataPoint(coordinates.getXOffset(), coordinates.getYOffset(), 1);
1054
+ public void setMaxY(int max) {
1058
+ public int getXOffset() {
1059
+ return (int) coordinates.getAxisToPixel().entries[0][2];
1062
+ public int getYOffset() {
1063
+ return (int) coordinates.getAxisToPixel().entries[1][2];
1070
+ * First available point buffer if any is available, else null
1072
+ public Iterator<DataPoint> getPointBuffer() {
1073
+ if (data.size() > 1)
1074
+ return getPointBuffer(0);
1078
+ public Iterator<DataPoint> getPointBuffer(int index) {
1079
+ return data.get(index).getIterator();
1082
+ public GraphAxis getAxis() {
1083
+ return coordinates.getAxis();
1086
+ public DataPoint getStartPoint() {
1087
+ return startPoint;
1090
+ public void add(DataPoint point, int subIndex) {
1091
+ if (subIndex >= data.size()) {
1092
+ data.add(new CircularPointBuffer(BUFFER_SIZE));
1094
+ if (graphType == FLEXIBLE_Y) {
1095
+ if (point.getY() > maxY ) {
1096
+ maxY = point.getY();
1097
+ coordinates.getAxis().setTopLabel(maxY + " " + units);
1098
+ if ( point.getY() > height) {
1099
+ double newScale = (double) height/maxY;
1100
+ coordinates.setYScale(newScale);
1104
+ data.get(subIndex).add(point);
1108
+ public DataPoint transform(DataPoint toTransform) {
1109
+ return coordinates.dataToPixel(toTransform);
1112
+ public boolean isChanged() {
1116
+ public void setChanged(boolean val) {
1120
+ public String getTitle() {
1124
+ public int getHeight() {
1128
+ public void setHeight(int value) {
1129
+ if (height == value)
1132
+ double newScale = (double) height/maxY;
1133
+ coordinates.setYScale(newScale);
1137
+ public void setYAxisCoordinate(int value) {
1138
+ coordinates.setYAxisCoordinate(value);
1139
+ startPoint.setY(value);
1142
+ public void setXAxisCoordinate(int value) {
1143
+ coordinates.setXAxisCoordinate(value);
1144
+ startPoint.setX(value);
1148
+ public CoordinateSystem getCoordinates() {
1149
+ return coordinates;
1153
+ * The main draw function -- implement this method to change
1154
+ * the way things are graphed
1157
+ * @param graphCanvas
1159
+ public abstract void drawOn(GC gc, Composite graphCanvas);
1162
+ protected void drawLine(GC gc, DataPoint p1, DataPoint p2) {
1163
+ gc.drawLine(p1.getX(), p1.getY(), p2.getX(), p2.getY());
1169
+ * Number of data buffers in this model
1171
+ public int getBufferCount() {
1172
+ return data.size();
1176
+ * Draws the x-axis and sets up the graph's title.
1177
+ * Also draws graduations for the x-axis
1182
+ protected void drawAxis(GC gc, int width) {
1183
+ gc.setLineWidth(2);
1184
+ gc.drawLine(getXOffset(), getYOffset(), width, getYOffset());
1185
+ int xSeg = getXOffset();
1186
+ int increment = width/BUFFER_SIZE;
1187
+ while (xSeg < width) {
1188
+ gc.drawLine(xSeg, getYOffset(), xSeg, getYOffset() - getHeight());
1189
+ xSeg += GRADUATION_SEPARATION * increment;
1191
+ gc.setForeground(new Color(Display.getCurrent(), 10, 10, 10));
1192
+ gc.drawText(getTitle(), getXOffset(), getYOffset() + 5, true);
1193
+// gc.drawText(this.getCoordinates().getAxis().getTopLabel(), this.getXOffset(), this.getYOffset() - this.getHeight(), true);
1196
+ protected void drawFillPolygons(GC gc, Composite graphCanvas, Iterator<DataPoint> nextPointBuffer) {
1197
+ DataPoint pp = this.getStartPoint();
1198
+ int xSeg = this.getXOffset();
1199
+ int increment = (graphCanvas.getSize().x - this.getXOffset())/GraphModel.BUFFER_SIZE;
1201
+ gc.setLineWidth(0);
1202
+ while (nextPointBuffer.hasNext()) {
1204
+ DataPoint nextPoint = new DataPoint(xSeg, this.transform(nextPointBuffer.next()).getY(), 0);
1205
+ //Use old point, new point, and the corresponding intersections with the x-axis to fill
1206
+ gc.fillPolygon(new int[] {pp.getX(), pp.getY(), nextPoint.getX(), nextPoint.getY(), nextPoint.getX(), getStartPoint().getY(), pp.getX(), getStartPoint().getY()});
1207
+ xSeg += increment;
1212
+ protected void drawLines(GC gc, Composite graphCanvas, Iterator<DataPoint> nextPointBuffer) {
1213
+ DataPoint pp = this.getStartPoint();
1214
+ int xSeg = this.getXOffset();
1215
+ int increment = (graphCanvas.getSize().x - this.getXOffset())/GraphModel.BUFFER_SIZE;
1217
+ while (nextPointBuffer.hasNext()) {
1218
+ DataPoint nextPoint = new DataPoint(xSeg, this.transform(nextPointBuffer.next()).getY(), 0);
1219
+ xSeg += increment;
1220
+ drawLine(gc, pp, nextPoint);
1226
diff --git a/src/org/eclipse/linuxtools/threadprofiler/graphs/MultiGraph.java b/src/org/eclipse/linuxtools/threadprofiler/graphs/MultiGraph.java
1227
index ee3565e..5d958b2 100644
1228
--- a/src/org/eclipse/linuxtools/threadprofiler/graphs/MultiGraph.java
1229
+++ b/src/org/eclipse/linuxtools/threadprofiler/graphs/MultiGraph.java
1230
@@ -80,6 +80,7 @@ public class MultiGraph extends GraphModel {
1231
gc.setBackground(oldBg);
1234
+ gc.setLineWidth(0);
1235
gc.drawText(getPointBuffer(i).toString(), xPos, yPos);
1236
prev = getPointBuffer(i).toString();
1237
xPos = xPos + separation(prev);