• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2012 Google, Inc.
4  */
5 
6 #undef TRACE_SYSTEM
7 #define TRACE_SYSTEM binder
8 
9 #if !defined(_BINDER_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
10 #define _BINDER_TRACE_H
11 
12 #include <linux/tracepoint.h>
13 
14 struct binder_buffer;
15 struct binder_node;
16 struct binder_proc;
17 struct binder_alloc;
18 struct binder_ref_data;
19 struct binder_thread;
20 struct binder_transaction;
21 
22 TRACE_EVENT(binder_ioctl,
23 	TP_PROTO(unsigned int cmd, unsigned long arg),
24 	TP_ARGS(cmd, arg),
25 
26 	TP_STRUCT__entry(
27 		__field(unsigned int, cmd)
28 		__field(unsigned long, arg)
29 	),
30 	TP_fast_assign(
31 		__entry->cmd = cmd;
32 		__entry->arg = arg;
33 	),
34 	TP_printk("cmd=0x%x arg=0x%lx", __entry->cmd, __entry->arg)
35 );
36 
37 DECLARE_EVENT_CLASS(binder_lock_class,
38 	TP_PROTO(const char *tag),
39 	TP_ARGS(tag),
40 	TP_STRUCT__entry(
41 		__field(const char *, tag)
42 	),
43 	TP_fast_assign(
44 		__entry->tag = tag;
45 	),
46 	TP_printk("tag=%s", __entry->tag)
47 );
48 
49 #define DEFINE_BINDER_LOCK_EVENT(name)	\
50 DEFINE_EVENT(binder_lock_class, name,	\
51 	TP_PROTO(const char *func), \
52 	TP_ARGS(func))
53 
54 DEFINE_BINDER_LOCK_EVENT(binder_lock);
55 DEFINE_BINDER_LOCK_EVENT(binder_locked);
56 DEFINE_BINDER_LOCK_EVENT(binder_unlock);
57 
58 DECLARE_EVENT_CLASS(binder_function_return_class,
59 	TP_PROTO(int ret),
60 	TP_ARGS(ret),
61 	TP_STRUCT__entry(
62 		__field(int, ret)
63 	),
64 	TP_fast_assign(
65 		__entry->ret = ret;
66 	),
67 	TP_printk("ret=%d", __entry->ret)
68 );
69 
70 #define DEFINE_BINDER_FUNCTION_RETURN_EVENT(name)	\
71 DEFINE_EVENT(binder_function_return_class, name,	\
72 	TP_PROTO(int ret), \
73 	TP_ARGS(ret))
74 
75 DEFINE_BINDER_FUNCTION_RETURN_EVENT(binder_ioctl_done);
76 DEFINE_BINDER_FUNCTION_RETURN_EVENT(binder_write_done);
77 DEFINE_BINDER_FUNCTION_RETURN_EVENT(binder_read_done);
78 
79 TRACE_EVENT(binder_set_priority,
80 	TP_PROTO(int proc, int thread, unsigned int old_prio,
81 		 unsigned int new_prio, unsigned int desired_prio),
82 	TP_ARGS(proc, thread, old_prio, new_prio, desired_prio),
83 
84 	TP_STRUCT__entry(
85 		__field(int, proc)
86 		__field(int, thread)
87 		__field(unsigned int, old_prio)
88 		__field(unsigned int, new_prio)
89 		__field(unsigned int, desired_prio)
90 	),
91 	TP_fast_assign(
92 		__entry->proc = proc;
93 		__entry->thread = thread;
94 		__entry->old_prio = old_prio;
95 		__entry->new_prio = new_prio;
96 		__entry->desired_prio = desired_prio;
97 	),
98 	TP_printk("proc=%d thread=%d old=%d => new=%d desired=%d",
99 		  __entry->proc, __entry->thread, __entry->old_prio,
100 		  __entry->new_prio, __entry->desired_prio)
101 );
102 
103 TRACE_EVENT(binder_wait_for_work,
104 	TP_PROTO(bool proc_work, bool transaction_stack, bool thread_todo),
105 	TP_ARGS(proc_work, transaction_stack, thread_todo),
106 
107 	TP_STRUCT__entry(
108 		__field(bool, proc_work)
109 		__field(bool, transaction_stack)
110 		__field(bool, thread_todo)
111 	),
112 	TP_fast_assign(
113 		__entry->proc_work = proc_work;
114 		__entry->transaction_stack = transaction_stack;
115 		__entry->thread_todo = thread_todo;
116 	),
117 	TP_printk("proc_work=%d transaction_stack=%d thread_todo=%d",
118 		  __entry->proc_work, __entry->transaction_stack,
119 		  __entry->thread_todo)
120 );
121 
122 TRACE_EVENT(binder_txn_latency_free,
123 	TP_PROTO(struct binder_transaction *t,
124 		 int from_proc, int from_thread,
125 		 int to_proc, int to_thread),
126 	TP_ARGS(t, from_proc, from_thread, to_proc, to_thread),
127 	TP_STRUCT__entry(
128 		__field(int, debug_id)
129 		__field(int, from_proc)
130 		__field(int, from_thread)
131 		__field(int, to_proc)
132 		__field(int, to_thread)
133 		__field(unsigned int, code)
134 		__field(unsigned int, flags)
135 	),
136 	TP_fast_assign(
137 		__entry->debug_id = t->debug_id;
138 		__entry->from_proc = from_proc;
139 		__entry->from_thread = from_thread;
140 		__entry->to_proc = to_proc;
141 		__entry->to_thread = to_thread;
142 		__entry->code = t->code;
143 		__entry->flags = t->flags;
144 	),
145 	TP_printk("transaction=%d from %d:%d to %d:%d flags=0x%x code=0x%x",
146 		  __entry->debug_id, __entry->from_proc, __entry->from_thread,
147 		  __entry->to_proc, __entry->to_thread, __entry->code,
148 		  __entry->flags)
149 );
150 
151 TRACE_EVENT(binder_transaction,
152 	TP_PROTO(bool reply, struct binder_transaction *t,
153 		 struct binder_node *target_node),
154 	TP_ARGS(reply, t, target_node),
155 	TP_STRUCT__entry(
156 		__field(int, debug_id)
157 		__field(int, target_node)
158 		__field(int, to_proc)
159 		__field(int, to_thread)
160 		__field(int, reply)
161 		__field(unsigned int, code)
162 		__field(unsigned int, flags)
163 	),
164 	TP_fast_assign(
165 		__entry->debug_id = t->debug_id;
166 		__entry->target_node = target_node ? target_node->debug_id : 0;
167 		__entry->to_proc = t->to_proc->pid;
168 		__entry->to_thread = t->to_thread ? t->to_thread->pid : 0;
169 		__entry->reply = reply;
170 		__entry->code = t->code;
171 		__entry->flags = t->flags;
172 	),
173 	TP_printk("transaction=%d dest_node=%d dest_proc=%d dest_thread=%d reply=%d flags=0x%x code=0x%x",
174 		  __entry->debug_id, __entry->target_node,
175 		  __entry->to_proc, __entry->to_thread,
176 		  __entry->reply, __entry->flags, __entry->code)
177 );
178 
179 TRACE_EVENT(binder_transaction_received,
180 	TP_PROTO(struct binder_transaction *t),
181 	TP_ARGS(t),
182 
183 	TP_STRUCT__entry(
184 		__field(int, debug_id)
185 	),
186 	TP_fast_assign(
187 		__entry->debug_id = t->debug_id;
188 	),
189 	TP_printk("transaction=%d", __entry->debug_id)
190 );
191 
192 TRACE_EVENT(binder_transaction_node_to_ref,
193 	TP_PROTO(struct binder_transaction *t, struct binder_node *node,
194 		 struct binder_ref_data *rdata),
195 	TP_ARGS(t, node, rdata),
196 
197 	TP_STRUCT__entry(
198 		__field(int, debug_id)
199 		__field(int, node_debug_id)
200 		__field(binder_uintptr_t, node_ptr)
201 		__field(int, ref_debug_id)
202 		__field(uint32_t, ref_desc)
203 	),
204 	TP_fast_assign(
205 		__entry->debug_id = t->debug_id;
206 		__entry->node_debug_id = node->debug_id;
207 		__entry->node_ptr = node->ptr;
208 		__entry->ref_debug_id = rdata->debug_id;
209 		__entry->ref_desc = rdata->desc;
210 	),
211 	TP_printk("transaction=%d node=%d src_ptr=0x%016llx ==> dest_ref=%d dest_desc=%d",
212 		  __entry->debug_id, __entry->node_debug_id,
213 		  (u64)__entry->node_ptr,
214 		  __entry->ref_debug_id, __entry->ref_desc)
215 );
216 
217 TRACE_EVENT(binder_transaction_ref_to_node,
218 	TP_PROTO(struct binder_transaction *t, struct binder_node *node,
219 		 struct binder_ref_data *rdata),
220 	TP_ARGS(t, node, rdata),
221 
222 	TP_STRUCT__entry(
223 		__field(int, debug_id)
224 		__field(int, ref_debug_id)
225 		__field(uint32_t, ref_desc)
226 		__field(int, node_debug_id)
227 		__field(binder_uintptr_t, node_ptr)
228 	),
229 	TP_fast_assign(
230 		__entry->debug_id = t->debug_id;
231 		__entry->ref_debug_id = rdata->debug_id;
232 		__entry->ref_desc = rdata->desc;
233 		__entry->node_debug_id = node->debug_id;
234 		__entry->node_ptr = node->ptr;
235 	),
236 	TP_printk("transaction=%d node=%d src_ref=%d src_desc=%d ==> dest_ptr=0x%016llx",
237 		  __entry->debug_id, __entry->node_debug_id,
238 		  __entry->ref_debug_id, __entry->ref_desc,
239 		  (u64)__entry->node_ptr)
240 );
241 
242 TRACE_EVENT(binder_transaction_ref_to_ref,
243 	TP_PROTO(struct binder_transaction *t, struct binder_node *node,
244 		 struct binder_ref_data *src_ref,
245 		 struct binder_ref_data *dest_ref),
246 	TP_ARGS(t, node, src_ref, dest_ref),
247 
248 	TP_STRUCT__entry(
249 		__field(int, debug_id)
250 		__field(int, node_debug_id)
251 		__field(int, src_ref_debug_id)
252 		__field(uint32_t, src_ref_desc)
253 		__field(int, dest_ref_debug_id)
254 		__field(uint32_t, dest_ref_desc)
255 	),
256 	TP_fast_assign(
257 		__entry->debug_id = t->debug_id;
258 		__entry->node_debug_id = node->debug_id;
259 		__entry->src_ref_debug_id = src_ref->debug_id;
260 		__entry->src_ref_desc = src_ref->desc;
261 		__entry->dest_ref_debug_id = dest_ref->debug_id;
262 		__entry->dest_ref_desc = dest_ref->desc;
263 	),
264 	TP_printk("transaction=%d node=%d src_ref=%d src_desc=%d ==> dest_ref=%d dest_desc=%d",
265 		  __entry->debug_id, __entry->node_debug_id,
266 		  __entry->src_ref_debug_id, __entry->src_ref_desc,
267 		  __entry->dest_ref_debug_id, __entry->dest_ref_desc)
268 );
269 
270 TRACE_EVENT(binder_transaction_fd_send,
271 	TP_PROTO(struct binder_transaction *t, int fd, size_t offset),
272 	TP_ARGS(t, fd, offset),
273 
274 	TP_STRUCT__entry(
275 		__field(int, debug_id)
276 		__field(int, fd)
277 		__field(size_t, offset)
278 	),
279 	TP_fast_assign(
280 		__entry->debug_id = t->debug_id;
281 		__entry->fd = fd;
282 		__entry->offset = offset;
283 	),
284 	TP_printk("transaction=%d src_fd=%d offset=%zu",
285 		  __entry->debug_id, __entry->fd, __entry->offset)
286 );
287 
288 TRACE_EVENT(binder_transaction_fd_recv,
289 	TP_PROTO(struct binder_transaction *t, int fd, size_t offset),
290 	TP_ARGS(t, fd, offset),
291 
292 	TP_STRUCT__entry(
293 		__field(int, debug_id)
294 		__field(int, fd)
295 		__field(size_t, offset)
296 	),
297 	TP_fast_assign(
298 		__entry->debug_id = t->debug_id;
299 		__entry->fd = fd;
300 		__entry->offset = offset;
301 	),
302 	TP_printk("transaction=%d dest_fd=%d offset=%zu",
303 		  __entry->debug_id, __entry->fd, __entry->offset)
304 );
305 
306 DECLARE_EVENT_CLASS(binder_buffer_class,
307 	TP_PROTO(struct binder_buffer *buf),
308 	TP_ARGS(buf),
309 	TP_STRUCT__entry(
310 		__field(int, debug_id)
311 		__field(size_t, data_size)
312 		__field(size_t, offsets_size)
313 		__field(size_t, extra_buffers_size)
314 	),
315 	TP_fast_assign(
316 		__entry->debug_id = buf->debug_id;
317 		__entry->data_size = buf->data_size;
318 		__entry->offsets_size = buf->offsets_size;
319 		__entry->extra_buffers_size = buf->extra_buffers_size;
320 	),
321 	TP_printk("transaction=%d data_size=%zd offsets_size=%zd extra_buffers_size=%zd",
322 		  __entry->debug_id, __entry->data_size, __entry->offsets_size,
323 		  __entry->extra_buffers_size)
324 );
325 
326 DEFINE_EVENT(binder_buffer_class, binder_transaction_alloc_buf,
327 	TP_PROTO(struct binder_buffer *buffer),
328 	TP_ARGS(buffer));
329 
330 DEFINE_EVENT(binder_buffer_class, binder_transaction_buffer_release,
331 	TP_PROTO(struct binder_buffer *buffer),
332 	TP_ARGS(buffer));
333 
334 DEFINE_EVENT(binder_buffer_class, binder_transaction_failed_buffer_release,
335 	TP_PROTO(struct binder_buffer *buffer),
336 	TP_ARGS(buffer));
337 
338 DEFINE_EVENT(binder_buffer_class, binder_transaction_update_buffer_release,
339 	     TP_PROTO(struct binder_buffer *buffer),
340 	     TP_ARGS(buffer));
341 
342 TRACE_EVENT(binder_update_page_range,
343 	TP_PROTO(struct binder_alloc *alloc, bool allocate,
344 		 unsigned long start, unsigned long end),
345 	TP_ARGS(alloc, allocate, start, end),
346 	TP_STRUCT__entry(
347 		__field(int, proc)
348 		__field(bool, allocate)
349 		__field(size_t, offset)
350 		__field(size_t, size)
351 	),
352 	TP_fast_assign(
353 		__entry->proc = alloc->pid;
354 		__entry->allocate = allocate;
355 		__entry->offset = start - alloc->buffer;
356 		__entry->size = end - start;
357 	),
358 	TP_printk("proc=%d allocate=%d offset=%zu size=%zu",
359 		  __entry->proc, __entry->allocate,
360 		  __entry->offset, __entry->size)
361 );
362 
363 DECLARE_EVENT_CLASS(binder_lru_page_class,
364 	TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
365 	TP_ARGS(alloc, page_index),
366 	TP_STRUCT__entry(
367 		__field(int, proc)
368 		__field(size_t, page_index)
369 	),
370 	TP_fast_assign(
371 		__entry->proc = alloc->pid;
372 		__entry->page_index = page_index;
373 	),
374 	TP_printk("proc=%d page_index=%zu",
375 		  __entry->proc, __entry->page_index)
376 );
377 
378 DEFINE_EVENT(binder_lru_page_class, binder_alloc_lru_start,
379 	TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
380 	TP_ARGS(alloc, page_index));
381 
382 DEFINE_EVENT(binder_lru_page_class, binder_alloc_lru_end,
383 	TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
384 	TP_ARGS(alloc, page_index));
385 
386 DEFINE_EVENT(binder_lru_page_class, binder_free_lru_start,
387 	TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
388 	TP_ARGS(alloc, page_index));
389 
390 DEFINE_EVENT(binder_lru_page_class, binder_free_lru_end,
391 	TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
392 	TP_ARGS(alloc, page_index));
393 
394 DEFINE_EVENT(binder_lru_page_class, binder_alloc_page_start,
395 	TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
396 	TP_ARGS(alloc, page_index));
397 
398 DEFINE_EVENT(binder_lru_page_class, binder_alloc_page_end,
399 	TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
400 	TP_ARGS(alloc, page_index));
401 
402 DEFINE_EVENT(binder_lru_page_class, binder_unmap_user_start,
403 	TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
404 	TP_ARGS(alloc, page_index));
405 
406 DEFINE_EVENT(binder_lru_page_class, binder_unmap_user_end,
407 	TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
408 	TP_ARGS(alloc, page_index));
409 
410 DEFINE_EVENT(binder_lru_page_class, binder_unmap_kernel_start,
411 	TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
412 	TP_ARGS(alloc, page_index));
413 
414 DEFINE_EVENT(binder_lru_page_class, binder_unmap_kernel_end,
415 	TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
416 	TP_ARGS(alloc, page_index));
417 
418 TRACE_EVENT(binder_command,
419 	TP_PROTO(uint32_t cmd),
420 	TP_ARGS(cmd),
421 	TP_STRUCT__entry(
422 		__field(uint32_t, cmd)
423 	),
424 	TP_fast_assign(
425 		__entry->cmd = cmd;
426 	),
427 	TP_printk("cmd=0x%x %s",
428 		  __entry->cmd,
429 		  _IOC_NR(__entry->cmd) < ARRAY_SIZE(binder_command_strings) ?
430 			  binder_command_strings[_IOC_NR(__entry->cmd)] :
431 			  "unknown")
432 );
433 
434 TRACE_EVENT(binder_return,
435 	TP_PROTO(uint32_t cmd),
436 	TP_ARGS(cmd),
437 	TP_STRUCT__entry(
438 		__field(uint32_t, cmd)
439 	),
440 	TP_fast_assign(
441 		__entry->cmd = cmd;
442 	),
443 	TP_printk("cmd=0x%x %s",
444 		  __entry->cmd,
445 		  _IOC_NR(__entry->cmd) < ARRAY_SIZE(binder_return_strings) ?
446 			  binder_return_strings[_IOC_NR(__entry->cmd)] :
447 			  "unknown")
448 );
449 
450 TRACE_EVENT(binder_netlink_report,
451 	TP_PROTO(const char *context,
452 		 struct binder_transaction *t,
453 		 u32 data_size,
454 		 u32 error,
455 		 int is_reply),
456 	TP_ARGS(context, t, data_size, error, is_reply),
457 	TP_STRUCT__entry(
458 		__field(const char *, context)
459 		__field(u32, error)
460 		__field(int, from_pid)
461 		__field(int, from_tid)
462 		__field(int, to_pid)
463 		__field(int, to_tid)
464 		__field(bool, is_reply)
465 		__field(unsigned int, flags)
466 		__field(unsigned int, code)
467 		__field(size_t, data_size)
468 	),
469 	TP_fast_assign(
470 		__entry->context = context;
471 		__entry->error = error;
472 		__entry->from_pid = t->from_pid;
473 		__entry->from_tid = t->from_tid;
474 		__entry->to_pid = t->to_proc ? t->to_proc->pid : 0;
475 		__entry->to_tid = t->to_thread ? t->to_thread->pid : 0;
476 		__entry->is_reply = is_reply;
477 		__entry->flags = t->flags;
478 		__entry->code = t->code;
479 		__entry->data_size = data_size;
480 	),
481 	TP_printk("from %d:%d to %d:%d context=%s error=%d is_reply=%d flags=0x%x code=0x%x size=%zu",
482 		  __entry->from_pid, __entry->from_tid,
483 		  __entry->to_pid, __entry->to_tid,
484 		  __entry->context, __entry->error, __entry->is_reply,
485 		  __entry->flags, __entry->code, __entry->data_size)
486 );
487 
488 #endif /* _BINDER_TRACE_H */
489 
490 #undef TRACE_INCLUDE_PATH
491 #undef TRACE_INCLUDE_FILE
492 #define TRACE_INCLUDE_PATH .
493 #define TRACE_INCLUDE_FILE binder_trace
494 #include <trace/define_trace.h>
495