^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * call-path.h: Manipulate a tree data structure containing function call paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2014, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef __PERF_CALL_PATH_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define __PERF_CALL_PATH_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * struct call_path - node in list of calls leading to a function call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * @parent: call path to the parent function call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * @sym: symbol of function called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * @ip: only if sym is null, the ip of the function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * @db_id: id used for db-export
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * @in_kernel: whether function is a in the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * @rb_node: node in parent's tree of called functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * @children: tree of call paths of functions called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * In combination with the call_return structure, the call_path structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * defines a context-sensitve call-graph.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct call_path {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct call_path *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct symbol *sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u64 ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u64 db_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) bool in_kernel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct rb_node rb_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct rb_root children;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define CALL_PATH_BLOCK_SHIFT 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define CALL_PATH_BLOCK_SIZE (1 << CALL_PATH_BLOCK_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define CALL_PATH_BLOCK_MASK (CALL_PATH_BLOCK_SIZE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct call_path_block {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct call_path cp[CALL_PATH_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct list_head node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * struct call_path_root - root of all call paths.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * @call_path: root call path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @blocks: list of blocks to store call paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @next: next free space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @sz: number of spaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct call_path_root {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct call_path call_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct list_head blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) size_t next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) size_t sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct call_path_root *call_path_root__new(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) void call_path_root__free(struct call_path_root *cpr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct call_path *call_path__findnew(struct call_path_root *cpr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct call_path *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct symbol *sym, u64 ip, u64 ks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #endif