/
KernelStateProviderStub.java
81 lines (73 loc) · 2.92 KB
/
KernelStateProviderStub.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
/*******************************************************************************
* Copyright (c) 2023 É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.analysis.callstack.core.tests.stubs;
import org.eclipse.tracecompass.analysis.os.linux.core.model.ProcessStatus;
import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
/**
* A kernel state provider stub
*
* This reproduces the thread statuses as follows:
*
* <pre>
* |- THREADS
* | |- <Thread number> -> Thread Status
* | | |- SYSTEM_CALL
* </pre>
*
* @author Arnaud Fiorini
*/
public class KernelStateProviderStub extends AbstractTmfStateProvider {
private static final String ENTRY = "entry";
/**
* Constructor
*
* @param trace
* The trace to run this provider on
*/
public KernelStateProviderStub(ITmfTrace trace) {
super(trace, KernelAnalysisModuleStub.ID1);
}
@Override
public int getVersion() {
return 0;
}
@Override
public ITmfStateProvider getNewInstance() {
return new KernelStateProviderStub(getTrace());
}
@Override
protected void eventHandle(ITmfEvent event) {
ITmfStateSystemBuilder ssb = getStateSystemBuilder();
if (ssb == null) {
return;
}
int threadQuark = ssb.getQuarkAbsoluteAndAdd(Attributes.THREADS, event.getContent().getFieldValue(String.class, "tid"));
boolean isEntry = event.getName().equals(ENTRY);
long timestamp = event.getTimestamp().getValue();
if (isEntry) {
if (event.getName().equals("op4")) {
int systemCallQuark = ssb.getQuarkRelativeAndAdd(threadQuark, Attributes.SYSTEM_CALL);
ssb.modifyAttribute(timestamp, "openat", systemCallQuark);
/* Put the process in system call mode */
ssb.modifyAttribute(timestamp, ProcessStatus.RUN_SYTEMCALL.getStateValue().unboxValue(), threadQuark);
} else {
ssb.modifyAttribute(timestamp, ProcessStatus.RUN.getStateValue().unboxValue(), threadQuark);
}
} else {
ssb.modifyAttribute(timestamp, ProcessStatus.WAIT_CPU.getStateValue().unboxValue(), threadQuark);
}
}
}