Commit | Line | Data |
---|---|---|
7b79ee46 FLN |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | *******************************************************************************/ | |
9 | ||
10 | package org.eclipse.tracecompass.analysis.os.linux.core.latency; | |
11 | ||
12 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; | |
13 | ||
14 | import java.io.Serializable; | |
15 | import java.util.Comparator; | |
16 | import java.util.Map; | |
17 | ||
18 | import org.eclipse.jdt.annotation.Nullable; | |
19 | import org.eclipse.tracecompass.common.core.NonNullUtils; | |
20 | import org.eclipse.tracecompass.segmentstore.core.ISegment; | |
21 | import org.eclipse.tracecompass.segmentstore.core.SegmentComparators; | |
22 | ||
23 | import com.google.common.collect.ImmutableMap; | |
24 | import com.google.common.collect.Ordering; | |
25 | ||
26 | /** | |
27 | * A linux kernel system call, represented as an {@link ISegment}. | |
28 | * | |
29 | * @author Alexandre Montplaisir | |
30 | * @since 1.1 | |
31 | */ | |
32 | public class SystemCall implements ISegment { | |
33 | ||
34 | private static final long serialVersionUID = 1554494342105208730L; | |
35 | ||
36 | private static final Comparator<ISegment> COMPARATOR = checkNotNull(Ordering | |
37 | .from(SegmentComparators.INTERVAL_START_COMPARATOR) | |
38 | .compound(SegmentComparators.INTERVAL_END_COMPARATOR) | |
39 | /* Kind of lazy, but should work! */ | |
40 | .compound(Ordering.usingToString())); | |
41 | ||
42 | /** | |
43 | * The subset of information that is available from the syscall entry event. | |
44 | */ | |
45 | public static class InitialInfo implements Serializable { | |
46 | ||
47 | private static final long serialVersionUID = -5009710718804983721L; | |
48 | ||
49 | private final long fStartTime; | |
50 | private final String fName; | |
51 | private final Map<String, String> fArgs; | |
52 | ||
53 | /** | |
54 | * @param startTime | |
55 | * Start time of the system call | |
56 | * @param name | |
57 | * Name of the system call | |
58 | * @param arguments | |
59 | * Arguments of the system call | |
60 | */ | |
61 | public InitialInfo( | |
62 | long startTime, | |
63 | String name, | |
64 | Map<String, String> arguments) { | |
65 | fStartTime = startTime; | |
66 | fName = name; | |
67 | fArgs = NonNullUtils.checkNotNull(ImmutableMap.copyOf(arguments)); | |
68 | } | |
69 | } | |
70 | ||
71 | private final InitialInfo fInfo; | |
72 | private final long fEndTime; | |
73 | private final int fRet; | |
7b79ee46 FLN |
74 | |
75 | /** | |
76 | * @param info | |
77 | * Initial information of the system call | |
78 | * @param endTime | |
79 | * End time of the system call | |
80 | * @param ret | |
81 | * Return value of the system call | |
82 | */ | |
83 | public SystemCall( | |
84 | InitialInfo info, | |
85 | long endTime, | |
86 | int ret) { | |
87 | fInfo = info; | |
88 | fEndTime = endTime; | |
89 | fRet = ret; | |
7b79ee46 FLN |
90 | } |
91 | ||
92 | @Override | |
93 | public long getStart() { | |
94 | return fInfo.fStartTime; | |
95 | } | |
96 | ||
97 | @Override | |
98 | public long getEnd() { | |
99 | return fEndTime; | |
100 | } | |
101 | ||
102 | @Override | |
103 | public long getLength() { | |
d948686f | 104 | return fEndTime - fInfo.fStartTime; |
7b79ee46 FLN |
105 | } |
106 | ||
107 | /** | |
108 | * Get the name of the system call | |
109 | * | |
110 | * @return Name | |
111 | */ | |
112 | public String getName() { | |
113 | return fInfo.fName; | |
114 | } | |
115 | ||
116 | /** | |
117 | * Get the arguments of the system call | |
118 | * | |
119 | * @return Map of the arguments | |
120 | */ | |
121 | public Map<String, String> getArguments() { | |
122 | return fInfo.fArgs; | |
123 | } | |
124 | ||
125 | /** | |
126 | * Get the return value of the system call | |
127 | * | |
128 | * @return Return value | |
129 | */ | |
130 | public int getReturnValue() { | |
131 | return fRet; | |
132 | } | |
133 | ||
7b79ee46 FLN |
134 | @Override |
135 | public int compareTo(@Nullable ISegment o) { | |
136 | if (o == null) { | |
137 | throw new IllegalArgumentException(); | |
138 | } | |
139 | return COMPARATOR.compare(this, o); | |
140 | } | |
141 | ||
142 | @Override | |
143 | public String toString() { | |
144 | return "Start Time = " + getStart() + //$NON-NLS-1$ | |
145 | "; End Time = " + getEnd() + //$NON-NLS-1$ | |
146 | "; Duration = " + getLength() + //$NON-NLS-1$ | |
147 | "; Name = " + getName() + //$NON-NLS-1$ | |
148 | "; Args = " + getArguments().toString() + //$NON-NLS-1$ | |
149 | "; Return = " + getReturnValue(); //$NON-NLS-1$ | |
150 | } | |
151 | } |