analysis.lami: Implementation of LAMI plugins
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.lami.core / src / org / eclipse / tracecompass / internal / provisional / analysis / lami / core / types / LamiProcess.java
1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 EfficiOS Inc., Alexandre Montplaisir
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types;
11
12 import java.util.StringJoiner;
13
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16
17 /**
18 * Class defining a LAMI 'process' type.
19 *
20 * This is the representation of an operating system process.
21 *
22 * @author Alexandre Montplaisir
23 */
24 public class LamiProcess extends LamiData {
25
26 private final @Nullable String fName;
27 private final @Nullable Long fPid;
28 private final @Nullable Long fTid;
29
30 private final String fString;
31
32 /**
33 * Constructor
34 *
35 * All parameters are optional, but realistically at least one should be
36 * provided!
37 *
38 * @param name
39 * The process name
40 * @param pid
41 * The process's PID
42 * @param tid
43 * The process's TID
44 */
45 public LamiProcess(@Nullable String name, @Nullable Long pid, @Nullable Long tid) {
46 fName = name;
47 fPid = pid;
48 fTid = tid;
49
50 fString = generateString();
51 }
52
53 /**
54 * Get this process's name, null if unavailable.
55 *
56 * @return The process name
57 */
58 public @Nullable String getName() {
59 return fName;
60 }
61
62 /**
63 * Get this process's PID, null if unavailable.
64 *
65 * @return The process PID
66 */
67 public @Nullable Long getPID() {
68 return fPid;
69 }
70
71 /**
72 * Get this process's TID, null if unavailable.
73 *
74 * @return The process TID
75 */
76 public @Nullable Long getTID() {
77 return fTid;
78 }
79
80 private String generateString() {
81 Long pid = fPid;
82 Long tid = fTid;
83
84 StringBuilder sb = new StringBuilder();
85 if (fName != null) {
86 sb.append(fName);
87 }
88
89 if (pid != null || tid != null) {
90 sb.append(' ');
91 StringJoiner sj = new StringJoiner(", ", "(", ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
92 if (pid != null) {
93 sj.add("pid=" + pid.toString()); //$NON-NLS-1$
94 }
95 if (tid != null) {
96 sj.add("tid=" + tid.toString()); //$NON-NLS-1$
97 }
98 sb.append(sj.toString());
99 }
100
101 return sb.toString();
102 }
103
104 @Override
105 public @NonNull String toString() {
106 return fString;
107 }
108
109 }
This page took 0.066151 seconds and 5 git commands to generate.