• Andrew Birchall's avatar
    move ENOMEM comment; create --stack-storage-size arg; misc cleanup · 47d871f0
    Andrew Birchall authored
    Summary:
    * move ENOMEM comment from tools/offcputime.py to src/cc/export/helpers.h
    * create --stack-storage-size arg to allow the user to set the stack storage size
        * requires a positive_nonzero_int type checking function for argparse
    * clean up the rest of the args a bit
        * use parser.add_mutually_exclusive_group instead of manually handling the
          mutual exclusion
        * use positive_nonzero_int for duration arg
        * use positive_int for pid arg
    * only print a warning about increasing the storage size if at least one of the
      get_stackid errors was a -ENOMEM
    * remove the debug param (we can add this manually when testing)
    * fix a bug where all processes are traced when specifying pid of 0
    
    Test Plan:
    ```
    devbig680[bcc](no branch, rebasing abirchall_dev): ~/bcc_run_tool.sh offcputime --help
    [Running] /data/users/abirchall/bcc/tools/offcputime.py --help
    usage: offcputime.py [-h] [-u | -p PID] [-v] [-f]
                         [--stack-storage-size STACK_STORAGE_SIZE]
                         [duration]
    
    Summarize off-CPU time by kernel stack trace
    
    positional arguments:
      duration              duration of trace, in seconds
    
    optional arguments:
      -h, --help            show this help message and exit
      -u, --useronly        user threads only (no kernel threads)
      -p PID, --pid PID     trace this PID only
      -v, --verbose         show raw addresses
      -f, --folded          output folded format
      --stack-storage-size STACK_STORAGE_SIZE
                            the number of unique stack traces that can be stored
                            and displayed
    
    examples:
        ./offcputime             # trace off-CPU stack time until Ctrl-C
        ./offcputime 5           # trace for 5 seconds only
        ./offcputime -f 5        # 5 seconds, and output in folded format
        ./offcputime -u          # don't include kernel threads (user only)
        ./offcputime -p 185      # trace fo PID 185 only
    devbig680[bcc](no branch, rebasing abirchall_dev): ~/bcc_run_tool.sh offcputime -f 0
    [Running] /data/users/abirchall/bcc/tools/offcputime.py -f 0
    usage: offcputime.py [-h] [-u | -p PID] [-v] [-f]
                         [--stack-storage-size STACK_STORAGE_SIZE]
                         [duration]
    offcputime.py: error: argument duration: must be positive and nonzero
    devbig680[bcc](no branch, rebasing abirchall_dev): ~/bcc_run_tool.sh offcputime -f -1
    [Running] /data/users/abirchall/bcc/tools/offcputime.py -f -1
    usage: offcputime.py [-h] [-u | -p PID] [-v] [-f]
                         [--stack-storage-size STACK_STORAGE_SIZE]
                         [duration]
    offcputime.py: error: argument duration: must be positive and nonzero
    devbig680[bcc](no branch, rebasing abirchall_dev): ~/bcc_run_tool.sh offcputime --stack-storage-size 0 -f 1
    [Running] /data/users/abirchall/bcc/tools/offcputime.py --stack-storage-size 0 -f 1
    usage: offcputime.py [-h] [-u | -p PID] [-v] [-f]
                         [--stack-storage-size STACK_STORAGE_SIZE]
                         [duration]
    offcputime.py: error: argument --stack-storage-size: must be positive and nonzero
    devbig680[bcc](no branch, rebasing abirchall_dev): ~/bcc_run_tool.sh offcputime --stack-storage-size 1 -f 1
    [Running] /data/users/abirchall/bcc/tools/offcputime.py --stack-storage-size 1 -f 1
    swapper/27;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 7
    swapper/29;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 102
    swapper/25;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 113
    swapper/26;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 138
    swapper/28;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 164
    swapper/30;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 177
    swapper/24;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 980
    swapper/31;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 1556
    swapper/1;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2038
    swapper/3;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2190
    swapper/2;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2235
    swapper/15;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2260
    swapper/13;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2450
    swapper/6;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2646
    swapper/12;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2675
    swapper/11;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2769
    swapper/8;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 2885
    swapper/4;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 3134
    swapper/10;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 3416
    swapper/14;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 3702
    swapper/7;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 4343
    swapper/9;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 5397
    swapper/5;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 6836
    swapper/17;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 13792
    swapper/19;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 14488
    swapper/22;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 15298
    swapper/18;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 15735
    swapper/20;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 17333
    swapper/16;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 17645
    swapper/23;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 17681
    swapper/21;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule 18607
    WARNING: 92 stack traces could not be displayed. Consider increasing --stack-storage-size.
    47d871f0
offcputime.py 5.61 KB