(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:tracing)
          op: Equal
          rhs: {(/sys/kernel/debug/tracing)}
        )
      ]
    )
    (command.ShAssignment
      pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:flock) op:Equal rhs:{(/var/tmp/.ftrace-lock)})]
    )
    (command.CommandList
      children: [
        (command.Sentence
          child: 
            (command.ShAssignment
              pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:opt_duration) op:Equal rhs:{(0)})]
            )
          terminator: <Op_Semi ';'>
        )
        (command.Sentence
          child: 
            (command.ShAssignment
              pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:duration) op:Equal rhs:(word.Empty))]
            )
          terminator: <Op_Semi ';'>
        )
        (command.Sentence
          child: 
            (command.ShAssignment
              pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:opt_pid) op:Equal rhs:{(0)})]
            )
          terminator: <Op_Semi ';'>
        )
        (command.Sentence
          child: 
            (command.ShAssignment
              pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:pid) op:Equal rhs:(word.Empty))]
            )
          terminator: <Op_Semi ';'>
        )
        (command.Sentence
          child: 
            (command.ShAssignment
              pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:opt_tid) op:Equal rhs:{(0)})]
            )
          terminator: <Op_Semi ';'>
        )
        (command.Sentence
          child: 
            (command.ShAssignment
              pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:tid) op:Equal rhs:(word.Empty))]
            )
          terminator: <Op_Semi ';'>
        )
        (command.ShAssignment
          pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:pidtext) op:Equal rhs:(word.Empty))]
        )
      ]
    )
    (command.ShAssignment
      pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:opt_headers) op:Equal rhs:{(0)})]
    )
    (C {(trap)} {(SQ <':'>)} {(INT)} {(QUIT)} {(TERM)} {(PIPE)} {(HUP)})
    (command.ShFunction
      name: usage
      body: 
        (command.BraceGroup
          children: [
            (command.Simple
              words: [{(cat)}]
              redirects: [
                (redir.HereDoc
                  op: <Redir_DLessDash '<<-'>
                  fd: 16777215
                  here_begin: {(END)}
                  here_end_span_id: 269
                  stdin_parts: [
                    ('USAGE: functrace [-hH] [-p PID] [-L TID] [-d secs] funcstring\n')
                    ('                 -d seconds      # trace duration, and use buffers\n')
                    ('                 -h              # this usage message\n')
                    ('                 -H              # include column headers\n')
                    ('                 -p PID          # trace when this pid is on-CPU\n')
                    ('                 -L TID          # trace when this thread is on-CPU\n')
                    ('  eg,\n')
                    ('       functrace do_nanosleep    # trace the do_nanosleep() function\n')
                    ("       functrace '*sleep'        # trace functions ending in ")
                    (Right_DoubleQuote '"')
                    (sleep)
                    (Right_DoubleQuote '"')
                    ('\n')
                    ("       functrace -p 198 'vfs*'   # trace ")
                    (Right_DoubleQuote '"')
                    ('vfs*')
                    (Right_DoubleQuote '"')
                    (' funcs for PID 198\n')
                    ("       functrace 'tcp*' > out    # trace all ")
                    (Right_DoubleQuote '"')
                    ('tcp*')
                    (Right_DoubleQuote '"')
                    (' funcs to out file\n')
                    ("       functrace -d 1 'tcp*' > out  # trace 1 sec, then write out file\n")
                    ('\n')
                    ('See the man page and example file for more info.\n')
                  ]
                )
                (redir.Redir op:<Redir_GreatAnd '>&'> fd:16777215 arg_word:{(2)})
              ]
            )
            (command.ControlFlow token:<ControlFlow_Exit exit>)
          ]
        )
    )
    (command.ShFunction
      name: warn
      body: 
        (command.BraceGroup
          children: [
            (command.If
              arms: [
                (if_arm
                  cond: [
                    (command.Sentence
                      child: 
                        (command.Pipeline
                          children: [(C {(eval)} {(DQ ($ VSub_At '$@'))})]
                          negated: T
                        )
                      terminator: <Op_Semi ';'>
                    )
                  ]
                  action: [
                    (command.Simple
                      words: [
                        {(echo)}
                        {
                          (DQ ('WARNING: command failed ') 
                            (word_part.EscapedLiteral
                              token: <Lit_EscapedChar '\\"'>
                            ) ($ VSub_At '$@') (word_part.EscapedLiteral token:<Lit_EscapedChar '\\"'>)
                          )
                        }
                      ]
                      redirects: [(redir.Redir op:<Redir_GreatAnd '>&'> fd:16777215 arg_word:{(2)})]
                    )
                  ]
                )
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: end
      body: 
        (command.BraceGroup
          children: [
            (command.Simple
              words: [{(echo)}]
              redirects: [(redir.Redir op:<Redir_Great '2>'> fd:2 arg_word:{(/dev/null)})]
            )
            (command.Simple
              words: [{(echo)} {(DQ ('Ending tracing...'))}]
              redirects: [(redir.Redir op:<Redir_Great '2>'> fd:2 arg_word:{(/dev/null)})]
            )
            (C {(cd)} {($ VSub_DollarName '$tracing')})
            (C {(warn)} {(DQ ('echo nop > current_tracer'))})
            (command.AndOr
              ops: [Op_DAmp]
              children: [
                (command.DParen
                  child: 
                    (arith_expr.Binary
                      op_id: Arith_DPipe
                      left: (arith_expr.VarRef token:<Lit_ArithVarLike opt_pid>)
                      right: (arith_expr.VarRef token:<Lit_ArithVarLike opt_tid>)
                    )
                )
                (C {(warn)} {(DQ ('echo > set_ftrace_pid'))})
              ]
            )
            (C {(warn)} {(DQ ('echo > set_ftrace_filter'))})
            (C {(warn)} {(DQ ('echo > trace'))})
            (command.AndOr
              ops: [Op_DAmp]
              children: [
                (command.DParen
                  child: (arith_expr.VarRef token:<Lit_ArithVarLike wroteflock>)
                )
                (C {(warn)} {(DQ ('rm ') ($ VSub_DollarName '$flock'))})
              ]
            )
          ]
        )
    )
    (command.ShFunction
      name: die
      body: 
        (command.BraceGroup
          children: [
            (command.Simple
              words: [{(echo)} {(DQ ($ VSub_At '$@'))}]
              redirects: [(redir.Redir op:<Redir_GreatAnd '>&'> fd:16777215 arg_word:{(2)})]
            )
            (command.ControlFlow token:<ControlFlow_Exit exit> arg_word:{(1)})
          ]
        )
    )
    (command.ShFunction
      name: edie
      body: 
        (command.BraceGroup
          children: [
            (command.Simple
              words: [{(echo)} {(DQ ($ VSub_At '$@'))}]
              redirects: [(redir.Redir op:<Redir_GreatAnd '>&'> fd:16777215 arg_word:{(2)})]
            )
            (command.Simple
              words: [{(exec)}]
              redirects: [
                (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(/dev/null)})
                (redir.Redir op:<Redir_GreatAnd '2>&'> fd:2 arg_word:{(1)})
              ]
            )
            (C {(end)})
            (command.ControlFlow token:<ControlFlow_Exit exit> arg_word:{(1)})
          ]
        )
    )
    (command.WhileUntil
      keyword: <KW_While while>
      cond: [(C {(getopts)} {(d) (Lit_Other ':') (hHp) (Lit_Other ':') (L) (Lit_Other ':')} {(opt)})]
      body: 
        (command.DoGroup
          children: [
            (command.Case
              to_match: {($ VSub_DollarName '$opt')}
              arms: [
                (case_arm
                  pat_list: [{(d)}]
                  action: [
                    (command.Sentence
                      child: 
                        (command.ShAssignment
                          pairs: [
                            (assign_pair
                              lhs: (sh_lhs_expr.Name name:opt_duration)
                              op: Equal
                              rhs: {(1)}
                            )
                          ]
                        )
                      terminator: <Op_Semi ';'>
                    )
                    (command.ShAssignment
                      pairs: [
                        (assign_pair
                          lhs: (sh_lhs_expr.Name name:duration)
                          op: Equal
                          rhs: {($ VSub_DollarName '$OPTARG')}
                        )
                      ]
                    )
                  ]
                )
                (case_arm
                  pat_list: [{(p)}]
                  action: [
                    (command.Sentence
                      child: 
                        (command.ShAssignment
                          pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:opt_pid) op:Equal rhs:{(1)})]
                        )
                      terminator: <Op_Semi ';'>
                    )
                    (command.ShAssignment
                      pairs: [
                        (assign_pair
                          lhs: (sh_lhs_expr.Name name:pid)
                          op: Equal
                          rhs: {($ VSub_DollarName '$OPTARG')}
                        )
                      ]
                    )
                  ]
                )
                (case_arm
                  pat_list: [{(L)}]
                  action: [
                    (command.Sentence
                      child: 
                        (command.ShAssignment
                          pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:opt_tid) op:Equal rhs:{(1)})]
                        )
                      terminator: <Op_Semi ';'>
                    )
                    (command.ShAssignment
                      pairs: [
                        (assign_pair
                          lhs: (sh_lhs_expr.Name name:tid)
                          op: Equal
                          rhs: {($ VSub_DollarName '$OPTARG')}
                        )
                      ]
                    )
                  ]
                )
                (case_arm
                  pat_list: [{(H)}]
                  action: [
                    (command.Sentence
                      child: 
                        (command.ShAssignment
                          pairs: [
                            (assign_pair
                              lhs: (sh_lhs_expr.Name name:opt_headers)
                              op: Equal
                              rhs: {(1)}
                            )
                          ]
                        )
                      terminator: <Op_Semi ';'>
                    )
                  ]
                )
                (case_arm pat_list:[{(h)} {(Lit_QMark '?')}] action:[(C {(usage)})])
              ]
            )
          ]
        )
    )
    (C {(shift)} 
      {
        (word_part.ArithSub
          anode: 
            (arith_expr.Binary
              op_id: Arith_Minus
              left: (arith_expr.ArithWord w:{($ VSub_DollarName '$OPTIND')})
              right: (arith_expr.ArithWord w:{(Lit_Digits 1)})
            )
        )
      }
    )
    (command.AndOr
      ops: [Op_DAmp]
      children: [
        (command.DParen
          child: 
            (arith_expr.Binary
              op_id: Arith_DEqual
              left: (arith_expr.ArithWord w:{($ VSub_Pound '$#')})
              right: (arith_expr.ArithWord w:{(Lit_Digits 0)})
            )
        )
        (C {(usage)})
      ]
    )
    (command.AndOr
      ops: [Op_DAmp]
      children: [
        (command.DParen
          child: 
            (arith_expr.Binary
              op_id: Arith_DAmp
              left: (arith_expr.VarRef token:<Lit_ArithVarLike opt_pid>)
              right: (arith_expr.VarRef token:<Lit_ArithVarLike opt_tid>)
            )
        )
        (C {(edie)} {(DQ ('ERROR: You can use -p or -L but not both.'))})
      ]
    )
    (command.ShAssignment
      pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:funcs) op:Equal rhs:{(DQ ($ VSub_Number '$1'))})]
    )
    (command.AndOr
      ops: [Op_DAmp]
      children: [
        (command.DParen child:(arith_expr.VarRef token:<Lit_ArithVarLike opt_pid>))
        (command.ShAssignment
          pairs: [
            (assign_pair
              lhs: (sh_lhs_expr.Name name:pidtext)
              op: Equal
              rhs: {(DQ (' for PID ') ($ VSub_DollarName '$pid'))}
            )
          ]
        )
      ]
    )
    (command.AndOr
      ops: [Op_DAmp]
      children: [
        (command.DParen child:(arith_expr.VarRef token:<Lit_ArithVarLike opt_tid>))
        (command.ShAssignment
          pairs: [
            (assign_pair
              lhs: (sh_lhs_expr.Name name:pidtext)
              op: Equal
              rhs: {(DQ (' for TID ') ($ VSub_DollarName '$pid'))}
            )
          ]
        )
      ]
    )
    (command.If
      arms: [
        (if_arm
          cond: [
            (command.Sentence
              child: (command.DParen child:(arith_expr.VarRef token:<Lit_ArithVarLike opt_duration>))
              terminator: <Op_Semi ';'>
            )
          ]
          action: [
            (C {(echo)} 
              {
                (DQ ('Tracing ') (word_part.EscapedLiteral token:<Lit_EscapedChar '\\"'>) 
                  ($ VSub_DollarName '$funcs') (word_part.EscapedLiteral token:<Lit_EscapedChar '\\"'>) ($ VSub_DollarName '$pidtext') (' for ') 
                  ($ VSub_DollarName '$duration') (' seconds...')
                )
              }
            )
          ]
        )
      ]
      else_action: [
        (C {(echo)} 
          {
            (DQ ('Tracing ') (word_part.EscapedLiteral token:<Lit_EscapedChar '\\"'>) 
              ($ VSub_DollarName '$funcs') (word_part.EscapedLiteral token:<Lit_EscapedChar '\\"'>) ($ VSub_DollarName '$pidtext') 
              ('... Ctrl-C to end.')
            )
          }
        )
      ]
    )
    (command.AndOr
      ops: [Op_DPipe]
      children: [
        (C {(cd)} {($ VSub_DollarName '$tracing')})
        (C {(die)} 
          {
            (DQ ('ERROR: accessing tracing. Root user? Kernel has FTRACE?\n') 
              ('    debugfs mounted? (mount -t debugfs debugfs /sys/kernel/debug)')
            )
          }
        )
      ]
    )
    (command.AndOr
      ops: [Op_DAmp]
      children: [
        (command.DBracket
          expr: (bool_expr.Unary op_id:BoolUnary_e child:{($ VSub_DollarName '$flock')})
        )
        (C {(die)} 
          {
            (DQ ('ERROR: ftrace may be in use by PID ') 
              (command_sub
                left_token: <Left_DollarParen '$('>
                command_list: 
                  (command.CommandList
                    children: [(C {(cat)} {($ VSub_DollarName '$flock')})]
                  )
              ) (' ') ($ VSub_DollarName '$flock')
            )
          }
        )
      ]
    )
    (command.AndOr
      ops: [Op_DPipe]
      children: [
        (command.Simple
          words: [{(echo)} {($ VSub_Dollar '$$')}]
          redirects: [
            (redir.Redir
              op: <Redir_Great '>'>
              fd: 16777215
              arg_word: {($ VSub_DollarName '$flock')}
            )
          ]
        )
        (C {(die)} {(DQ ('ERROR: unable to write ') ($ VSub_DollarName '$flock') (.))})
      ]
    )
    (command.ShAssignment
      pairs: [(assign_pair lhs:(sh_lhs_expr.Name name:wroteflock) op:Equal rhs:{(1)})]
    )
    (C {(sysctl)} {(-q)} {(kernel.ftrace_enabled) (Lit_Equals '=') (1)})
    (command.Simple
      words: [{(read)} {(mode)}]
      redirects: [(redir.Redir op:<Redir_Less '<'> fd:16777215 arg_word:{(current_tracer)})]
    )
    (command.AndOr
      ops: [Op_DAmp]
      children: [
        (command.DBracket
          expr: 
            (bool_expr.Binary
              op_id: BoolBinary_GlobNEqual
              left: {(DQ ($ VSub_DollarName '$mode'))}
              right: {(DQ (nop))}
            )
        )
        (C {(edie)} {(DQ ('ERROR: ftrace active (current_tracer=') ($ VSub_DollarName '$mode') (')'))})
      ]
    )
    (command.If
      arms: [
        (if_arm
          cond: [
            (command.Sentence
              child: (command.DParen child:(arith_expr.VarRef token:<Lit_ArithVarLike opt_pid>))
              terminator: <Op_Semi ';'>
            )
          ]
          action: [
            (command.Simple
              words: [{(echo)}]
              redirects: [(redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(set_ftrace_pid)})]
            )
            (command.ForEach
              iter_name: tid
              iter_words: [{(/proc/) ($ VSub_DollarName '$pid') (/task/) (Lit_Star '*')}]
              do_arg_iter: F
              body: 
                (command.DoGroup
                  children: [
                    (command.If
                      arms: [
                        (if_arm
                          cond: [
                            (command.Sentence
                              child: 
                                (command.Pipeline
                                  children: [
                                    (command.Simple
                                      words: [
                                        {(echo)}
                                        {
                                          (braced_var_sub
                                            token: <VSub_Name tid>
                                            suffix_op: 
                                              (suffix_op.Unary
                                                op_id: VOp1_DPound
                                                arg_word: {('*') (Lit_Slash /)}
                                              )
                                          )
                                        }
                                      ]
                                      redirects: [
                                        (redir.Redir
                                          op: <Redir_DGreat '>>'>
                                          fd: 16777215
                                          arg_word: {(set_ftrace_pid)}
                                        )
                                      ]
                                    )
                                  ]
                                  negated: T
                                )
                              terminator: <Op_Semi ';'>
                            )
                          ]
                          action: [
                            (C {(edie)} 
                              {
                                (DQ ('ERROR: setting -p ') ($ VSub_DollarName '$pid') 
                                  (' (PID exist?). Exiting.')
                                )
                              }
                            )
                          ]
                        )
                      ]
                    )
                  ]
                )
            )
          ]
        )
      ]
    )
    (command.If
      arms: [
        (if_arm
          cond: [
            (command.Sentence
              child: (command.DParen child:(arith_expr.VarRef token:<Lit_ArithVarLike opt_tid>))
              terminator: <Op_Semi ';'>
            )
          ]
          action: [
            (command.If
              arms: [
                (if_arm
                  cond: [
                    (command.Sentence
                      child: 
                        (command.Pipeline
                          children: [
                            (command.Simple
                              words: [{(echo)} {($ VSub_DollarName '$tid')}]
                              redirects: [
                                (redir.Redir
                                  op: <Redir_Great '>'>
                                  fd: 16777215
                                  arg_word: {(set_ftrace_pid)}
                                )
                              ]
                            )
                          ]
                          negated: T
                        )
                      terminator: <Op_Semi ';'>
                    )
                  ]
                  action: [
                    (C {(edie)} 
                      {
                        (DQ ('ERROR: setting -L ') ($ VSub_DollarName '$tid') 
                          (' (TID exist?). Exiting.')
                        )
                      }
                    )
                  ]
                )
              ]
            )
          ]
        )
      ]
    )
    (command.If
      arms: [
        (if_arm
          cond: [
            (command.Sentence
              child: 
                (command.Pipeline
                  children: [
                    (command.Simple
                      words: [{(echo)} {(DQ ($ VSub_DollarName '$funcs'))}]
                      redirects: [
                        (redir.Redir
                          op: <Redir_Great '>'>
                          fd: 16777215
                          arg_word: {(set_ftrace_filter)}
                        )
                      ]
                    )
                  ]
                  negated: T
                )
              terminator: <Op_Semi ';'>
            )
          ]
          action: [
            (C {(edie)} 
              {
                (DQ ('ERROR: enabling ') (word_part.EscapedLiteral token:<Lit_EscapedChar '\\"'>) 
                  ($ VSub_DollarName '$funcs') (word_part.EscapedLiteral token:<Lit_EscapedChar '\\"'>) ('. Exiting.')
                )
              }
            )
          ]
        )
      ]
    )
    (command.If
      arms: [
        (if_arm
          cond: [
            (command.Sentence
              child: 
                (command.Pipeline
                  children: [
                    (command.Simple
                      words: [{(echo)} {(KW_Function function)}]
                      redirects: [
                        (redir.Redir
                          op: <Redir_Great '>'>
                          fd: 16777215
                          arg_word: {(current_tracer)}
                        )
                      ]
                    )
                  ]
                  negated: T
                )
              terminator: <Op_Semi ';'>
            )
          ]
          action: [
            (C {(edie)} 
              {
                (DQ ('ERROR: setting current_tracer to ') 
                  (word_part.EscapedLiteral token:<Lit_EscapedChar '\\"'>) (function) (word_part.EscapedLiteral token:<Lit_EscapedChar '\\"'>) ('. Exiting.')
                )
              }
            )
          ]
        )
      ]
    )
    (C {(warn)} {(DQ ('echo > trace'))})
    (command.If
      arms: [
        (if_arm
          cond: [
            (command.Sentence
              child: (command.DParen child:(arith_expr.VarRef token:<Lit_ArithVarLike opt_duration>))
              terminator: <Op_Semi ';'>
            )
          ]
          action: [
            (C {(sleep)} {($ VSub_DollarName '$duration')})
            (command.If
              arms: [
                (if_arm
                  cond: [
                    (command.Sentence
                      child: 
                        (command.DParen
                          child: (arith_expr.VarRef token:<Lit_ArithVarLike opt_headers>)
                        )
                      terminator: <Op_Semi ';'>
                    )
                  ]
                  action: [(C {(cat)} {(trace)})]
                )
              ]
              else_action: [(C {(grep)} {(-v)} {(SQ <'^#'>)} {(trace)})]
            )
          ]
        )
      ]
      else_action: [
        (command.AndOr
          ops: [Op_DAmp]
          children: [
            (command.DParen child:(arith_expr.VarRef token:<Lit_ArithVarLike opt_headers>))
            (C {(cat)} {(trace)})
          ]
        )
        (C {(cat)} {(trace_pipe)})
      ]
    )
    (C {(end)})
  ]
)