qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 29/34] scripts/kvm/kvm_stat: Move to argparse and ad


From: Janosch Frank
Subject: [Qemu-devel] [PATCH 29/34] scripts/kvm/kvm_stat: Move to argparse and add description
Date: Thu, 10 Dec 2015 13:12:59 +0100

The OptionParser is deprecated since the introduction of the
ArgumentParser in 2.7.

Additionally added a description text for the script, so new users
don't have to guess its purpose and inner workings.
---
 scripts/kvm/kvm_stat | 86 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 53 insertions(+), 33 deletions(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index aa3de71..109c22c 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -15,7 +15,7 @@ import curses
 import sys
 import os
 import time
-import optparse
+import argparse
 import ctypes
 import fcntl
 import resource
@@ -622,38 +622,58 @@ def log(stats):
         line += 1
 
 def get_options():
-    optparser = optparse.OptionParser()
-    optparser.add_option('-1', '--once', '--batch',
-                         action='store_true',
-                         default=False,
-                         dest='once',
-                         help='run in batch mode for one second',
-                         )
-    optparser.add_option('-l', '--log',
-                         action='store_true',
-                         default=False,
-                         dest='log',
-                         help='run in logging mode (like vmstat)',
-                         )
-    optparser.add_option('-t', '--tracepoints',
-                         action='store_true',
-                         default=False,
-                         dest='tracepoints',
-                         help='retrieve statistics from tracepoints',
-                         )
-    optparser.add_option('-d', '--debugfs',
-                         action='store_true',
-                         default=False,
-                         dest='debugfs',
-                         help='retrieve statistics from debugfs',
-                         )
-    optparser.add_option('-f', '--fields',
-                         action='store',
-                         default=None,
-                         dest='fields',
-                         help='fields to display (regex)',
-                         )
-    (options, _) = optparser.parse_args(sys.argv)
+    description_text = """
+This script displays various statistics about VMs running under KVM.
+The statistics are gathered from the KVM debugfs entries and / or the
+currently available perf traces.
+
+The monitoring takes additional cpu cycles and might affect the VM's
+performance.
+
+Requirements:
+- Access to:
+    /sys/kernel/debug/kvm
+    /sys/kernel/debug/trace/events/*
+    /proc/pid/task
+- /proc/sys/kernel/perf_event_paranoid < 1 if user has no
+  CAP_SYS_ADMIN and perf events are used.
+- CAP_SYS_RESOURCE if the hard limit is not high enough to allow
+  the large number of files that are possibly opened.
+"""
+    formatter = argparse.RawTextHelpFormatter
+    parser = argparse.ArgumentParser(description=description_text,
+                                     formatter_class=formatter)
+    parser.add_argument('-1', '--once', '--batch',
+                        action='store_true',
+                        default=False,
+                        dest='once',
+                        help='run in batch mode for one second',
+                        )
+    parser.add_argument('-l', '--log',
+                        action='store_true',
+                        default=False,
+                        dest='log',
+                        help='run in logging mode (like vmstat)',
+                        )
+    parser.add_argument('-t', '--tracepoints',
+                        action='store_true',
+                        default=False,
+                        dest='tracepoints',
+                        help='retrieve statistics from tracepoints',
+                        )
+    parser.add_argument('-d', '--debugfs',
+                        action='store_true',
+                        default=False,
+                        dest='debugfs',
+                        help='retrieve statistics from debugfs',
+                        )
+    parser.add_argument('-f', '--fields',
+                        action='store',
+                        default=None,
+                        dest='fields',
+                        help='fields to display (regex)',
+                        )
+    options = parser.parse_args()
     return options
 
 def get_providers(options):
-- 
2.3.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]