ss: Implement ISegment#getLength() as a default method
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / analysis / os / linux / core / latency / SystemCall.java
CommitLineData
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
10package org.eclipse.tracecompass.analysis.os.linux.core.latency;
11
12import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
13
14import java.io.Serializable;
15import java.util.Comparator;
16import java.util.Map;
17
18import org.eclipse.jdt.annotation.Nullable;
19import org.eclipse.tracecompass.common.core.NonNullUtils;
20import org.eclipse.tracecompass.segmentstore.core.ISegment;
21import org.eclipse.tracecompass.segmentstore.core.SegmentComparators;
22
23import com.google.common.collect.ImmutableMap;
24import com.google.common.collect.Ordering;
25
26/**
27 * A linux kernel system call, represented as an {@link ISegment}.
28 *
29 * @author Alexandre Montplaisir
fb3a499b 30 * @since 2.0
7b79ee46
FLN
31 */
32public 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
7b79ee46
FLN
102 /**
103 * Get the name of the system call
104 *
105 * @return Name
106 */
107 public String getName() {
108 return fInfo.fName;
109 }
110
111 /**
112 * Get the arguments of the system call
113 *
114 * @return Map of the arguments
115 */
116 public Map<String, String> getArguments() {
117 return fInfo.fArgs;
118 }
119
120 /**
121 * Get the return value of the system call
122 *
123 * @return Return value
124 */
125 public int getReturnValue() {
126 return fRet;
127 }
128
7b79ee46
FLN
129 @Override
130 public int compareTo(@Nullable ISegment o) {
131 if (o == null) {
132 throw new IllegalArgumentException();
133 }
134 return COMPARATOR.compare(this, o);
135 }
136
137 @Override
138 public String toString() {
139 return "Start Time = " + getStart() + //$NON-NLS-1$
140 "; End Time = " + getEnd() + //$NON-NLS-1$
141 "; Duration = " + getLength() + //$NON-NLS-1$
142 "; Name = " + getName() + //$NON-NLS-1$
143 "; Args = " + getArguments().toString() + //$NON-NLS-1$
144 "; Return = " + getReturnValue(); //$NON-NLS-1$
145 }
146}
This page took 0.032352 seconds and 5 git commands to generate.