89e370d738777756ef0410afc1c6914bcef3455c
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / kernel / Attributes.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
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.analysis.os.linux.core.kernel;
11
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.eclipse.tracecompass.tmf.core.util.Pair;
14
15 /**
16 * This file defines all the attribute names used in the handler. Both the
17 * construction and query steps should use them.
18 *
19 * These should not be externalized! The values here are used as-is in the
20 * history file on disk, so they should be kept the same to keep the file format
21 * compatible. If a view shows attribute names directly, the localization should
22 * be done on the viewer side.
23 *
24 * @author Alexandre Montplaisir
25 */
26 @SuppressWarnings({ "nls", "javadoc" })
27 public interface Attributes {
28
29 /* First-level attributes */
30 String CPUS = "CPUs";
31 String THREADS = "Threads";
32
33 /* Sub-attributes of the CPU nodes */
34 String CURRENT_THREAD = "Current_thread";
35 String STATUS = "Status";
36 String SOFT_IRQS = "Soft_IRQs";
37 String IRQS = "IRQs";
38
39 /* Sub-attributes of the Thread nodes */
40 String PPID = "PPID";
41 // static final String STATUS = "Status"
42 String EXEC_NAME = "Exec_name";
43
44 String PRIO = "Prio";
45 String SYSTEM_CALL = "System_call";
46
47 /* Misc stuff */
48 String UNKNOWN = "Unknown";
49 String THREAD_0_PREFIX = "0_";
50 String THREAD_0_SEPARATOR = "_";
51
52 /**
53 * Build the thread attribute name.
54 *
55 * For all threads except "0" this is the string representation of the
56 * threadId. For thread "0" which is the idle thread and can be running
57 * concurrently on multiple CPUs, append "_cpuId".
58 *
59 * @param threadId
60 * the thread id
61 * @param cpuId
62 * the cpu id
63 * @return the thread attribute name null if the threadId is zero and the
64 * cpuId is null
65 */
66 public static @Nullable String buildThreadAttributeName(int threadId, @Nullable Integer cpuId) {
67 if (threadId == 0) {
68 if (cpuId == null) {
69 return null;
70 }
71 return Attributes.THREAD_0_PREFIX + String.valueOf(cpuId);
72 }
73
74 return String.valueOf(threadId);
75 }
76
77 /**
78 * Parse the thread id and CPU id from the thread attribute name string
79 *
80 * For thread "0" the attribute name is in the form "threadId_cpuId",
81 * extract both values from the string.
82 *
83 * For all other threads, the attribute name is the string representation of
84 * the threadId and there is no cpuId.
85 *
86 * @param threadAttributeName
87 * the thread attribute name
88 * @return the thread id and cpu id
89 */
90 public static Pair<Integer, Integer> parseThreadAttributeName(String threadAttributeName) {
91 Integer threadId = -1;
92 Integer cpuId = -1;
93
94 try {
95 if (threadAttributeName.startsWith(Attributes.THREAD_0_PREFIX)) {
96 threadId = 0;
97 String[] tokens = threadAttributeName.split(Attributes.THREAD_0_SEPARATOR);
98 cpuId = Integer.parseInt(tokens[1]);
99 } else {
100 threadId = Integer.parseInt(threadAttributeName);
101 }
102 } catch (NumberFormatException e1) {
103 // pass
104 }
105
106 return new Pair<>(threadId, cpuId);
107 }
108 }
This page took 0.039371 seconds and 4 git commands to generate.