Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) # failed system call counts, by pid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) # (c) 2010, Tom Zanussi <tzanussi@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) # Licensed under the terms of the GNU GPL License version 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) # Displays system-wide failed system call totals, broken down by pid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) # If a [comm] arg is specified, only syscalls called by [comm] are displayed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) from __future__ import print_function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) import os
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) import sys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) sys.path.append(os.environ['PERF_EXEC_PATH'] + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) from perf_trace_context import *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) from Core import *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) from Util import *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) usage = "perf script -s syscall-counts-by-pid.py [comm|pid]\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) for_comm = None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) for_pid = None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) if len(sys.argv) > 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	sys.exit(usage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if len(sys.argv) > 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 		for_pid = int(sys.argv[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	except:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 		for_comm = sys.argv[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) syscalls = autodict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) def trace_begin():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	print("Press control+C to stop and show the summary")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) def trace_end():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	print_error_totals()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) def raw_syscalls__sys_exit(event_name, context, common_cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	common_secs, common_nsecs, common_pid, common_comm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	common_callchain, id, ret):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	if (for_comm and common_comm != for_comm) or \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	   (for_pid  and common_pid  != for_pid ):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	if ret < 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 		try:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 			syscalls[common_comm][common_pid][id][ret] += 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 		except TypeError:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 			syscalls[common_comm][common_pid][id][ret] = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) def syscalls__sys_exit(event_name, context, common_cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	common_secs, common_nsecs, common_pid, common_comm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	id, ret):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	raw_syscalls__sys_exit(**locals())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) def print_error_totals():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	if for_comm is not None:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 		print("\nsyscall errors for %s:\n" % (for_comm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 		print("\nsyscall errors:\n")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	print("%-30s  %10s" % ("comm [pid]", "count"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	print("%-30s  %10s" % ("------------------------------", "----------"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	comm_keys = syscalls.keys()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	for comm in comm_keys:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 		pid_keys = syscalls[comm].keys()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 		for pid in pid_keys:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 			print("\n%s [%d]" % (comm, pid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 			id_keys = syscalls[comm][pid].keys()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 			for id in id_keys:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 				print("  syscall: %-16s" % syscall_name(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 				ret_keys = syscalls[comm][pid][id].keys()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 				for ret, val in sorted(syscalls[comm][pid][id].items(), key = lambda kv: (kv[1], kv[0]), reverse = True):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 					print("    err = %-20s  %10d" % (strerror(ret), val))