acrntrace: Fix the incorrect total vmexit cnt issue

Originally, we assume that the vmenter will sit at the first line
of the trace file. But if the vmexit comes earlier than vmenter.
The total vmexit cnt will be set as 0 by the first vmenter.

This patch fixes the issue by:
   - Search the trace file to find the first vmexit entry and start to analyze here
     and mark the TSC_BEGIN as the tsc of this vmexit.
   - Inc the total vmexit cnt by 1 when meet the vmexit entry.
   - Calc the vmexit duration when meet the vmenter in pair with the last vmexit.

Tracked-On: #4175
Acked-by: Yan, Like <like.yan@intel.com>
Signed-off-by: Kaige Fu <kaige.fu@intel.com>
This commit is contained in:
Kaige Fu 2019-11-29 00:37:43 +08:00 committed by wenlingz
parent 1115c0c6af
commit 9655b9de15
1 changed files with 24 additions and 14 deletions

View File

@ -89,12 +89,31 @@ def parse_trace_data(ifile):
global TSC_BEGIN, TSC_END, TOTAL_NR_EXITS
last_ev_id = ''
tsc_enter = 0
tsc_exit = 0
tsc_last_exit_period = 0
fd = open(ifile, 'rb')
# The duration of one vmexit is tsc_enter - tsc_exit
# Here we should find the first vmexit and ignore other entries on top of the first vmexit
while True:
try:
line = fd.read(struct.calcsize(TRCREC))
if not line:
break
(tsc, event, d1, d2) = struct.unpack(TRCREC, line)
event = event & 0xffffffffffff
if event != VM_EXIT:
continue
# We found the first vmexit and should seek back one line as we will read it in the following loop
TSC_BEGIN = tsc
fd.seek(fd.tell() - len(line))
break
except (IOError, struct.error) as e:
sys.exit()
while True:
try:
line = fd.read(struct.calcsize(TRCREC))
@ -105,21 +124,12 @@ def parse_trace_data(ifile):
event = event & 0xffffffffffff
if event == VM_ENTER:
if TSC_BEGIN == 0:
TSC_BEGIN = tsc
tsc_exit = tsc
TOTAL_NR_EXITS = 0
tsc_enter = tsc
TSC_END = tsc_enter
tsc_last_exit_period = tsc_enter - tsc_exit
if tsc_last_exit_period != 0:
TIME_IN_EXIT[last_ev_id] += tsc_last_exit_period
TSC_END = tsc
# Found one vmenter in pair with the last vmexit
TIME_IN_EXIT[last_ev_id] += tsc - tsc_exit
elif event == VM_EXIT:
tsc_exit = tsc
TSC_END = tsc_exit
TOTAL_NR_EXITS += 1
else: