Back to home page

OSCL-LXR

 
 

    


0001 " Enable folding for ftrace function_graph traces.
0002 "
0003 " To use, :source this file while viewing a function_graph trace, or use vim's
0004 " -S option to load from the command-line together with a trace.  You can then
0005 " use the usual vim fold commands, such as "za", to open and close nested
0006 " functions.  While closed, a fold will show the total time taken for a call,
0007 " as would normally appear on the line with the closing brace.  Folded
0008 " functions will not include finish_task_switch(), so folding should remain
0009 " relatively sane even through a context switch.
0010 "
0011 " Note that this will almost certainly only work well with a
0012 " single-CPU trace (e.g. trace-cmd report --cpu 1).
0013 
0014 function! FunctionGraphFoldExpr(lnum)
0015   let line = getline(a:lnum)
0016   if line[-1:] == '{'
0017     if line =~ 'finish_task_switch() {$'
0018       return '>1'
0019     endif
0020     return 'a1'
0021   elseif line[-1:] == '}'
0022     return 's1'
0023   else
0024     return '='
0025   endif
0026 endfunction
0027 
0028 function! FunctionGraphFoldText()
0029   let s = split(getline(v:foldstart), '|', 1)
0030   if getline(v:foldend+1) =~ 'finish_task_switch() {$'
0031     let s[2] = ' task switch  '
0032   else
0033     let e = split(getline(v:foldend), '|', 1)
0034     let s[2] = e[2]
0035   endif
0036   return join(s, '|')
0037 endfunction
0038 
0039 setlocal foldexpr=FunctionGraphFoldExpr(v:lnum)
0040 setlocal foldtext=FunctionGraphFoldText()
0041 setlocal foldcolumn=12
0042 setlocal foldmethod=expr