1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
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 ******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
;
12 import org
.eclipse
.jdt
.annotation
.Nullable
;
13 import org
.eclipse
.tracecompass
.tmf
.core
.util
.Pair
;
16 * This file defines all the attribute names used in the handler. Both the
17 * construction and query steps should use them.
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.
24 * @author Alexandre Montplaisir
26 @SuppressWarnings({ "nls", "javadoc" })
27 public interface Attributes
{
29 /* First-level attributes */
31 String THREADS
= "Threads";
33 /* Sub-attributes of the CPU nodes */
34 String CURRENT_THREAD
= "Current_thread";
35 String SOFT_IRQS
= "Soft_IRQs";
38 /* Sub-attributes of the Thread nodes */
40 String EXEC_NAME
= "Exec_name";
43 String SYSTEM_CALL
= "System_call";
46 String UNKNOWN
= "Unknown";
47 String THREAD_0_PREFIX
= "0_";
48 String THREAD_0_SEPARATOR
= "_";
51 * Build the thread attribute name.
53 * For all threads except "0" this is the string representation of the
54 * threadId. For thread "0" which is the idle thread and can be running
55 * concurrently on multiple CPUs, append "_cpuId".
61 * @return the thread attribute name null if the threadId is zero and the
64 public static @Nullable String
buildThreadAttributeName(int threadId
, @Nullable Integer cpuId
) {
69 return Attributes
.THREAD_0_PREFIX
+ String
.valueOf(cpuId
);
72 return String
.valueOf(threadId
);
76 * Parse the thread id and CPU id from the thread attribute name string
78 * For thread "0" the attribute name is in the form "threadId_cpuId",
79 * extract both values from the string.
81 * For all other threads, the attribute name is the string representation of
82 * the threadId and there is no cpuId.
84 * @param threadAttributeName
85 * the thread attribute name
86 * @return the thread id and cpu id
88 public static Pair
<Integer
, Integer
> parseThreadAttributeName(String threadAttributeName
) {
89 Integer threadId
= -1;
93 if (threadAttributeName
.startsWith(Attributes
.THREAD_0_PREFIX
)) {
95 String
[] tokens
= threadAttributeName
.split(Attributes
.THREAD_0_SEPARATOR
);
96 cpuId
= Integer
.parseInt(tokens
[1]);
98 threadId
= Integer
.parseInt(threadAttributeName
);
100 } catch (NumberFormatException e1
) {
104 return new Pair
<>(threadId
, cpuId
);