88import java .io .PrintWriter ;
99
1010/**
11- * Represents a complete execution sequence: Guest → VM Exit → Host → VM Entry
11+ * Represents a complete execution sequence in a virtualized environment:
12+ * <pre>
13+ * Guest → VM Exit → Hypervisor (Host) → VM Entry
14+ * </pre>
15+ * <p>
16+ * This class aggregates events occurring in both the guest and the hypervisor,
17+ * as well as the VM exit and entry transitions that connect them.
18+ * </p>
1219 *
13- * @author philippe
20+ * @author Francois Belias
1421 */
1522public class ExecutionSequence {
23+
24+ /**
25+ * List of events that occurred in the guest before the VM exit.
26+ */
1627 private final List <FlowEvent > guestEvents = new ArrayList <>();
28+
29+ /**
30+ * List of events that occurred in the hypervisor (host)
31+ * between VM exit and VM entry.
32+ */
1733 private final List <FlowEvent > hypervisorEvents = new ArrayList <>();
34+
35+ /**
36+ * Event representing the VM exit (transition from guest to host).
37+ */
1838 private FlowEvent vmExit ;
39+
40+ /**
41+ * Event representing the VM entry (transition from host back to guest).
42+ */
1943 private FlowEvent vmEntry ;
2044
45+ /**
46+ * Adds an event to the guest event list.
47+ *
48+ * @param event
49+ * the guest event to add
50+ */
2151 void addGuestEvent (FlowEvent event ) {
2252 guestEvents .add (event );
2353 }
2454
55+ /**
56+ * Adds an event to the hypervisor event list.
57+ *
58+ * @param event
59+ * the hypervisor event to add
60+ */
2561 void addHypervisorEvent (FlowEvent event ) {
2662 hypervisorEvents .add (event );
2763 }
2864
65+ /**
66+ * Sets the VM exit event.
67+ *
68+ * @param event
69+ * the VM exit event
70+ */
2971 void setVmExit (FlowEvent event ) {
3072 this .vmExit = event ;
3173 }
3274
75+ /**
76+ * Sets the VM entry event.
77+ *
78+ * @param event
79+ * the VM entry event
80+ */
3381 void setVmEntry (FlowEvent event ) {
3482 this .vmEntry = event ;
3583 }
3684
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+ */
3795 void printSequence () throws IOException {
3896 try (
39-
40- FileOutputStream fos = new FileOutputStream ( new File ("/home/philippe/Desktop/virtualized_flow.txt" ), true ); //$NON-NLS-1$
97+ FileOutputStream fos = new FileOutputStream (
98+ new File ("/home/philippe/Desktop/virtualized_flow.txt" ), true ); //$NON-NLS-1$
4199 PrintWriter writer = new PrintWriter (fos )) {
100+
101+ // Print guest events
42102 for (FlowEvent guestEvent : guestEvents ) {
43103 KernelEventInfo evt = guestEvent .kernelEvent ;
44104 System .out .printf (" [GUEST] %s (TID:%d, CPU:%d)\n " , evt .name , evt .tid , evt .cpuid ); //$NON-NLS-1$
@@ -47,41 +107,66 @@ void printSequence() throws IOException {
47107
48108 // Print VM exit
49109 if (vmExit != null ) {
50- System .out .printf (" ↓ [VM_EXIT] %s (CPU:%d, VCPU:%d, exit_reason:%s)\n " , vmExit .kernelEvent .name , //$NON-NLS-1$
51- vmExit .kernelEvent .cpuid , vmExit .kernelEvent .vcpuid , vmExit .kernelEvent .exitReason );
52-
53- writer .printf (" ↓ [VM_EXIT] %s (CPU:%d, VCPU:%d, exit_reason:%s)\n " , vmExit .kernelEvent .name , //$NON-NLS-1$
54- vmExit .kernelEvent .cpuid , vmExit .kernelEvent .vcpuid , vmExit .kernelEvent .exitReason );
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 );
55121 }
56122
57123 // Print hypervisor events
58124 for (FlowEvent hypervisorEvent : hypervisorEvents ) {
59125 KernelEventInfo evt = hypervisorEvent .kernelEvent ;
60- System .out .printf (" [HOST] %s (PID:%d, CPU:%d)\n " , evt .name , evt .pid , evt .cpuid ); //$NON-NLS-1$
126+ System .out .printf (" [HOST] %s (PID:%d, CPU:%d)\n " , //$NON-NLS-1$
127+ evt .name , evt .pid , evt .cpuid );
61128
62- writer .printf (" [HOST] %s (PID:%d, CPU:%d)\n " , evt .name , evt .pid , evt .cpuid ); //$NON-NLS-1$
129+ writer .printf (" [HOST] %s (PID:%d, CPU:%d)\n " , //$NON-NLS-1$
130+ evt .name , evt .pid , evt .cpuid );
63131 }
64132
65133 // Print VM entry
66134 if (vmEntry != null ) {
67- System .out .printf (" ↑ [VM_ENTRY] %s (CPU:%d, VCPU:%d)\n " , vmEntry .kernelEvent .name , //$NON-NLS-1$
68- vmEntry .kernelEvent .cpuid , vmEntry .kernelEvent .vcpuid );
69-
70- writer .printf (" ↑ [VM_ENTRY] %s (CPU:%d, VCPU:%d)\n " , vmEntry .kernelEvent .name , //$NON-NLS-1$
71- vmEntry .kernelEvent .cpuid , vmEntry .kernelEvent .vcpuid );
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 );
72144 }
73145
74146 // Print timing summary
75147 if (!guestEvents .isEmpty () && vmEntry != null ) {
76- long totalDuration = vmEntry .kernelEvent .timestamp -
77- guestEvents .get (0 ).kernelEvent .timestamp ;
78- System .out .printf (" Total sequence duration: %d µs\n " , totalDuration / 1000 ); //$NON-NLS-1$
148+ long totalDuration = vmEntry .kernelEvent .timestamp
149+ - guestEvents .get (0 ).kernelEvent .timestamp ;
79150
151+ System .out .printf (" Total sequence duration: %d µs\n " , totalDuration / 1000 ); //$NON-NLS-1$
80152 writer .printf (" Total sequence duration: %d µs\n " , totalDuration / 1000 ); //$NON-NLS-1$
81153 }
82154 }
83155 }
84156
157+ /**
158+ * Indicates whether the execution sequence is complete.
159+ * <p>
160+ * A sequence is considered complete if it contains:
161+ * <ul>
162+ * <li>At least one guest event</li>
163+ * <li>A VM exit event</li>
164+ * <li>A VM entry event</li>
165+ * </ul>
166+ * </p>
167+ *
168+ * @return {@code true} if the sequence is complete, {@code false} otherwise
169+ */
85170 boolean isComplete () {
86171 return !guestEvents .isEmpty () && vmExit != null && vmEntry != null ;
87172 }
0 commit comments