From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Tomas Glozar <tglozar@redhat.com>, John Kacur <jkacur@redhat.com>,
"lgoncalv@redhat.com" <lgoncalv@redhat.com>,
Furkan Onder <furkanonder@protonmail.com>
Subject: [for-next][PATCH 4/5] tools/rtla: Improve exception handling in timerlat_load.py
Date: Mon, 18 Nov 2024 16:41:26 -0500 [thread overview]
Message-ID: <20241118214150.069691382@goodmis.org> (raw)
In-Reply-To: 20241118214122.136581969@goodmis.org
From: furkanonder <furkanonder@protonmail.com>
The enhancements made to timerlat_load.py are intended to improve the script's exception handling.
Summary of the changes:
- Specific exceptions are now caught for CPU affinity and priority
settings, with clearer error messages provided.
- The timerlat file descriptor opening now includes handling for
PermissionError and OSError, with informative messages.
- In the infinite loop, generic exceptions have been replaced with
specific types like KeyboardInterrupt and IOError, improving feedback.
Before:
$ sudo python timerlat_load.py 122
Error setting affinity
After:
$ sudo python timerlat_load.py 122
Error setting affinity: [Errno 22] Invalid argument
Before:
$ sudo python timerlat_load.py 1 -p 950
Error setting priority
After:
$ sudo python timerlat_load.py 1 -p 950
Error setting priority: [Errno 22] Invalid argument
Before:
$ python timerlat_load.py 1
Error opening timerlat fd, did you run timerlat -U?
After:
$ python timerlat_load.py 1
Permission denied. Please check your access rights.
Cc: "lgoncalv@redhat.com" <lgoncalv@redhat.com>
Cc: "jkacur@redhat.com" <jkacur@redhat.com>
Link: https://lore.kernel.org/Q_k1s4hBtUy2px8ou0QKenjEK2_T_LoV8IxAE79aBakBogb-7uHp2fpET3oWtI1t3dy8uKjWeRzQOdKNzIzOOpyM4OjutJOriZ9TrGY6b-g=@protonmail.com
Signed-off-by: Furkan Onder <furkanonder@protonmail.com>
Reviewed-by: Tomas Glozar <tglozar@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
tools/tracing/rtla/sample/timerlat_load.py | 37 ++++++++++++----------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/tools/tracing/rtla/sample/timerlat_load.py b/tools/tracing/rtla/sample/timerlat_load.py
index d7341ed5127a..a819c3588073 100644
--- a/tools/tracing/rtla/sample/timerlat_load.py
+++ b/tools/tracing/rtla/sample/timerlat_load.py
@@ -31,43 +31,48 @@ args = parser.parse_args()
try:
affinity_mask = {args.cpu}
-except:
- print("Invalid cpu: " + args.cpu)
- exit(1)
-
-try:
os.sched_setaffinity(0, affinity_mask)
-except:
- print("Error setting affinity")
- exit(1)
+except Exception as e:
+ print(f"Error setting affinity: {e}")
+ sys.exit(1)
if args.prio:
try:
param = os.sched_param(args.prio)
os.sched_setscheduler(0, os.SCHED_FIFO, param)
- except:
- print("Error setting priority")
- exit(1)
+ except Exception as e:
+ print(f"Error setting priority: {e}")
+ sys.exit(1)
try:
timerlat_path = f"/sys/kernel/tracing/osnoise/per_cpu/cpu{args.cpu}/timerlat_fd"
timerlat_fd = open(timerlat_path, 'r')
-except:
+except PermissionError:
+ print("Permission denied. Please check your access rights.")
+ sys.exit(1)
+except OSError:
print("Error opening timerlat fd, did you run timerlat -U?")
- exit(1)
+ sys.exit(1)
try:
data_fd = open("/dev/full", 'r')
-except:
- print("Error opening data fd")
+except Exception as e:
+ print(f"Error opening data fd: {e}")
+ sys.exit(1)
while True:
try:
timerlat_fd.read(1)
data_fd.read(20 * 1024 * 1024)
- except:
+ except KeyboardInterrupt:
print("Leaving")
break
+ except IOError as e:
+ print(f"I/O error occurred: {e}")
+ break
+ except Exception as e:
+ print(f"Unexpected error: {e}")
+ break
timerlat_fd.close()
data_fd.close()
--
2.45.2
next prev parent reply other threads:[~2024-11-18 21:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 21:41 [for-next][PATCH 0/5] tools/tracing: Last minute updates for 6.13 Steven Rostedt
2024-11-18 21:41 ` [for-next][PATCH 1/5] rtla/timerlat: Do not set params->user_workload with -U Steven Rostedt
2024-11-18 21:41 ` [for-next][PATCH 2/5] tools/rtla: Improve code readability in timerlat_load.py Steven Rostedt
2024-11-18 21:41 ` [for-next][PATCH 3/5] tools/rtla: Enhance argument parsing " Steven Rostedt
2024-11-18 21:41 ` Steven Rostedt [this message]
2024-11-18 21:41 ` [for-next][PATCH 5/5] verification/dot2: Improve dot parser robustness Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241118214150.069691382@goodmis.org \
--to=rostedt@goodmis.org \
--cc=furkanonder@protonmail.com \
--cc=jkacur@redhat.com \
--cc=lgoncalv@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglozar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox