1*4882a593Smuzhiyun" Enable folding for ftrace function_graph traces. 2*4882a593Smuzhiyun" 3*4882a593Smuzhiyun" To use, :source this file while viewing a function_graph trace, or use vim's 4*4882a593Smuzhiyun" -S option to load from the command-line together with a trace. You can then 5*4882a593Smuzhiyun" use the usual vim fold commands, such as "za", to open and close nested 6*4882a593Smuzhiyun" functions. While closed, a fold will show the total time taken for a call, 7*4882a593Smuzhiyun" as would normally appear on the line with the closing brace. Folded 8*4882a593Smuzhiyun" functions will not include finish_task_switch(), so folding should remain 9*4882a593Smuzhiyun" relatively sane even through a context switch. 10*4882a593Smuzhiyun" 11*4882a593Smuzhiyun" Note that this will almost certainly only work well with a 12*4882a593Smuzhiyun" single-CPU trace (e.g. trace-cmd report --cpu 1). 13*4882a593Smuzhiyun 14*4882a593Smuzhiyunfunction! FunctionGraphFoldExpr(lnum) 15*4882a593Smuzhiyun let line = getline(a:lnum) 16*4882a593Smuzhiyun if line[-1:] == '{' 17*4882a593Smuzhiyun if line =~ 'finish_task_switch() {$' 18*4882a593Smuzhiyun return '>1' 19*4882a593Smuzhiyun endif 20*4882a593Smuzhiyun return 'a1' 21*4882a593Smuzhiyun elseif line[-1:] == '}' 22*4882a593Smuzhiyun return 's1' 23*4882a593Smuzhiyun else 24*4882a593Smuzhiyun return '=' 25*4882a593Smuzhiyun endif 26*4882a593Smuzhiyunendfunction 27*4882a593Smuzhiyun 28*4882a593Smuzhiyunfunction! FunctionGraphFoldText() 29*4882a593Smuzhiyun let s = split(getline(v:foldstart), '|', 1) 30*4882a593Smuzhiyun if getline(v:foldend+1) =~ 'finish_task_switch() {$' 31*4882a593Smuzhiyun let s[2] = ' task switch ' 32*4882a593Smuzhiyun else 33*4882a593Smuzhiyun let e = split(getline(v:foldend), '|', 1) 34*4882a593Smuzhiyun let s[2] = e[2] 35*4882a593Smuzhiyun endif 36*4882a593Smuzhiyun return join(s, '|') 37*4882a593Smuzhiyunendfunction 38*4882a593Smuzhiyun 39*4882a593Smuzhiyunsetlocal foldexpr=FunctionGraphFoldExpr(v:lnum) 40*4882a593Smuzhiyunsetlocal foldtext=FunctionGraphFoldText() 41*4882a593Smuzhiyunsetlocal foldcolumn=12 42*4882a593Smuzhiyunsetlocal foldmethod=expr 43