support to specify maxinum of threads and edge cases. The default values make map taking more than 0.5G memory which cause out-of-memory issue on some systems.
also fix an issue with python `open` so the open file is automatically closed upon file reading is done.
Comma-separated list of unlock symbols to trace. Default is
pthread_mutex_unlock. These symbols cannot be inlined in the binary.
.TP
+\-t THREADS, --threads THREADS
+Specifies the maximum number of threads to trace. default 65536.
+Note. 40 bytes per thread.
+.TP
+\-e EDGES, --edges EDGES
+Specifies the maximum number of edge cases that can be
+recorded. default 65536. Note. 88 bytes per edge case.
+.TP
pid
Pid to trace
.SH EXAMPLES
};
// Map of thread ID -> array of (mutex addresses, stack id)
-BPF_HASH(thread_to_held_mutexes, u32, struct thread_to_held_mutex_leaf_t, 2097152);
+BPF_HASH(thread_to_held_mutexes, u32, struct thread_to_held_mutex_leaf_t, MAX_THREADS);
// Key type for edges. Represents an edge from mutex1 => mutex2.
struct edges_key_t {
};
// Represents all edges currently in the mutex wait graph.
-BPF_HASH(edges, struct edges_key_t, struct edges_leaf_t, 2097152);
+BPF_HASH(edges, struct edges_key_t, struct edges_leaf_t, MAX_EDGES);
// Info about parent thread when a child thread is created.
struct thread_created_leaf_t {
help='Comma-separated list of unlock symbols to trace. Default is '
'pthread_mutex_unlock. These symbols cannot be inlined in the binary.',
)
+ parser.add_argument(
+ '-t', '--threads', type=int, default=65536,
+ help='Specifies the maximum number of threads to trace. default 65536. '
+ 'Note. 40 bytes per thread.'
+ )
+ parser.add_argument(
+ '-e', '--edges', type=int, default=65536,
+ help='Specifies the maximum number of edge cases that can be recorded. '
+ 'default 65536. Note. 88 bytes per edge case.'
+ )
args = parser.parse_args()
if not args.binary:
try:
print('%s. Is the process (pid=%d) running?' % (str(e), args.pid))
sys.exit(1)
- bpf = BPF(src_file=b'deadlock.c')
+ with open('deadlock.c') as f:
+ text = f.read()
+ text = text.replace(b'MAX_THREADS', str(args.threads));
+ text = text.replace(b'MAX_EDGES', str(args.edges));
+ bpf = BPF(text=text)
# Trace where threads are created
bpf.attach_kretprobe(event=bpf.get_syscall_fnname('clone'), fn_name='trace_clone')
Comma-separated list of unlock symbols to trace.
Default is pthread_mutex_unlock. These symbols cannot
be inlined in the binary.
+ -t THREADS, --threads THREADS
+ Specifies the maximum number of threads to trace.
+ default 65536. Note. 40 bytes per thread.
+ -e EDGES, --edges EDGES
+ Specifies the maximum number of edge cases that can be
+ recorded. default 65536. Note. 88 bytes per edge case.
Examples:
deadlock 181 # Analyze PID 181