Skip to content

Commit 9fd2890

Browse files
committed
vm: fixed review comments
Signed-off-by: philippe <beliasossim@gmail.com>
1 parent 4e9e1a1 commit 9fd2890

40 files changed

Lines changed: 786 additions & 2532 deletions

File tree

analyses/org.eclipse.tracecompass.incubator.executioncomparison.core/src/org/eclipse/tracecompass/incubator/internal/executioncomparison/core/DifferentialSeqCallGraphAnalysis.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ public DifferentialSeqCallGraphAnalysis() {
9797
// Adding VM/Native analysis
9898
fCallStackAnalysisMap.put("org.eclipse.linuxtools.lttng2.kernel.tracetype", //$NON-NLS-1$
9999
"org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis.vm.native.callstack"); //$NON-NLS-1$
100-
101-
/*fCallStackAnalysisMap.put("org.eclipse.tracecompass.tmf.core.experiment", //$NON-NLS-1$
102-
"org.eclipse.tracecompass.incubator.overhead.core.analysis.vm.native.callstack"); //$NON-NLS-1$*/
103100
}
104101

105102
/**

callstack/org.eclipse.tracecompass.incubator.analysis.core/.settings/org.eclipse.m2e.core.prefs

Lines changed: 0 additions & 4 deletions
This file was deleted.

vm/org.eclipse.tracecompass.incubator.virtual.machine.analysis.core/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ Export-Package: org.eclipse.tracecompass.incubator.internal.virtual.machine.anal
3636
org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.virtual.resources.handlers;x-internal:=true
3737
Import-Package: com.google.common.collect,
3838
com.google.common.hash,
39-
com.google.common.primitives
39+
com.google.common.primitives,
40+
org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout
4041
Automatic-Module-Name: org.eclipse.tracecompass.incubator.virtual.machine.analysis.core

vm/org.eclipse.tracecompass.incubator.virtual.machine.analysis.core/plugin.xml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,10 @@
6363
class="org.eclipse.tracecompass.tmf.core.trace.TmfTrace">
6464
</tracetype>
6565
</module>
66-
<module
67-
analysis_module="org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis.VMNativeComparisonAnalysis"
68-
id="org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis.vmcomparison"
69-
name="VM vs Native Comparison">
70-
<tracetype
71-
class="org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment">
72-
</tracetype>
73-
</module>
7466
<module
7567
analysis_module="org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis.VMNativeCallStackAnalysis"
7668
applies_experiment="true"
69+
automatic="false"
7770
id="org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis.vm.native.callstack"
7871
name="VM Native CallStack">
7972
<tracetype
@@ -84,7 +77,7 @@
8477
<extension
8578
point="org.eclipse.tracecompass.tmf.core.dataprovider">
8679
<dataProviderFactory
87-
class="org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis.core.data.provider.KvmExitDataProviderFactory"
80+
class="org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis.core.data.provider.KvmExitRateDataProviderFactory"
8881
id="org.eclipse.incubator.overhead.xy.rate.dataprovider">
8982
</dataProviderFactory>
9083
<dataProviderFactory

vm/org.eclipse.tracecompass.incubator.virtual.machine.analysis.core/src/org/eclipse/tracecompass/incubator/internal/virtual/machine/analysis/core/flow/analysis/ExecutionSequence.java

Lines changed: 11 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 École Polytechnique de Montréal
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License 2.0 which
6+
* accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
111
package org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis;
212

313
import java.util.ArrayList;
414
import java.util.List;
5-
import java.io.File;
6-
import java.io.FileOutputStream;
7-
import java.io.IOException;
8-
import java.io.PrintWriter;
915

1016
/**
1117
* Represents a complete execution sequence in a virtualized environment:
1218
* <pre>
13-
* Guest → VM Exit → Hypervisor (Host) → VM Entry
19+
* VM ENTRY → GUEST → VM EXIT → Hypervisor (Host) → VM Entry
1420
* </pre>
1521
* <p>
1622
* This class aggregates events occurring in both the guest and the hypervisor,
@@ -82,78 +88,6 @@ void setVmEntry(FlowEvent event) {
8288
this.vmEntry = event;
8389
}
8490

85-
/**
86-
* Prints the execution sequence for debugging purposes.
87-
* <p>
88-
* The sequence is printed both to the standard output and appended
89-
* to a file on disk.
90-
* </p>
91-
*
92-
* @throws IOException
93-
* if an I/O error occurs while writing to the file
94-
*/
95-
void printSequence() throws IOException {
96-
try (
97-
FileOutputStream fos = new FileOutputStream(
98-
new File("/home/philippe/Desktop/virtualized_flow.txt"), true); //$NON-NLS-1$
99-
PrintWriter writer = new PrintWriter(fos)) {
100-
101-
// Print guest events
102-
for (FlowEvent guestEvent : guestEvents) {
103-
KernelEventInfo evt = guestEvent.kernelEvent;
104-
System.out.printf(" [GUEST] %s (TID:%d, CPU:%d)\n", evt.name, evt.tid, evt.cpuid); //$NON-NLS-1$
105-
writer.printf(" [GUEST] %s (TID:%d, CPU:%d)\n", evt.name, evt.tid, evt.cpuid); //$NON-NLS-1$
106-
}
107-
108-
// Print VM exit
109-
if (vmExit != null) {
110-
System.out.printf(" ↓ [VM_EXIT] %s (CPU:%d, VCPU:%d, exit_reason:%s)\n", //$NON-NLS-1$
111-
vmExit.kernelEvent.name,
112-
vmExit.kernelEvent.cpuid,
113-
vmExit.kernelEvent.vcpuid,
114-
vmExit.kernelEvent.exitReason);
115-
116-
writer.printf(" ↓ [VM_EXIT] %s (CPU:%d, VCPU:%d, exit_reason:%s)\n", //$NON-NLS-1$
117-
vmExit.kernelEvent.name,
118-
vmExit.kernelEvent.cpuid,
119-
vmExit.kernelEvent.vcpuid,
120-
vmExit.kernelEvent.exitReason);
121-
}
122-
123-
// Print hypervisor events
124-
for (FlowEvent hypervisorEvent : hypervisorEvents) {
125-
KernelEventInfo evt = hypervisorEvent.kernelEvent;
126-
System.out.printf(" [HOST] %s (PID:%d, CPU:%d)\n", //$NON-NLS-1$
127-
evt.name, evt.pid, evt.cpuid);
128-
129-
writer.printf(" [HOST] %s (PID:%d, CPU:%d)\n", //$NON-NLS-1$
130-
evt.name, evt.pid, evt.cpuid);
131-
}
132-
133-
// Print VM entry
134-
if (vmEntry != null) {
135-
System.out.printf(" ↑ [VM_ENTRY] %s (CPU:%d, VCPU:%d)\n", //$NON-NLS-1$
136-
vmEntry.kernelEvent.name,
137-
vmEntry.kernelEvent.cpuid,
138-
vmEntry.kernelEvent.vcpuid);
139-
140-
writer.printf(" ↑ [VM_ENTRY] %s (CPU:%d, VCPU:%d)\n", //$NON-NLS-1$
141-
vmEntry.kernelEvent.name,
142-
vmEntry.kernelEvent.cpuid,
143-
vmEntry.kernelEvent.vcpuid);
144-
}
145-
146-
// Print timing summary
147-
if (!guestEvents.isEmpty() && vmEntry != null) {
148-
long totalDuration = vmEntry.kernelEvent.timestamp
149-
- guestEvents.get(0).kernelEvent.timestamp;
150-
151-
System.out.printf(" Total sequence duration: %d µs\n", totalDuration / 1000); //$NON-NLS-1$
152-
writer.printf(" Total sequence duration: %d µs\n", totalDuration / 1000); //$NON-NLS-1$
153-
}
154-
}
155-
}
156-
15791
/**
15892
* Indicates whether the execution sequence is complete.
15993
* <p>

vm/org.eclipse.tracecompass.incubator.virtual.machine.analysis.core/src/org/eclipse/tracecompass/incubator/internal/virtual/machine/analysis/core/flow/analysis/ExitReasonMap.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 École Polytechnique de Montréal
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License 2.0 which
6+
* accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
111
package org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis;
212

313
import java.util.HashMap;
@@ -6,6 +16,7 @@
616

717
/**
818
* Mapping of Exit reason number to their text description
19+
*
920
* @author Francois Belias
1021
*/
1122
public class ExitReasonMap {

vm/org.eclipse.tracecompass.incubator.virtual.machine.analysis.core/src/org/eclipse/tracecompass/incubator/internal/virtual/machine/analysis/core/flow/analysis/FlowEvent.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 École Polytechnique de Montréal
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License 2.0 which
6+
* accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
111
package org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis;
212

313
/**

vm/org.eclipse.tracecompass.incubator.virtual.machine.analysis.core/src/org/eclipse/tracecompass/incubator/internal/virtual/machine/analysis/core/flow/analysis/KernelEventInfo.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 École Polytechnique de Montréal
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License 2.0 which
6+
* accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
111
package org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis;
212

313

@@ -82,12 +92,12 @@ public class KernelEventInfo {
8292
*/
8393
public KernelEventInfo(String name, long timestamp, int pid, int tid, String processName,
8494
TraceType source, int cpuid, int vcpuid, String exitReason) {
85-
this.name = name;
95+
this.name = java.util.Objects.requireNonNull(name, "name cannot be null"); //$NON-NLS-1$
8696
this.timestamp = timestamp;
8797
this.pid = pid;
8898
this.tid = tid;
89-
this.processName = processName;
90-
this.source = source;
99+
this.processName = java.util.Objects.requireNonNull(processName, "processName cannot be null"); //$NON-NLS-1$
100+
this.source = java.util.Objects.requireNonNull(source, "source cannot be null"); //$NON-NLS-1$
91101
this.cpuid = cpuid;
92102
this.vcpuid = vcpuid;
93103
this.exitReason = exitReason;

vm/org.eclipse.tracecompass.incubator.virtual.machine.analysis.core/src/org/eclipse/tracecompass/incubator/internal/virtual/machine/analysis/core/flow/analysis/KvmExitAnalysisModule.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
/***********************************************************************
2-
* KVM Exit Analysis Module
3-
* This module analyzes and tracks KVM exit event per cpu
4-
***********************************************************************/
5-
1+
/*******************************************************************************
2+
* Copyright (c) 2026 École Polytechnique de Montréal
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License 2.0 which
6+
* accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
611
package org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis;
712

813

@@ -16,6 +21,8 @@
1621
/**
1722
* Analysis module that builds a state system from KVM exit events in a trace.
1823
* It tracks the number and types of VM exits for each CPU.
24+
*
25+
* @author Francois Belias
1926
*/
2027
public class KvmExitAnalysisModule extends TmfStateSystemAnalysisModule {
2128

vm/org.eclipse.tracecompass.incubator.virtual.machine.analysis.core/src/org/eclipse/tracecompass/incubator/internal/virtual/machine/analysis/core/flow/analysis/KvmExitStateProvider.java

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
21
/*******************************************************************************
3-
* KVM Exit State Provider
4-
* This state provider processes trace events related to KVM exits
2+
* Copyright (c) 2026 École Polytechnique de Montréal
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License 2.0 which
6+
* accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
510
*******************************************************************************/
6-
7-
8-
911
package org.eclipse.tracecompass.incubator.internal.virtual.machine.analysis.core.flow.analysis;
1012

1113

1214
import org.eclipse.jdt.annotation.NonNull;
1315
import org.eclipse.jdt.annotation.Nullable;
1416
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
17+
import org.eclipse.tracecompass.statesystem.core.StateSystemBuilderUtils;
1518
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
1619
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
1720
import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
@@ -29,16 +32,7 @@ public class KvmExitStateProvider extends AbstractTmfStateProvider {
2932

3033
private static final int VERSION = 1;
3134
private static final String ID = "org.eclipse.tracecompass.incubator.internal.overhead.core.analysis"; //$NON-NLS-1$
32-
33-
// Event names that we're interested in
34-
private static final String KVM_EXIT = "kvm_x86_exit"; //$NON-NLS-1$
35-
private static final String KVM_ENTRY = "kvm_x86_entry"; //$NON-NLS-1$
36-
37-
38-
// Field names in the KVM exit event
39-
private static final String EXIT_REASON = "exit_reason"; //$NON-NLS-1$
40-
private static final String VCPU_ID = "vcpu_id"; //$NON-NLS-1$
41-
private static final String CPU_ID = "context.cpu_id"; //$NON-NLS-1$
35+
private final static VMNativeEventLayout fLayout = VMNativeEventLayout.getInstance();
4236

4337
/**
4438
* Constructor
@@ -72,11 +66,11 @@ protected void eventHandle(@NonNull ITmfEvent event) {
7266
final ITmfEventField content = event.getContent();
7367

7468
// Process KVM exit events
75-
if (eventName.equals(KVM_EXIT)) {
69+
if (eventName.equals(fLayout.eventsKVMExit().iterator().next())) {
7670
// Get the CPU ID and exit reason
77-
Object cpuObj = getFieldValue(content, CPU_ID);
78-
Object exitReasonObj = getFieldValue(content, EXIT_REASON);
79-
Object vcpuIdObj = getFieldValue(content, VCPU_ID);
71+
Object cpuObj = content.getFieldValue(Integer.class, fLayout.contextCpuid());
72+
Object exitReasonObj = content.getFieldValue(Integer.class, fLayout.contextExitReason());
73+
Object vcpuIdObj = content.getFieldValue(Integer.class, fLayout.contextVcpuid());
8074

8175
if (cpuObj == null) {
8276
return;
@@ -95,7 +89,7 @@ protected void eventHandle(@NonNull ITmfEvent event) {
9589

9690
// Create and increment the KVM exits counter for this CPU
9791
int exitCountQuark = ss.getQuarkRelativeAndAdd(cpuQuark, "kvm_exits"); //$NON-NLS-1$
98-
incrementExitCounter(ss, exitCountQuark, timestamp);
92+
StateSystemBuilderUtils.incrementAttributeLong(ss, timestamp, exitCountQuark, 1);
9993

10094
// Track the VCPU if available
10195
if (vcpuId != null) {
@@ -106,12 +100,12 @@ protected void eventHandle(@NonNull ITmfEvent event) {
106100
int vcpusQuark = ss.getQuarkAbsoluteAndAdd("VCPUs"); //$NON-NLS-1$
107101
int specificVcpuQuark = ss.getQuarkRelativeAndAdd(vcpusQuark, String.valueOf(vcpuId));
108102
int vcpuExitCountQuark = ss.getQuarkRelativeAndAdd(specificVcpuQuark, "kvm_exits"); //$NON-NLS-1$
109-
incrementExitCounter(ss, vcpuExitCountQuark, timestamp);
103+
StateSystemBuilderUtils.incrementAttributeLong(ss, timestamp, vcpuExitCountQuark, 1);
110104

111105
// If we have exit reason information, track it
112106
if (exitReason != null) {
113107
int reasonQuark = ss.getQuarkRelativeAndAdd(specificVcpuQuark, "exit_reasons", ExitReasonMap.getExitReasonName(exitReason)); //$NON-NLS-1$
114-
incrementExitCounter(ss, reasonQuark, timestamp);
108+
StateSystemBuilderUtils.incrementAttributeLong(ss, timestamp, reasonQuark, 1);
115109
}
116110

117111

@@ -124,9 +118,9 @@ protected void eventHandle(@NonNull ITmfEvent event) {
124118
int stateQuark = ss.getQuarkRelativeAndAdd(cpuQuark, "kvm_state"); //$NON-NLS-1$
125119
ss.modifyAttribute(timestamp, "exit", stateQuark); //$NON-NLS-1$
126120

127-
} else if (eventName.equals(KVM_ENTRY)) {
121+
} else if (eventName.equals(fLayout.eventsKVMEntry().iterator().next())) {
128122
// Get the CPU ID
129-
Object cpuObj = getFieldValue(content, CPU_ID);
123+
Object cpuObj = content.getFieldValue(Integer.class, fLayout.contextCpuid());
130124
if (cpuObj == null) {
131125
return;
132126
}
@@ -143,36 +137,18 @@ protected void eventHandle(@NonNull ITmfEvent event) {
143137
}
144138
}
145139

146-
/**
147-
* Increment a counter in the state system, handling the case where it doesn't exist yet
148-
*/
149-
private static void incrementExitCounter(ITmfStateSystemBuilder ss, int quark, long timestamp) {
150-
Object currentValue = ss.queryOngoing(quark);
151-
int newValue = 1;
152-
153-
if (currentValue instanceof Integer) {
154-
newValue = ((Integer) currentValue) + 1;
155-
}
156-
157-
ss.modifyAttribute(timestamp, newValue, quark);
158-
}
159-
160-
/**
161-
* Safely get a field value from the event content
162-
*/
163-
private static @Nullable Object getFieldValue(ITmfEventField content, String fieldName) {
164-
ITmfEventField field = content.getField(fieldName);
165-
return (field != null) ? field.getValue() : null;
166-
}
167-
168140
/**
169141
* Convert an object to Integer if possible
170142
*/
171143
private static @Nullable Integer getIntegerValue(@Nullable Object obj) {
172144
if (obj instanceof Integer) {
173145
return (Integer) obj;
174146
} else if (obj instanceof Long) {
175-
return ((Long) obj).intValue();
147+
long value = ((Long) obj).longValue();
148+
if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
149+
return null;
150+
}
151+
return (int) value;
176152
} else if (obj instanceof String) {
177153
try {
178154
return Integer.parseInt((String) obj);

0 commit comments

Comments
 (0)