cyclicteset: improvements to the python style in get_cyclictest_snapshot
PATCH 1/7 cyclicteset: improvements to the python style in get_cyclictest_snapshot
Improvements to the python style in get_cyclictest_snapshot
- Add comments to the methods, functions, class and moduleb
- Put imports on individual lines
- Use "is" and "is not" with None insteald of == or !=
- Don't compare the length of lists to zero, to determine if they are empty
--- src/cyclictest/get_cyclictest_snapshot.py | 38 +++++++++++++---------- 1 file changed, 22 insertions(+), 16 deletions(-)
src/cyclictest/get_cyclictest_snapshot.py +22 -16
@@ -1,9 +1,14 @@ #!/usr/bin/env python3 +""" Program to get a snapshot of a running instance of cyclictest """ # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (C) 2020 John Kacur <[email protected]> -import subprocess, signal, argparse, re, glob, sys +import subprocess +import argparse +import re +import glob +import sys parser = argparse.ArgumentParser(description='Get a snapshot of running instances of cyclictest') parser.add_argument('-l', '--list', action='store_true', help='list the main pid(s) of running instances of cyclictest')
@@ -11,8 +16,8 @@ parser.add_argument('-s', '--snapshot', nargs='*', metavar='pid', help='take a s parser.add_argument('-p', '--print', nargs='*', metavar='pid', help='print the snapshots') args = parser.parse_args() - class Snapshot: + """ Class for getting a snapshot of a running cyclictest instance """ def __init__(self): self.pids = []
@@ -20,6 +25,7 @@ class Snapshot: self.refresh() def refresh(self): + """ Create a list of running cyclictest instances. """ self.pids = [] self.shm_files = glob.glob('/dev/shm/cyclictest*') self.shm_files.sort()
@@ -27,21 +33,21 @@ class Snapshot: pid = re.search('[0-9]*$', shm_file).group() self.pids += [pid] - # Send USR2 to all running instances of cyclictest or just to - # a specific pid (spid) if specified def take_snapshot(self, spids=None): + """ Send USR2 to all running instances of cyclictest, + or just to a specific pid (spids) if specified. """ for pid in self.pids: - if (spids == None) or (pid in spids): - # print("kill -s USR2 ", pid) + if (spids is None) or (pid in spids): subprocess.run(["kill", "-s", "USR2", pid]) def print_pids(self): + """ Print the list of pids of running cyclictest instances. """ for pid in self.pids: print(pid) - # Print the data in /dev/shm/cyclictest* def print(self, spids=None): - if spids == None: + """ Print the data in /dev/shm/cyclictest* """ + if spids is None: for shm_file in self.shm_files: with open(shm_file, 'r') as f: data = f.read()
@@ -59,17 +65,17 @@ snapshot = Snapshot() if args.list: snapshot.print_pids() -if args.snapshot != None: - if len(args.snapshot) == 0: - snapshot.take_snapshot() - else: +if args.snapshot is not None: + if args.snapshot: snapshot.take_snapshot(args.snapshot) - -if args.print != None: - if len(args.print) == 0: - snapshot.print() else: + snapshot.take_snapshot() + +if args.print is not None: + if args.print: snapshot.print(args.print) + else: + snapshot.print() if len(sys.argv) == 1: snapshot.take_snapshot()
Signature · 1 line
2.21.3
PATCH 2/7 rt-tests: pi_stress.8: Remove unused -t n from the manpage
The -t option was replaced with the -D, --duration=TIME option Remove it from the manpage as well.
--- src/pi_tests/pi_stress.8 | 6 ------ 1 file changed, 6 deletions(-)
src/pi_tests/pi_stress.8 +0 -6
@@ -15,8 +15,6 @@ pi_stress \- a stress test for POSIX Priority Inheritance mutexes .B pi_stress .RB [ \-i|\-\-inversions .IR inversions ] -.RB [ \-t|\-\-duration -.IR seconds ] .RB [ \-g|\-\-groups .IR groups .RB [ \-d|\-\-debug ]
@@ -50,10 +48,6 @@ Run for .I n number of inversion conditions. This is the total number of inversions for all inversion groups. Default is \-1 for infinite. -.IP "\-t n|\-\-duration=n" -Run the test for -.I n -seconds and then terminate. .IP "\-g n|\-\-groups=n" The number of inversion groups to run. Defaults to 10. .IP \-d|\-\-debug
Signature · 1 line
2.21.3
PATCH 3/7 rt-tests: ptsematest.8: Update the ptsematest man page
In reply to John KacurThe smp option should be a capital (-S)
Also fix the update synopsis to include missing and options
--- src/ptsematest/ptsematest.8 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
src/ptsematest/ptsematest.8 +3 -3
@@ -2,9 +2,9 @@ .SH "NAME" .LP \fBptsematest\fR \- Start two threads and measure the latency of interprocess communication with POSIX mutex. -.SH "SYNTAX" +.SH "SYNOPSIS" .LP -ptsematest [-a|-a PROC] [-b USEC] [-d DIST] [-i INTV] [-l loops] [-p PRIO] [-t|-t NUM] +ptsematest [-a|--affinity [PROC]] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME][-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-S|--smp] [-t|--threads [NUM]] .br .SH "DESCRIPTION" .LP
@@ -35,7 +35,7 @@ Set the number of loops. The default is 0 (endless). This option is useful for a .B \-p, \-\-prio=PRIO Set the priority of the process. .TP -.B \-s, \-\-smp +.B \-S, \-\-smp SMP testing: options -a -t and same priority .TP .B \-t, \-\-threads[=NUM]
Signature · 1 line
2.21.3
PATCH 4/7 rt-tests: Add a man page for get_cyclictest_snapshot
In reply to John KacurAdd a man page for get_cyclictest_snapshot based on -h
--- src/cyclictest/get_cyclictest_snapshot.8 | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/cyclictest/get_cyclictest_snapshot.8
src/cyclictest/get_cyclictest_snapshot.8 new file +44 -0
@@ -0,0 +1,44 @@ +.\" Hey, EMACS: -*- nroff -*- +.TH GET_CYCLICTEST_SNAPSHOT 8 "July 6, 2020" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp <n> insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +get_cyclictest_snapshot \- Get a snapshot of running instances of cyclictest +.SH SYNOPSIS +.SY get_cyclictest_snapshot +.OP [\-h]\ [\-l]\ [\-s\ [pid [pid ...]]] +.br +.OP [\-p\ [pid\ [pid ...]]] +.SH OPTIONS +Without options, this program will send USR2 to cyclictest to create a snapshot and then print it out. +.br +.TP +Optional arguments: +.TP +.B -h, --help +show this help message and exit +.TP +.B -l, --list +list the main pid(s) of running instances of cyclictest +.TP +.B -s [pid [pid ...]], --snapshot [pid [pid ...]] +take a snapshot of running instances of cyclictest +.br +by sending USR2 to cyclictest +.TP +.B -p [pid [pid ...]], --print [pid [pid ...]] +print the snapshots +.SH SEE ALSO +.BR cyclictest (8), +.SH AUTHOR +get_cyclictest_snapshot was written by John Kacur <jkacur at redhat dot com>
Signature · 1 line
2.21.3
PATCH 5/7 rt-tests: Tweak the cyclictest man page
In reply to John KacurTweak the cyclictest man page with the .SY macro to make the cyclictest command stand out apart from the options
--- src/cyclictest/cyclictest.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/cyclictest/cyclictest.8 +1 -1
@@ -15,7 +15,7 @@ .SH NAME cyclictest \- High resolution test program .SH SYNOPSIS -.B cyclictest +.SY cyclictest .RI "[ \-hfmnqrsvMS ] [\-a " proc " ] [\-A " align " ] [\-b " usec " ] [\-c " clock " ] [\-d " dist " ] \ [\-h " histogram " ] [\-i " intv " ] [\-l " loop " ] [\-o " red " ] [\-p " prio " ] \ [\-t " num " ] [\-D " time "] [\-w] [\-W] [\-y " policy " ] [ \-S | \-U ]"
Signature · 1 line
2.21.3
PATCH 6/7 rt-tests: Add some files like get_cyclictest_snapshot to .gitignore
In reply to John KacurAdd some files like get_cyclictest_snapshot and .xz files etc
--- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+)
.gitignore +6 -0
@@ -6,6 +6,10 @@ *.d *.patch *.a +*.gz +*.bz2 +*.xz +*.asc tmp patches ChangeLog
@@ -34,8 +38,10 @@ SRPMS /deadline_test /queuelat /ssdd +/get_cyclictest_snapshot rt-tests.spec tags TAGS cscope.* +src/cyclictest/__pycache__/
Signature · 1 line
2.21.3
PATCH 7/7 rt-tests: get_cyclictest_snapshot: Warn if no cyclictest instance found
In reply to John Kacur- Print a warning if no cyclictest instance is found.
- Also fix up the method take_snapshot for the case when the user provides a pid.
--- src/cyclictest/get_cyclictest_snapshot.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
src/cyclictest/get_cyclictest_snapshot.py +21 -2
@@ -19,6 +19,14 @@ args = parser.parse_args() class Snapshot: """ Class for getting a snapshot of a running cyclictest instance """ + warned = False + + def print_warning(): + """ print a warning one time only even if called multiple times """ + if not Snapshot.warned: + Snapshot.warned = True + print("No cyclictest instance found") + def __init__(self): self.pids = [] self.shm_files = []
@@ -36,18 +44,27 @@ class Snapshot: def take_snapshot(self, spids=None): """ Send USR2 to all running instances of cyclictest, or just to a specific pid (spids) if specified. """ - for pid in self.pids: - if (spids is None) or (pid in spids): + if spids is None: + if not self.pids: + Snapshot.print_warning() + for pid in self.pids: + subprocess.run(["kill", "-s", "USR2", pid]) + else: + for pid in spids: subprocess.run(["kill", "-s", "USR2", pid]) def print_pids(self): """ Print the list of pids of running cyclictest instances. """ + if not self.pids: + Snapshot.print_warning() for pid in self.pids: print(pid) def print(self, spids=None): """ Print the data in /dev/shm/cyclictest* """ if spids is None: + if not self.shm_files: + Snapshot.print_warning() for shm_file in self.shm_files: with open(shm_file, 'r') as f: data = f.read()
@@ -59,6 +76,8 @@ class Snapshot: with open(shm_file, 'r') as f: data = f.read() print(data) + else: + Snapshot.print_warning() snapshot = Snapshot()
Signature · 1 line
2.21.3