Skip to content

Commit

Permalink
tools/rtla: Improve exception handling in timerlat_load.py
Browse files Browse the repository at this point in the history
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: "[email protected]" <[email protected]>
Cc: "[email protected]" <[email protected]>
Link: https://lore.kernel.org/Q_k1s4hBtUy2px8ou0QKenjEK2_T_LoV8IxAE79aBakBogb-7uHp2fpET3oWtI1t3dy8uKjWeRzQOdKNzIzOOpyM4OjutJOriZ9TrGY6b-g=@protonmail.com
Signed-off-by: Furkan Onder <[email protected]>
Reviewed-by: Tomas Glozar <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
  • Loading branch information
furkanonder authored and rostedt committed Nov 19, 2024
1 parent bd26818 commit 4d8c1ba
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions tools/tracing/rtla/sample/timerlat_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,48 @@

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()

0 comments on commit 4d8c1ba

Please sign in to comment.