This program summarize syscall counts and latencies, in flavor of
per-CPU, per-PID, or histogram.

There are major two categories of parameters:
1. one category of parameters control the sampling source, such as
-s[--syscall] and -p[--pid]
2. another category of parameters control the displaying format,
such as -S[--syscalls], -P[--pids] and -D[--dist]

These two categories of parameters are Orthogonal.


Example 1.

By default, the program will sample all syscalls of all processes.
Statistics of all processes on the same syscall is aggregated and
displayed in a per-syscall flavor.

In this case, "alisyscount" is the same as "alisyscount -S".

# alisyscount
Tracing syscall statistics... Hit Ctrl-C to end.
^C
     SysNR                        Syscall      Count TOTAL_usecs
        35                      nanosleep       246   23815620
         4                           stat       207        306
         0                           read        61         65
       321                            bpf        43        112
         3                          close        28         23
        14                 rt_sigprocmask        20          5
       232                     epoll_wait        20          5
       162                           sync        19    1901216
       228                  clock_gettime        18          5
        23                         select         9    4016487
         6                          lstat         9         16
         1                          write         8        136
         2                           open         8         19
        72                          fcntl         6          1
         5                          fstat         4          2
        16                          ioctl         3          3
       271                          ppoll         1     900954
        78                       getdents         1        355
        89                       readlink         1          4
       257                         openat         1          2
         9                           mmap         1          2
       100                          times         1          2
        13                   rt_sigaction         1          0


Example 2.

Make the output displayed in a per-process flavor with "-P" parameter.
In this case, all syscalls of all processe are sampled as usual, while
all statistics of the same process is aggregated, whatever syscall it
runs.

# alisyscount -P
Tracing syscall statistics... Hit Ctrl-C to end.
^C
       PID                         Thread      Count TOTAL_usecs
      3550                      AliYunDun       125    3103841
      3529                      AliYunDun        71    3101981
      3549                      AliYunDun        62    3103861
      3543                      AliYunDun        61    3001874
      3493                 aliyun-service        61    3001874
      3564                           sshd        48    3149751
      3824                alisyscount.py        46    3149398
      3548                      AliYunDun        40    3002530
      3544                      AliYunDun        32    2000233
      3530                      AliYunDun        31    3101971
      3556                      AliYunDun        31    3001000
      3542                      AliYunDun        30    3001918
      3531                      AliYunDun        30    3001871
      3423                AliYunDunUpdate        30    3001867
      3424                AliYunDunUpdate        30    3001853
      3475                   in:imjournal         5    1801873
      3551                      AliYunDun         3    1000111
      3422                AliYunDunUpdate         3          1
      3553                      AliYunDun         2    2000172
      3547                      AliYunDun         2    2000172
      3555                      AliYunDun         2    2000162


Example 3.

You can set "-P" and "-S" parameter at the same time, in which case, the
output is displayed in a per-syscall and per-process flavor.

# alisyscount -P -S
Tracing syscall statistics... Hit Ctrl-C to end.
^C
     SysNR                        Syscall        PID                         Thread      Count TOTAL_usecs
         4                           stat       3550                      AliYunDun       586        855
        35                      nanosleep       3549                      AliYunDun        40    2002500
         0                           read       3550                      AliYunDun        36         90
        35                      nanosleep       3548                      AliYunDun        26    1951607
       321                            bpf       3832                alisyscount.py        23         36
        35                      nanosleep       3550                      AliYunDun        22    1901390
        35                      nanosleep       3530


Example 4.

Sample specified process only with "-p", and "-P" is added implicitly
when "-p" is specified.

# alisyscount -p 3550
Tracing syscall statistics... Hit Ctrl-C to end.
^C
       PID                         Thread      Count TOTAL_usecs
      3550                      AliYunDun       121    3003773


Example 5.

When both "-p" and "-S" parameters are specified, the output is displayed
in per-syscall and per-process flavor.

# alisyscount -p 3550 -S
Tracing syscall statistics... Hit Ctrl-C to end.
^C
     SysNR                        Syscall        PID                         Thread      Count TOTAL_usecs
         0                           read       3550                      AliYunDun        42         16
        35                      nanosleep       3550                      AliYunDun        41    2052562


Example 6.

Sample specified syscall only with "-s", and "-S" is added
implicitly when "-s" is specified.

# alisyscount -s 3
Tracing syscall statistics... Hit Ctrl-C to end.
^C
     SysNR                        Syscall      Count TOTAL_usecs
         3                          close        36         15


Example 7.

Make the output displayed in a diagram when "-D" is specified.

# alisyscount -p 3550 -D
Tracing syscall statistics... Hit Ctrl-C to end.
^C

Thread =                     PID 3550 (AliYunDun)
     time_usecs          : count     distribution
         0 -> 1          : 33       |****************************************|
         2 -> 3          : 0        |                                        |
         4 -> 7          : 0        |                                        |
         8 -> 15         : 0        |                                        |
        16 -> 31         : 0        |                                        |
        32 -> 63         : 0        |                                        |
        64 -> 127        : 0        |                                        |
       128 -> 255        : 0        |                                        |
       256 -> 511        : 0        |                                        |
       512 -> 1023       : 0        |                                        |
      1024 -> 2047       : 0        |                                        |
      2048 -> 4095       : 0        |                                        |
      4096 -> 8191       : 0        |                                        |
      8192 -> 16383      : 0        |                                        |
     16384 -> 32767      : 0        |                                        |
     32768 -> 65535      : 32       |**************************************  |



USAGE message:

# alisyscount -h
usage: alisyscount.py [-h] [-T] [-N] [-S] [-P] [-D] [-s SYSCALL] [-p PID]
                      [interval] [outputs]

Summarize syscall counts and latencies.

positional arguments:
  interval              output interval, in seconds
  outputs               number of outputs

optional arguments:
  -h, --help            show this help message and exit
  -T, --timestamp       include timestamp on output
  -N, --nanoseconds     output in nanoseconds
  -S, --syscalls        show per-syscall statistics
  -P, --pids            show per-thread syscall statistics
  -D, --dist            show distributions as histograms
  -s SYSCALL, --syscall SYSCALL
                        show statistics of specific syscall only
  -p PID, --pid PID     show syscall statistics of specific PID only

examples:
    ./alisyscount            # sum syscall counts and latencies.
    ./alisyscount -S         # show per-syscall statistics
    ./alisyscount -P         # show per-thread syscall statistics
    ./alisyscount -D         # show syscall statistics as histograms
    ./alisyscount -s 0       # show syscall statistics of syscall 0 only
    ./alisyscount -p 25      # show syscall statistics of PID 25 only
    ./alisyscount 1 10       # print 1 second summaries, 10 times
    ./alisyscount -NT 1      # 1s summaries, nanoseconds, and timestamps
