1 /**********************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 **********************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.views
.io
.diskioactivity
;
12 import java
.util
.Collection
;
14 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
15 import org
.eclipse
.jdt
.annotation
.Nullable
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.inputoutput
.Disk
;
19 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.inputoutput
.InputOutputAnalysisModule
;
20 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.inputoutput
.InputOutputInformationProvider
;
21 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.inputoutput
.IoOperationType
;
22 import org
.eclipse
.tracecompass
.common
.core
.format
.DataSpeedWithUnitFormat
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
27 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.xycharts
.linecharts
.TmfCommonXLineChartViewer
;
28 import org
.swtchart
.Chart
;
31 * Disk IO Activity viewer, shows read and write bandwidth used over time.
33 * @author Houssem Daoud
35 public class DisksIOActivityViewer
extends TmfCommonXLineChartViewer
{
37 // Timeout between updates in the updateData thread
38 private static final long BUILD_UPDATE_TIMEOUT
= 500;
39 private static final double RESOLUTION
= 0.2;
40 private static final int BYTES_PER_SECTOR
= 512;
41 private static final int SECOND_TO_NANOSECOND
= (int) Math
.pow(10, 9);
43 private @Nullable InputOutputAnalysisModule fModule
= null;
51 public DisksIOActivityViewer(@Nullable Composite parent
) {
52 super(parent
, Messages
.DiskIOActivityViewer_Title
, Messages
.DiskIOActivityViewer_XAxis
, Messages
.DiskIOActivityViewer_YAxis
);
53 setResolution(RESOLUTION
);
54 Chart chart
= getSwtChart();
55 chart
.getAxisSet().getYAxis(0).getTick().setFormat(new DataSpeedWithUnitFormat());
56 chart
.getLegend().setPosition(SWT
.LEFT
);
60 protected void initializeDataSource() {
61 ITmfTrace trace
= getTrace();
63 InputOutputAnalysisModule module
= TmfTraceUtils
.getAnalysisModuleOfClass(trace
, InputOutputAnalysisModule
.class, InputOutputAnalysisModule
.ID
);
73 protected void updateData(long start
, long end
, int nb
, @Nullable IProgressMonitor monitor
) {
74 InputOutputAnalysisModule module
= fModule
;
75 if (getTrace() == null || module
== null) {
78 if (!module
.waitForInitialization()) {
81 ITmfStateSystem ss
= module
.getStateSystem();
86 double[] xvalues
= getXAxis(start
, end
, nb
);
89 boolean complete
= false;
90 long currentEnd
= start
;
92 while (!complete
&& currentEnd
< end
) {
93 if (monitor
!= null && monitor
.isCanceled()) {
96 complete
= ss
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
97 currentEnd
= ss
.getCurrentEndTime();
98 long traceStart
= getStartTime();
99 long traceEnd
= getEndTime();
100 long offset
= this.getTimeOffset();
102 Collection
<Disk
> disks
= InputOutputInformationProvider
.getDisks(module
);
104 for (Disk disk
: disks
) {
105 if (!disk
.hasActivity()) {
109 String diskName
= disk
.getDiskName();
111 /* Initialize quarks and series names */
112 double[] yValuesWritten
= new double[xvalues
.length
];
113 double[] yValuesRead
= new double[xvalues
.length
];
114 String seriesNameWritten
= new String(diskName
+ Messages
.DisksIOActivityViewer_Write
);
115 String seriesNameRead
= new String(diskName
+ Messages
.DisksIOActivityViewer_Read
);
117 double prevX
= xvalues
[0];
118 long prevTime
= (long) prevX
+ offset
;
120 * make sure that time is in the trace range after double to
123 prevTime
= Math
.max(traceStart
, prevTime
);
124 prevTime
= Math
.min(traceEnd
, prevTime
);
125 long prevCountRead
= disk
.getSectorsAt(prevTime
, IoOperationType
.READ
);
126 long prevCountWrite
= disk
.getSectorsAt(prevTime
, IoOperationType
.WRITE
);
127 for (int i
= 1; i
< xvalues
.length
; i
++) {
128 if (monitor
!= null && monitor
.isCanceled()) {
131 double x
= xvalues
[i
];
132 long time
= (long) x
+ offset
;
133 time
= Math
.max(traceStart
, time
);
134 time
= Math
.min(traceEnd
, time
);
136 long count
= disk
.getSectorsAt(time
, IoOperationType
.WRITE
);
137 yValuesWritten
[i
] = (count
- prevCountWrite
) * BYTES_PER_SECTOR
/ ((double) (time
- prevTime
) / SECOND_TO_NANOSECOND
);
138 prevCountWrite
= count
;
139 count
= disk
.getSectorsAt(time
, IoOperationType
.READ
);
140 yValuesRead
[i
] = (count
- prevCountRead
) * BYTES_PER_SECTOR
/ ((double) (time
- prevTime
) / SECOND_TO_NANOSECOND
);
141 prevCountRead
= count
;
142 } catch (TimeRangeException e
) {
143 yValuesWritten
[i
] = 0;
148 setSeries(seriesNameRead
, yValuesRead
);
149 setSeries(seriesNameWritten
, yValuesWritten
);
150 if (monitor
!= null && monitor
.isCanceled()) {