0.1
  #   ˆl–Ðz¾”*ClÊq@à]¸ÛêbÑ¿Á„q¦„ïÄÃ ?÷     #! /usr/bin/python3
# SPDX-License-Identifier: GPL-2.0-only
#
# top-like utility for displaying kvm statistics
#
# Copyright 2006-2008 Qumranet Technologies
# Copyright 2008-2011 Red Hat, Inc.
#
# Authors:
#  Avi Kivity <avi@redhat.com>
#
"""The kvm_stat module outputs statistics about running KVM VMs

Three different ways of output formatting are available:
- as a top-like text ui
- in a key -> value format
- in an all keys, all values format

The data is sampled from the KVM's debugfs entries and its perf events.
"""
from __future__ import print_function

import curses
import sys
import locale
import os
import time
import argparse
import ctypes
import fcntl
import resource
import struct
import re
import subprocess
import signal
from collections import defaultdict, namedtuple
from functools import reduce
from datetime import datetime

VMX_EXIT_REASONS = {
    'EXCEPTION_NMI':        0,
    'EXTERNAL_INTERRUPT':   1,
    'TRIPLE_FAULT':         2,
    'INIT_SIGNAL':          3,
    'SIPI_SIGNAL':          4,
    'INTERRUPT_WINDOW':     7,
    'NMI_WINDOW':           8,
    'TASK_SWITCH':          9,
    'CPUID':                10,
    'HLT':                  12,
    'INVD':                 13,
    'INVLPG':               14,
    'RDPMC':                15,
    'RDTSC':                16,
    'VMCALL':               18,
    'VMCLEAR':              19,
    'VMLAUNCH':             20,
    'VMPTRLD':              21,
    'VMPTRST':              22,
    'VMREAD':               23,
    'VMRESUME':             24,
    'VMWRITE':              25,
    'VMOFF':                26,
    'VMON':                 27,
    'CR_ACCESS':            28,
    'DR_ACCESS':            29,
    'IO_INSTRUCTION':       30,
    'MSR_READ':             31,
    'MSR_WRITE':            32,
    'INVALID_STATE':        33,
    'MSR_LOAD_FAIL':        34,
    'MWAIT_INSTRUCTION':    36,
    'MONITOR_TRAP_FLAG':    37,
    'MONITOR_INSTRUCTION':  39,
    'PAUSE_INSTRUCTION':    40,
    'MCE_DURING_VMENTRY':   41,
    'TPR_BELOW_THRESHOLD':  43,
    'APIC_ACCESS':          44,
    'EOI_INDUCED':          45,
    'GDTR_IDTR':            46,
    'LDTR_TR':              47,
    'EPT_VIOLATION':        48,
    'EPT_MISCONFIG':        49,
    'INVEPT':               50,
    'RDTSCP':               51,
    'PREEMPTION_TIMER':     52,
    'INVVPID':              53,
    'WBINVD':               54,
    'XSETBV':               55,
    'APIC_WRITE':           56,
    'RDRAND':               57,
    'INVPCID':              58,
    'VMFUNC':               59,
    'ENCLS':                60,
    'RDSEED':               61,
    'PML_FULL':             62,
    'XSAVES':               63,
    'XRSTORS':              64,
    'UMWAIT':               67,
    'TPAUSE':               68,
    'BUS_LOCK':             74,
    'NOTIFY':               75,
}

SVM_EXIT_REASONS = {
    'READ_CR0':       0x000,
    'READ_CR2':       0x002,
    'READ_CR3':       0x003,
    'READ_CR4':       0x004,
    'READ_CR8':       0x008,
    'WRITE_CR0':      0x010,
    'WRITE_CR2':      0x012,
    'WRITE_CR3':      0x013,
    'WRITE_CR4':      0x014,
    'WRITE_CR8':      0x018,
    'READ_DR0':       0x020,
    'READ_DR1':       0x021,
    'READ_DR2':       0x022,
    'READ_DR3':       0x023,
    'READ_DR4':       0x024,
    'READ_DR5':       0x025,
    'READ_DR6':       0x026,
    'READ_DR7':       0x027,
    'WRITE_DR0':      0x030,
    'WRITE_DR1':      0x031,
    'WRITE_DR2':      0x032,
    'WRITE_DR3':      0x033,
    'WRITE_DR4':      0x034,
    'WRITE_DR5':      0x035,
    'WRITE_DR6':      0x036,
    'WRITE_DR7':      0x037,
    'EXCP_BASE':      0x040,
    'LAST_EXCP':      0x05f,
    'INTR':           0x060,
    'NMI':            0x061,
    'SMI':            0x062,
    'INIT':           0x063,
    'VINTR':          0x064,
    'CR0_SEL_WRITE':  0x065,
    'IDTR_READ':      0x066,
    'GDTR_READ':      0x067,
    'LDTR_READ':      0x068,
    'TR_READ':        0x069,
    'IDTR_WRITE':     0x06a,
    'GDTR_WRITE':     0x06b,
    'LDTR_