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