linux.core: Intern SystemCall name string
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / latency / SystemCall.java
1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 EfficiOS Inc., Alexandre Montplaisir and others
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.internal.analysis.os.linux.core.latency;
11
12 import java.io.IOException;
13 import java.io.ObjectInputStream;
14 import java.io.ObjectOutputStream;
15
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.eclipse.tracecompass.segmentstore.core.ISegment;
18
19 /**
20 * A linux kernel system call, represented as an {@link ISegment}.
21 *
22 * @author Alexandre Montplaisir
23 * @since 2.0
24 */
25 public final class SystemCall implements ISegment {
26
27 private static final long serialVersionUID = 1554494342105208730L;
28
29 /**
30 * The subset of information that is available from the syscall entry event.
31 */
32 public static class InitialInfo {
33
34 private long fStartTime;
35 private String fName;
36
37 /**
38 * @param startTime
39 * Start time of the system call
40 * @param name
41 * Name of the system call
42 */
43 public InitialInfo(
44 long startTime,
45 String name) {
46 fStartTime = startTime;
47 fName = name.intern();
48 }
49 }
50
51 private long fStartTime;
52 private long fEndTime;
53 private String fName;
54
55 /**
56 * @param info
57 * Initial information of the system call
58 * @param endTime
59 * End time of the system call
60 */
61 public SystemCall(
62 InitialInfo info,
63 long endTime) {
64 fStartTime = info.fStartTime;
65 fName = info.fName;
66 fEndTime = endTime;
67 }
68
69 private void writeObject(ObjectOutputStream out) throws IOException {
70 out.writeLong(fStartTime);
71 out.writeLong(fEndTime);
72 out.writeUTF(fName);
73 }
74
75 private void readObject(ObjectInputStream in) throws IOException {
76 fStartTime = in.readLong();
77 fEndTime = in.readLong();
78 fName = in.readUTF().intern();
79 }
80
81 @Override
82 public long getStart() {
83 return fStartTime;
84 }
85
86 @Override
87 public long getEnd() {
88 return fEndTime;
89 }
90
91 /**
92 * Get the name of the system call
93 *
94 * @return Name
95 */
96 public String getName() {
97 return fName;
98 }
99
100 @Override
101 public int compareTo(@NonNull ISegment o) {
102 int ret = ISegment.super.compareTo(o);
103 if (ret != 0) {
104 return ret;
105 }
106 return toString().compareTo(o.toString());
107 }
108
109 @Override
110 public String toString() {
111 return "Start Time = " + getStart() + //$NON-NLS-1$
112 "; End Time = " + getEnd() + //$NON-NLS-1$
113 "; Duration = " + getLength() + //$NON-NLS-1$
114 "; Name = " + getName(); //$NON-NLS-1$
115 }
116 }
This page took 0.034061 seconds and 5 git commands to generate.