analysis.io: Introduce the input/output linux analysis
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / inputoutput / Request.java
1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
3 *
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 *******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.analysis.os.linux.core.inputoutput;
11
12 import java.util.ArrayList;
13 import java.util.Collections;
14 import java.util.List;
15
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.eclipse.tracecompass.analysis.os.linux.core.inputoutput.IoOperationType;
18
19 /**
20 * Represents a request to a disk of the system
21 *
22 * @author Houssem Daoud
23 */
24 public class Request {
25
26 private Long fSector;
27 private int fNrSector;
28 private final DiskWriteModel fDisk;
29 private final List<BlockIO> fBios = new ArrayList<>();
30 private @Nullable Integer fIssuedFrom = null;
31 private IoOperationType fType;
32
33 /**
34 * Constructor
35 *
36 * @param disk
37 * The disk for this request
38 * @param sector
39 * The base sector of this request
40 * @param rwbs
41 * The read/write bits
42 */
43 public Request(DiskWriteModel disk, Long sector, int rwbs) {
44 fSector = sector;
45 fNrSector = 0;
46 fDisk = disk;
47 fType = IoOperationType.getType(rwbs);
48 }
49
50 /**
51 * Constructor from a Block IO structure
52 *
53 * @param bio
54 * The BIO to start this request from
55 */
56 public Request(BlockIO bio) {
57 fSector = bio.getSector();
58 fNrSector = bio.getNrSector();
59 fType = bio.getType();
60 fBios.add(0, bio);
61 fDisk = bio.getDisk();
62 }
63
64 /**
65 * Get the base sector of this request
66 *
67 * @return The base sector
68 */
69 public Long getSector() {
70 return fSector;
71 }
72
73 /**
74 * Get the number of sectors of this request
75 *
76 * @return The number of sectors
77 */
78 public int getNrSector() {
79 return fNrSector;
80 }
81
82 /**
83 * Updates the number of sectors for this request
84 *
85 * @param nrSector
86 * The new number of sectors
87 */
88 public void setNrSector(int nrSector) {
89 fNrSector = nrSector;
90 }
91
92 /**
93 * Get the disk this request is for
94 *
95 * @return The disk of this BIO
96 */
97 public DiskWriteModel getDisk() {
98 return fDisk;
99 }
100
101 /**
102 * Get the type of request
103 *
104 * @return The type of request
105 */
106 public IoOperationType getType() {
107 return fType;
108 }
109
110 /**
111 * Set the read/write mode of this request
112 *
113 * @param rwbs
114 * The read/write bits of the request
115 */
116 public void setType(int rwbs) {
117 fType = IoOperationType.getType(rwbs);
118 }
119
120 /**
121 * Get the list of BIOs included in this request
122 *
123 * @return The list of BIOs
124 */
125 public List<BlockIO> getBios() {
126 return Collections.unmodifiableList(fBios);
127 }
128
129 /**
130 * Get the request this request is based on
131 *
132 * @return The quark of the request this is issued from
133 */
134 public @Nullable Integer getIssuedFrom() {
135 return fIssuedFrom;
136 }
137
138 /**
139 * Insert the BIO into this request
140 *
141 * @param bio
142 * The Block IO to insert in this request
143 */
144 public void insertBio(BlockIO bio) {
145 fBios.add(bio);
146 fNrSector += bio.getNrSector();
147 if (bio.getSector() < getSector()) {
148 fSector = bio.getSector();
149 }
150 }
151
152 /**
153 * Merges a request into this one
154 *
155 * @param request
156 * The second request to merge
157 */
158 public void mergeRequest(Request request) {
159 fBios.addAll(request.getBios());
160 fNrSector = getNrSector() + request.getNrSector();
161 }
162
163 }
This page took 0.035687 seconds and 5 git commands to generate.