-
Notifications
You must be signed in to change notification settings - Fork 10
/
SysExitHandler.java
93 lines (84 loc) · 4.18 KB
/
SysExitHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************************************************
* Copyright (c) 2016 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.fused.handlers;
import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
import org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.Activator;
import org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.fused.FusedAttributes;
import org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.model.VirtualCPU;
import org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.model.VirtualMachine;
import org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.virtual.resources.StateValues;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
/**
* @author Cédric Biancheri
*/
public class SysExitHandler extends VMKernelEventHandler {
/**
* Constructor
*
* @param layout
* the layout
* @param sp
* the state provider
*/
public SysExitHandler(IKernelAnalysisEventLayout layout, FusedVirtualMachineStateProvider sp) {
super(layout, sp);
}
@Override
public void handleEvent(ITmfStateSystemBuilder ss, ITmfEvent event) {
Integer cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(event.getTrace(), TmfCpuAspect.class, event);
if (cpu == null) {
return;
}
FusedVirtualMachineStateProvider sp = getStateProvider();
VirtualMachine host = sp.getCurrentMachine(event);
VirtualCPU cpuObject = VirtualCPU.getVirtualCPU(host, cpu.longValue());
if (host != null && host.isGuest()) {
Integer physicalCPU = sp.getPhysicalCPU(host, cpu);
if (physicalCPU != null) {
cpu = physicalCPU;
} else {
return;
}
}
/* Assign the new system call to the process */
int currentThreadNode = FusedVMEventHandlerUtils.getCurrentThreadNode(cpu, ss);
int quark = ss.getQuarkRelativeAndAdd(currentThreadNode, FusedAttributes.SYSTEM_CALL);
long timestamp = FusedVMEventHandlerUtils.getTimestamp(event);
ss.modifyAttribute(timestamp, (Object) null, quark);
/* Put the process in user mode */
quark = ss.getQuarkRelativeAndAdd(currentThreadNode, FusedAttributes.STATUS);
ss.modifyAttribute(timestamp, StateValues.PROCESS_STATUS_RUN_USERMODE, quark);
/*
* If the trace that generates the event doesn't match the currently
* running machine on this pcpu then we do not modify the state system.
*/
int currentCPUNode = FusedVMEventHandlerUtils.getCurrentCPUNode(cpu, ss);
boolean modify = true;
if (host != null) {
int machineNameQuark = ss.getQuarkRelativeAndAdd(currentCPUNode, FusedAttributes.MACHINE_NAME);
try {
modify = ss.querySingleState(timestamp, machineNameQuark).getStateValue().unboxStr().equals(host.getHostId());
} catch (StateSystemDisposedException e) {
Activator.getInstance().logError(e.getMessage(), e);
}
}
/* Put the CPU in user mode */
quark = ss.getQuarkRelativeAndAdd(currentCPUNode, FusedAttributes.STATUS);
if (modify) {
ss.modifyAttribute(timestamp, StateValues.CPU_STATUS_RUN_USERMODE, quark);
}
cpuObject.setCurrentState(StateValues.CPU_STATUS_RUN_USERMODE);
}
}