1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
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
.lttng2
.kernel
.core
.analysis
.graph
.model
;
12 import java
.util
.Collection
;
13 import java
.util
.HashMap
;
15 import java
.util
.Stack
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.model
.HostThread
;
19 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
21 import com
.google
.common
.collect
.HashBasedTable
;
22 import com
.google
.common
.collect
.Table
;
25 * This class contains the model of a Linux system
27 * TODO: This model is custom made for the LTTng dependency analysis for ease of
28 * development of the feature, but most of it and the classes it uses also apply
29 * to any Linux OS trace, so the classes in this package should be moved to
32 * @author Francis Giraldeau
33 * @author Geneviève Bastien
35 public class LttngSystemModel
{
37 private final Table
<String
, Integer
, HostThread
> fCurrentTids
= NonNullUtils
.checkNotNull(HashBasedTable
.<String
, Integer
, HostThread
> create());
38 private final Table
<String
, Integer
, Stack
<LttngInterruptContext
>> fIntCtxStacks
= NonNullUtils
.checkNotNull(HashBasedTable
.<String
, Integer
, Stack
<LttngInterruptContext
>> create());
39 private final Map
<HostThread
, LttngWorker
> fWorkerMap
= new HashMap
<>();
42 * Cache the TID currently on the CPU of a host, for easier access later on
47 * The {@link HostThread} object that is running on this CPU
49 public void cacheTidOnCpu(Integer cpu
, HostThread ht
) {
50 fCurrentTids
.put(ht
.getHost(), cpu
, ht
);
54 * Get the {@link LttngWorker} object that is currently running on the CPU
58 * The identifier of the trace/machine of the CPU
60 * The CPU ID on which the worker is running
61 * @return The {@link LttngWorker} running on the CPU
63 public @Nullable LttngWorker
getWorkerOnCpu(String host
, Integer cpu
) {
64 HostThread ht
= fCurrentTids
.get(host
, cpu
);
68 return findWorker(ht
);
72 * Return the worker associated with this host TID
75 * The host thread associated with a worker
76 * @return The {@link LttngWorker} associated with a host thread
78 public @Nullable LttngWorker
findWorker(HostThread ht
) {
79 return fWorkerMap
.get(ht
);
83 * Add a new worker to the system
88 public void addWorker(LttngWorker worker
) {
89 fWorkerMap
.put(worker
.getHostThread(), worker
);
93 * Get the list of workers on this system
95 * @return The list of workers on the system
97 public Collection
<LttngWorker
> getWorkers() {
98 return NonNullUtils
.checkNotNull(fWorkerMap
.values());
102 * Pushes an interrupt context on the stack for a CPU on a host
105 * The host ID of the trace/machine the interrupt context belongs
108 * The CPU this interrupt happened on
109 * @param interruptCtx
110 * The interrupt context to push on the stack
112 public void pushContextStack(String hostId
, Integer cpu
, LttngInterruptContext interruptCtx
) {
113 Stack
<LttngInterruptContext
> stack
= fIntCtxStacks
.get(hostId
, cpu
);
115 stack
= new Stack
<>();
116 fIntCtxStacks
.put(hostId
, cpu
, stack
);
118 stack
.push(interruptCtx
);
122 * Peeks the top of the interrupt context stack for a CPU on a host, to see
123 * what is the latest context.
126 * The host ID of the trace/machine the interrupt context belongs
129 * The CPU this interrupt happened on
130 * @return The latest interrupt context on the CPU of the host
132 public LttngInterruptContext
peekContextStack(String hostId
, Integer cpu
) {
133 Stack
<LttngInterruptContext
> stack
= fIntCtxStacks
.get(hostId
, cpu
);
135 return LttngInterruptContext
.DEFAULT_CONTEXT
;
138 return LttngInterruptContext
.DEFAULT_CONTEXT
;
140 LttngInterruptContext peek
= stack
.peek();
142 peek
= LttngInterruptContext
.DEFAULT_CONTEXT
;
148 * Removes the top of the interrupt context stack for a CPU on a host and
152 * The host ID of the trace/machine the interrupt context belongs
155 * The CPU this interrupt happened on
156 * @return The latest interrupt context on the CPU of the host
158 public @Nullable LttngInterruptContext
popContextStack(String hostId
, Integer cpu
) {
159 Stack
<LttngInterruptContext
> stack
= fIntCtxStacks
.get(hostId
, cpu
);