- Implement jsc#SLE-13784
* Add patches: switch-to-argparse.patch, add-command-line-switch-s-to-update.patch,
add-command-line-switch-c-to-csv.patch, add-command-line-switch-z-skip-zero-records.patch,
add-command-line-switch-L-to-log-file.patch, add-sample-systemd-unit.patch
* patching is conditional, depending on kernel version
OBS-URL: https://build.opensuse.org/request/show/848387
OBS-URL: https://build.opensuse.org/package/show/Virtualization/kvm_stat?expand=0&rev=25
96 lines
3.5 KiB
Diff
96 lines
3.5 KiB
Diff
commit da1fda288943c37de8e1513b98f6dda40c8cd421
|
|
Author: Stefan Raspl <raspl@de.ibm.com>
|
|
Date: Thu Apr 2 10:57:03 2020 +0200
|
|
|
|
tools/kvm_stat: add command line switch '-z' to skip zero records
|
|
|
|
When running in logging mode, skip records with all zeros (=empty records)
|
|
to preserve space when logging to files.
|
|
|
|
Signed-off-by: Stefan Raspl <raspl@de.ibm.com>
|
|
Message-Id: <20200402085705.61155-2-raspl@linux.ibm.com>
|
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
|
diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
|
|
index e83fc8e868f4..d6cced4e1ef4 100755
|
|
--- a/tools/kvm/kvm_stat/kvm_stat
|
|
+++ b/tools/kvm/kvm_stat/kvm_stat
|
|
@@ -1500,8 +1500,7 @@ class StdFormat(object):
|
|
def get_banner(self):
|
|
return self._banner
|
|
|
|
- @staticmethod
|
|
- def get_statline(keys, s):
|
|
+ def get_statline(self, keys, s):
|
|
res = ''
|
|
for key in keys:
|
|
res += ' %9d' % s[key].delta
|
|
@@ -1517,8 +1516,7 @@ class CSVFormat(object):
|
|
def get_banner(self):
|
|
return self._banner
|
|
|
|
- @staticmethod
|
|
- def get_statline(keys, s):
|
|
+ def get_statline(self, keys, s):
|
|
return reduce(lambda res, key: "{},{!s}".format(res, s[key].delta),
|
|
keys, '')
|
|
|
|
@@ -1527,14 +1525,21 @@ def log(stats, opts, frmt, keys):
|
|
"""Prints statistics as reiterating key block, multiple value blocks."""
|
|
line = 0
|
|
banner_repeat = 20
|
|
+ banner_printed = False
|
|
+
|
|
while True:
|
|
try:
|
|
time.sleep(opts.set_delay)
|
|
- if line % banner_repeat == 0:
|
|
+ if line % banner_repeat == 0 and not banner_printed:
|
|
print(frmt.get_banner())
|
|
- print(datetime.now().strftime("%Y-%m-%d %H:%M:%S") +
|
|
- frmt.get_statline(keys, stats.get()))
|
|
- line += 1
|
|
+ banner_printed = True
|
|
+ values = stats.get()
|
|
+ if (not opts.skip_zero_records or
|
|
+ any(values[k].delta != 0 for k in keys)):
|
|
+ print(datetime.now().strftime("%Y-%m-%d %H:%M:%S") +
|
|
+ frmt.get_statline(keys, values))
|
|
+ line += 1
|
|
+ banner_printed = False
|
|
except KeyboardInterrupt:
|
|
break
|
|
|
|
@@ -1655,9 +1660,16 @@ Press any other key to refresh statistics immediately.
|
|
default=False,
|
|
help='retrieve statistics from tracepoints',
|
|
)
|
|
+ argparser.add_argument('-z', '--skip-zero-records',
|
|
+ action='store_true',
|
|
+ default=False,
|
|
+ help='omit records with all zeros in logging mode',
|
|
+ )
|
|
options = argparser.parse_args()
|
|
if options.csv and not options.log:
|
|
sys.exit('Error: Option -c/--csv requires -l/--log')
|
|
+ if options.skip_zero_records and not options.log:
|
|
+ sys.exit('Error: Option -z/--skip-zero-records requires -l/--log')
|
|
try:
|
|
# verify that we were passed a valid regex up front
|
|
re.compile(options.fields)
|
|
diff --git a/tools/kvm/kvm_stat/kvm_stat.txt b/tools/kvm/kvm_stat/kvm_stat.txt
|
|
index a97ded2aedad..24296dccc00a 100644
|
|
--- a/tools/kvm/kvm_stat/kvm_stat.txt
|
|
+++ b/tools/kvm/kvm_stat/kvm_stat.txt
|
|
@@ -104,6 +104,10 @@ OPTIONS
|
|
--tracepoints::
|
|
retrieve statistics from tracepoints
|
|
|
|
+*z*::
|
|
+--skip-zero-records::
|
|
+ omit records with all zeros in logging mode
|
|
+
|
|
SEE ALSO
|
|
--------
|
|
'perf'(1), 'trace-cmd'(1)
|