All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] cyclicteset: improvements to the python style in get_cyclictest_snapshot
@ 2020-07-06 20:17 John Kacur
  2020-07-06 20:17 ` [PATCH 2/7] rt-tests: pi_stress.8: Remove unused -t n from the manpage John Kacur
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: John Kacur @ 2020-07-06 20:17 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, John Kacur

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

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/cyclictest/get_cyclictest_snapshot.py | 38 +++++++++++++----------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/src/cyclictest/get_cyclictest_snapshot.py b/src/cyclictest/get_cyclictest_snapshot.py
index 7dddfc5d65b0..27fc629ca53e 100755
--- a/src/cyclictest/get_cyclictest_snapshot.py
+++ b/src/cyclictest/get_cyclictest_snapshot.py
@@ -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 <jkacur@redhat.com>
 
-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()
-- 
2.21.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/7] rt-tests: pi_stress.8: Remove unused -t n from the manpage
  2020-07-06 20:17 [PATCH 1/7] cyclicteset: improvements to the python style in get_cyclictest_snapshot John Kacur
@ 2020-07-06 20:17 ` John Kacur
  2020-07-06 20:17 ` [PATCH 3/7] rt-tests: ptsematest.8: Update the ptsematest man page John Kacur
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: John Kacur @ 2020-07-06 20:17 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, John Kacur

The -t option was replaced with the -D, --duration=TIME option
Remove it from the manpage as well.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/pi_tests/pi_stress.8 | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/src/pi_tests/pi_stress.8 b/src/pi_tests/pi_stress.8
index 5e2af6189ca1..ed03ad6187e7 100644
--- a/src/pi_tests/pi_stress.8
+++ b/src/pi_tests/pi_stress.8
@@ -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
-- 
2.21.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/7] rt-tests: ptsematest.8: Update the ptsematest man page
  2020-07-06 20:17 [PATCH 1/7] cyclicteset: improvements to the python style in get_cyclictest_snapshot John Kacur
  2020-07-06 20:17 ` [PATCH 2/7] rt-tests: pi_stress.8: Remove unused -t n from the manpage John Kacur
@ 2020-07-06 20:17 ` John Kacur
  2020-07-06 20:17 ` [PATCH 4/7] rt-tests: Add a man page for get_cyclictest_snapshot John Kacur
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: John Kacur @ 2020-07-06 20:17 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, John Kacur

The smp option should be a capital (-S)
Also fix the update synopsis to include missing and options

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/ptsematest/ptsematest.8 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/ptsematest/ptsematest.8 b/src/ptsematest/ptsematest.8
index 8f76bca4b6a8..5ee7d694d50d 100644
--- a/src/ptsematest/ptsematest.8
+++ b/src/ptsematest/ptsematest.8
@@ -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]
-- 
2.21.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/7] rt-tests: Add a man page for get_cyclictest_snapshot
  2020-07-06 20:17 [PATCH 1/7] cyclicteset: improvements to the python style in get_cyclictest_snapshot John Kacur
  2020-07-06 20:17 ` [PATCH 2/7] rt-tests: pi_stress.8: Remove unused -t n from the manpage John Kacur
  2020-07-06 20:17 ` [PATCH 3/7] rt-tests: ptsematest.8: Update the ptsematest man page John Kacur
@ 2020-07-06 20:17 ` John Kacur
  2020-07-06 20:17 ` [PATCH 5/7] rt-tests: Tweak the cyclictest man page John Kacur
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: John Kacur @ 2020-07-06 20:17 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, John Kacur

Add a man page for get_cyclictest_snapshot based on -h

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/cyclictest/get_cyclictest_snapshot.8 | 44 ++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 src/cyclictest/get_cyclictest_snapshot.8

diff --git a/src/cyclictest/get_cyclictest_snapshot.8 b/src/cyclictest/get_cyclictest_snapshot.8
new file mode 100644
index 000000000000..e9251a8e821f
--- /dev/null
+++ b/src/cyclictest/get_cyclictest_snapshot.8
@@ -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>
-- 
2.21.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/7] rt-tests: Tweak the cyclictest man page
  2020-07-06 20:17 [PATCH 1/7] cyclicteset: improvements to the python style in get_cyclictest_snapshot John Kacur
                   ` (2 preceding siblings ...)
  2020-07-06 20:17 ` [PATCH 4/7] rt-tests: Add a man page for get_cyclictest_snapshot John Kacur
@ 2020-07-06 20:17 ` John Kacur
  2020-07-06 20:17 ` [PATCH 6/7] rt-tests: Add some files like get_cyclictest_snapshot to .gitignore John Kacur
  2020-07-06 20:17 ` [PATCH 7/7] rt-tests: get_cyclictest_snapshot: Warn if no cyclictest instance found John Kacur
  5 siblings, 0 replies; 7+ messages in thread
From: John Kacur @ 2020-07-06 20:17 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, John Kacur

Tweak the cyclictest man page with the .SY macro to make the cyclictest
command stand out apart from the options

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/cyclictest/cyclictest.8 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/cyclictest/cyclictest.8 b/src/cyclictest/cyclictest.8
index 00e2d2403996..44b5d0dbcc4a 100644
--- a/src/cyclictest/cyclictest.8
+++ b/src/cyclictest/cyclictest.8
@@ -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 ]"
-- 
2.21.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 6/7] rt-tests: Add some files like get_cyclictest_snapshot to .gitignore
  2020-07-06 20:17 [PATCH 1/7] cyclicteset: improvements to the python style in get_cyclictest_snapshot John Kacur
                   ` (3 preceding siblings ...)
  2020-07-06 20:17 ` [PATCH 5/7] rt-tests: Tweak the cyclictest man page John Kacur
@ 2020-07-06 20:17 ` John Kacur
  2020-07-06 20:17 ` [PATCH 7/7] rt-tests: get_cyclictest_snapshot: Warn if no cyclictest instance found John Kacur
  5 siblings, 0 replies; 7+ messages in thread
From: John Kacur @ 2020-07-06 20:17 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, John Kacur

Add some files like get_cyclictest_snapshot and .xz files etc

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 .gitignore | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/.gitignore b/.gitignore
index f7574ef94900..bc01575141bb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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__/
-- 
2.21.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 7/7] rt-tests: get_cyclictest_snapshot: Warn if no cyclictest instance found
  2020-07-06 20:17 [PATCH 1/7] cyclicteset: improvements to the python style in get_cyclictest_snapshot John Kacur
                   ` (4 preceding siblings ...)
  2020-07-06 20:17 ` [PATCH 6/7] rt-tests: Add some files like get_cyclictest_snapshot to .gitignore John Kacur
@ 2020-07-06 20:17 ` John Kacur
  5 siblings, 0 replies; 7+ messages in thread
From: John Kacur @ 2020-07-06 20:17 UTC (permalink / raw)
  To: RT; +Cc: Clark Williams, 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.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 src/cyclictest/get_cyclictest_snapshot.py | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/cyclictest/get_cyclictest_snapshot.py b/src/cyclictest/get_cyclictest_snapshot.py
index 27fc629ca53e..aed9681e4cc5 100755
--- a/src/cyclictest/get_cyclictest_snapshot.py
+++ b/src/cyclictest/get_cyclictest_snapshot.py
@@ -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()
 
-- 
2.21.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-07-06 20:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-06 20:17 [PATCH 1/7] cyclicteset: improvements to the python style in get_cyclictest_snapshot John Kacur
2020-07-06 20:17 ` [PATCH 2/7] rt-tests: pi_stress.8: Remove unused -t n from the manpage John Kacur
2020-07-06 20:17 ` [PATCH 3/7] rt-tests: ptsematest.8: Update the ptsematest man page John Kacur
2020-07-06 20:17 ` [PATCH 4/7] rt-tests: Add a man page for get_cyclictest_snapshot John Kacur
2020-07-06 20:17 ` [PATCH 5/7] rt-tests: Tweak the cyclictest man page John Kacur
2020-07-06 20:17 ` [PATCH 6/7] rt-tests: Add some files like get_cyclictest_snapshot to .gitignore John Kacur
2020-07-06 20:17 ` [PATCH 7/7] rt-tests: get_cyclictest_snapshot: Warn if no cyclictest instance found John Kacur

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.