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 | ||
7b79ee46 | 12 | import java.io.Serializable; |
7b79ee46 FLN |
13 | import java.util.Map; |
14 | ||
f1c52947 | 15 | import org.eclipse.jdt.annotation.NonNull; |
7b79ee46 | 16 | import org.eclipse.tracecompass.segmentstore.core.ISegment; |
7b79ee46 FLN |
17 | |
18 | import com.google.common.collect.ImmutableMap; | |
7b79ee46 FLN |
19 | |
20 | /** | |
21 | * A linux kernel system call, represented as an {@link ISegment}. | |
22 | * | |
23 | * @author Alexandre Montplaisir | |
fb3a499b | 24 | * @since 2.0 |
7b79ee46 FLN |
25 | */ |
26 | public class SystemCall implements ISegment { | |
27 | ||
28 | private static final long serialVersionUID = 1554494342105208730L; | |
29 | ||
7b79ee46 FLN |
30 | /** |
31 | * The subset of information that is available from the syscall entry event. | |
32 | */ | |
33 | public static class InitialInfo implements Serializable { | |
34 | ||
35 | private static final long serialVersionUID = -5009710718804983721L; | |
36 | ||
37 | private final long fStartTime; | |
38 | private final String fName; | |
39 | private final Map<String, String> fArgs; | |
40 | ||
41 | /** | |
42 | * @param startTime | |
43 | * Start time of the system call | |
44 | * @param name | |
45 | * Name of the system call | |
46 | * @param arguments | |
47 | * Arguments of the system call | |
48 | */ | |
49 | public InitialInfo( | |
50 | long startTime, | |
51 | String name, | |
52 | Map<String, String> arguments) { | |
53 | fStartTime = startTime; | |
54 | fName = name; | |
0e4f957e | 55 | fArgs = ImmutableMap.copyOf(arguments); |
7b79ee46 FLN |
56 | } |
57 | } | |
58 | ||
59 | private final InitialInfo fInfo; | |
60 | private final long fEndTime; | |
61 | private final int fRet; | |
7b79ee46 FLN |
62 | |
63 | /** | |
64 | * @param info | |
65 | * Initial information of the system call | |
66 | * @param endTime | |
67 | * End time of the system call | |
68 | * @param ret | |
69 | * Return value of the system call | |
70 | */ | |
71 | public SystemCall( | |
72 | InitialInfo info, | |
73 | long endTime, | |
74 | int ret) { | |
75 | fInfo = info; | |
76 | fEndTime = endTime; | |
77 | fRet = ret; | |
7b79ee46 FLN |
78 | } |
79 | ||
80 | @Override | |
81 | public long getStart() { | |
82 | return fInfo.fStartTime; | |
83 | } | |
84 | ||
85 | @Override | |
86 | public long getEnd() { | |
87 | return fEndTime; | |
88 | } | |
89 | ||
7b79ee46 FLN |
90 | /** |
91 | * Get the name of the system call | |
92 | * | |
93 | * @return Name | |
94 | */ | |
95 | public String getName() { | |
96 | return fInfo.fName; | |
97 | } | |
98 | ||
99 | /** | |
100 | * Get the arguments of the system call | |
101 | * | |
102 | * @return Map of the arguments | |
103 | */ | |
104 | public Map<String, String> getArguments() { | |
105 | return fInfo.fArgs; | |
106 | } | |
107 | ||
108 | /** | |
109 | * Get the return value of the system call | |
110 | * | |
111 | * @return Return value | |
112 | */ | |
113 | public int getReturnValue() { | |
114 | return fRet; | |
115 | } | |
116 | ||
7b79ee46 | 117 | @Override |
f1c52947 JCK |
118 | public int compareTo(@NonNull ISegment o) { |
119 | int ret = ISegment.super.compareTo(o); | |
120 | if (ret != 0) { | |
121 | return ret; | |
7b79ee46 | 122 | } |
f1c52947 | 123 | return toString().compareTo(o.toString()); |
7b79ee46 FLN |
124 | } |
125 | ||
126 | @Override | |
127 | public String toString() { | |
128 | return "Start Time = " + getStart() + //$NON-NLS-1$ | |
129 | "; End Time = " + getEnd() + //$NON-NLS-1$ | |
130 | "; Duration = " + getLength() + //$NON-NLS-1$ | |
131 | "; Name = " + getName() + //$NON-NLS-1$ | |
132 | "; Args = " + getArguments().toString() + //$NON-NLS-1$ | |
133 | "; Return = " + getReturnValue(); //$NON-NLS-1$ | |
134 | } | |
135 | } |