162306a36Sopenharmony_ci" Enable folding for ftrace function_graph traces. 262306a36Sopenharmony_ci" 362306a36Sopenharmony_ci" To use, :source this file while viewing a function_graph trace, or use vim's 462306a36Sopenharmony_ci" -S option to load from the command-line together with a trace. You can then 562306a36Sopenharmony_ci" use the usual vim fold commands, such as "za", to open and close nested 662306a36Sopenharmony_ci" functions. While closed, a fold will show the total time taken for a call, 762306a36Sopenharmony_ci" as would normally appear on the line with the closing brace. Folded 862306a36Sopenharmony_ci" functions will not include finish_task_switch(), so folding should remain 962306a36Sopenharmony_ci" relatively sane even through a context switch. 1062306a36Sopenharmony_ci" 1162306a36Sopenharmony_ci" Note that this will almost certainly only work well with a 1262306a36Sopenharmony_ci" single-CPU trace (e.g. trace-cmd report --cpu 1). 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_cifunction! FunctionGraphFoldExpr(lnum) 1562306a36Sopenharmony_ci let line = getline(a:lnum) 1662306a36Sopenharmony_ci if line[-1:] == '{' 1762306a36Sopenharmony_ci if line =~ 'finish_task_switch() {$' 1862306a36Sopenharmony_ci return '>1' 1962306a36Sopenharmony_ci endif 2062306a36Sopenharmony_ci return 'a1' 2162306a36Sopenharmony_ci elseif line[-1:] == '}' 2262306a36Sopenharmony_ci return 's1' 2362306a36Sopenharmony_ci else 2462306a36Sopenharmony_ci return '=' 2562306a36Sopenharmony_ci endif 2662306a36Sopenharmony_ciendfunction 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_cifunction! FunctionGraphFoldText() 2962306a36Sopenharmony_ci let s = split(getline(v:foldstart), '|', 1) 3062306a36Sopenharmony_ci if getline(v:foldend+1) =~ 'finish_task_switch() {$' 3162306a36Sopenharmony_ci let s[2] = ' task switch ' 3262306a36Sopenharmony_ci else 3362306a36Sopenharmony_ci let e = split(getline(v:foldend), '|', 1) 3462306a36Sopenharmony_ci let s[2] = e[2] 3562306a36Sopenharmony_ci endif 3662306a36Sopenharmony_ci return join(s, '|') 3762306a36Sopenharmony_ciendfunction 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_cisetlocal foldexpr=FunctionGraphFoldExpr(v:lnum) 4062306a36Sopenharmony_cisetlocal foldtext=FunctionGraphFoldText() 4162306a36Sopenharmony_cisetlocal foldcolumn=12 4262306a36Sopenharmony_cisetlocal foldmethod=expr 43