os.linux: Correctly model each CPU's run queue
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / kernel / Attributes.java
CommitLineData
ee8e0dc9 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2012, 2015 Ericsson
ee8e0dc9
AM
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
ee8e0dc9
AM
8 ******************************************************************************/
9
f69045e2 10package org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel;
ee8e0dc9 11
642b4947
AM
12import org.eclipse.jdt.annotation.Nullable;
13import org.eclipse.tracecompass.tmf.core.util.Pair;
14
ee8e0dc9
AM
15/**
16 * This file defines all the attribute names used in the handler. Both the
17 * construction and query steps should use them.
d85d2a6d 18 *
ee8e0dc9
AM
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.
d85d2a6d 23 *
0f7a12d3 24 * @author Alexandre Montplaisir
ee8e0dc9 25 */
642b4947 26@SuppressWarnings({ "nls", "javadoc" })
6d9da7b0 27public interface Attributes {
ee8e0dc9
AM
28
29 /* First-level attributes */
64522b6b
AM
30 String CPUS = "CPUs";
31 String THREADS = "Threads";
ee8e0dc9
AM
32
33 /* Sub-attributes of the CPU nodes */
64522b6b 34 String CURRENT_THREAD = "Current_thread";
19ed6598
MK
35 String SOFT_IRQS = "Soft_IRQs";
36 String IRQS = "IRQs";
ee8e0dc9
AM
37
38 /* Sub-attributes of the Thread nodes */
16ad5604 39 String CURRENT_CPU_RQ = "Current_cpu_rq";
64522b6b 40 String PPID = "PPID";
64522b6b 41 String EXEC_NAME = "Exec_name";
dbc7991d 42
64522b6b
AM
43 String PRIO = "Prio";
44 String SYSTEM_CALL = "System_call";
ee8e0dc9 45
ee8e0dc9 46 /* Misc stuff */
64522b6b 47 String UNKNOWN = "Unknown";
8a0bbebf
MJ
48 String THREAD_0_PREFIX = "0_";
49 String THREAD_0_SEPARATOR = "_";
642b4947
AM
50
51 /**
52 * Build the thread attribute name.
53 *
54 * For all threads except "0" this is the string representation of the
55 * threadId. For thread "0" which is the idle thread and can be running
56 * concurrently on multiple CPUs, append "_cpuId".
57 *
58 * @param threadId
59 * the thread id
60 * @param cpuId
61 * the cpu id
62 * @return the thread attribute name null if the threadId is zero and the
63 * cpuId is null
64 */
65 public static @Nullable String buildThreadAttributeName(int threadId, @Nullable Integer cpuId) {
66 if (threadId == 0) {
67 if (cpuId == null) {
68 return null;
69 }
70 return Attributes.THREAD_0_PREFIX + String.valueOf(cpuId);
71 }
72
73 return String.valueOf(threadId);
74 }
75
76 /**
77 * Parse the thread id and CPU id from the thread attribute name string
78 *
79 * For thread "0" the attribute name is in the form "threadId_cpuId",
80 * extract both values from the string.
81 *
82 * For all other threads, the attribute name is the string representation of
83 * the threadId and there is no cpuId.
84 *
85 * @param threadAttributeName
86 * the thread attribute name
87 * @return the thread id and cpu id
88 */
89 public static Pair<Integer, Integer> parseThreadAttributeName(String threadAttributeName) {
90 Integer threadId = -1;
91 Integer cpuId = -1;
92
93 try {
94 if (threadAttributeName.startsWith(Attributes.THREAD_0_PREFIX)) {
95 threadId = 0;
96 String[] tokens = threadAttributeName.split(Attributes.THREAD_0_SEPARATOR);
97 cpuId = Integer.parseInt(tokens[1]);
98 } else {
99 threadId = Integer.parseInt(threadAttributeName);
100 }
101 } catch (NumberFormatException e1) {
102 // pass
103 }
104
105 return new Pair<>(threadId, cpuId);
106 }
ee8e0dc9 107}
This page took 0.099657 seconds and 5 git commands to generate.