-
Notifications
You must be signed in to change notification settings - Fork 9
/
SchedWS.java
176 lines (153 loc) · 5.03 KB
/
SchedWS.java
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*******************************************************************************
* Copyright (c) 2021 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.tracecompass.incubator.internal.kernel.core.swslatency;
import org.eclipse.tracecompass.analysis.os.linux.core.model.OsStrings;
import org.eclipse.tracecompass.datastore.core.interval.IHTIntervalReader;
import org.eclipse.tracecompass.datastore.core.serialization.ISafeByteBufferWriter;
import org.eclipse.tracecompass.datastore.core.serialization.SafeByteBufferFactory;
import org.eclipse.tracecompass.segmentstore.core.ISegment;
import org.eclipse.tracecompass.segmentstore.core.segment.interfaces.INamedSegment;
import org.eclipse.tracecompass.tmf.core.model.ICoreElementResolver;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
/**
* A Linux kernel sched_wakeup/ sched_switch event, represented as an
* {@link ISegment}.
*
* @author Abdellah Rahmani
*/
public final class SchedWS implements INamedSegment, ICoreElementResolver {
private static final long serialVersionUID = 4183872871733170072L;
/**
* The reader for this segment class
*/
public static final IHTIntervalReader<ISegment> READER = buffer -> new SchedWS(buffer.getLong(), buffer.getLong(), buffer.getString(), buffer.getInt(), buffer.getInt());
/**
* The subset of information that is available from the sched wakeup/switch
* entry event.
*/
public static class InitialInfo {
private long fStartTime;
private String fName;
private int fTid;
/**
* @param startTime
* Start time of the sched_wakeup event
* @param name
* Name of the thread to wake-up
* @param tid
* The TID of the thread to wake-up
*/
public InitialInfo(
long startTime,
String name,
int tid) {
fStartTime = startTime;
fName = name.intern();
fTid = tid;
}
}
private final long fStartTime;
private final long fEndTime;
private final String fName;
private final int fTid;
private final int fPriority;
/**
* @param info
* Initial information of sched_wakeup / sched_switch event
* @param endTime
* End time of the sched_switch event
* @param priority
* The priority of the thread to wake-up
*/
public SchedWS(
InitialInfo info,
long endTime, int priority) {
fStartTime = info.fStartTime;
fName = info.fName;
fEndTime = endTime;
fTid = info.fTid;
fPriority = priority;
}
private SchedWS(long startTime, long endTime, String name, int tid, int priority) {
fStartTime = startTime;
fEndTime = endTime;
fName = name;
fTid = tid;
fPriority = priority;
}
@Override
public long getStart() {
return fStartTime;
}
@Override
public long getEnd() {
return fEndTime;
}
/**
* Get the name of the sched_wakeup / switch_event event
*
* @return Name
*/
@Override
public String getName() {
return fName;
}
/**
* Get the thread ID for this sched_wakeup / sched_switch event
*
* @return The ID of the thread
*/
public int getTid() {
return fTid;
}
/**
* Get the priority of the thread to wake-up
*
* @return The priority value of the thread
*/
public int getPriority() {
return fPriority;
}
@Override
public int getSizeOnDisk() {
return 2 * Long.BYTES + SafeByteBufferFactory.getStringSizeInBuffer(fName) + 2 * Integer.BYTES;
}
@Override
public void writeSegment(ISafeByteBufferWriter buffer) {
buffer.putLong(fStartTime);
buffer.putLong(fEndTime);
buffer.putString(fName);
buffer.putInt(fTid);
buffer.putInt(fPriority);
}
@Override
public int compareTo(ISegment o) {
int ret = INamedSegment.super.compareTo(o);
if (ret != 0) {
return ret;
}
return toString().compareTo(o.toString());
}
@Override
public String toString() {
return "Start Time = " + getStart() + //$NON-NLS-1$
"; End Time = " + getEnd() + //$NON-NLS-1$
"; Duration = " + getLength() + //$NON-NLS-1$
"; Name = " + getName(); //$NON-NLS-1$
}
@Override
public Multimap<String, Object> getMetadata() {
Multimap<String, Object> map = HashMultimap.create();
map.put(OsStrings.tid(), fTid);
return map;
}
}