Skip to content

Commit

Permalink
tools: Introducing ppchcalls.py for hcall count/latency stats.
Browse files Browse the repository at this point in the history
Migrating perf based powerpc-hcalls.py to a more enhanced ebpf variant
inspired by existing bcc/tools/syscount.py.
Additional hcalls updated from Linux kernel source.

Signed-off-by: Harsh Prateek Bora ([email protected])
  • Loading branch information
Harsh Prateek Bora authored and chenhengqi committed Nov 2, 2022
1 parent 8c02729 commit 917b97b
Show file tree
Hide file tree
Showing 5 changed files with 774 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pair of .c and .py files, and some are directories of files.
- tools/[oomkill](tools/oomkill.py): Trace the out-of-memory (OOM) killer. [Examples](tools/oomkill_example.txt).
- tools/[opensnoop](tools/opensnoop.py): Trace open() syscalls. [Examples](tools/opensnoop_example.txt).
- tools/[pidpersec](tools/pidpersec.py): Count new processes (via fork). [Examples](tools/pidpersec_example.txt).
- tools/[ppchcalls](tools/ppchcalls.py): Summarize ppc hcall counts and latencies. [Examples](tools/ppchcalls_example.txt).
- tools/[profile](tools/profile.py): Profile CPU usage by sampling stack traces at a timed interval. [Examples](tools/profile_example.txt).
- tools/[readahead](tools/readahead.py): Show performance of read-ahead cache [Examples](tools/readahead_example.txt).
- tools/[reset-trace](tools/reset-trace.sh): Reset the state of tracing. Maintenance tool only. [Examples](tools/reset-trace_example.txt).
Expand Down
120 changes: 120 additions & 0 deletions man/man8/ppchcalls.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
.TH ppchcalls 8 "2022-10-19" "USER COMMANDS"
.SH NAME
ppchcalls \- Summarize ppc hcall counts and latencies.
.SH SYNOPSIS
.B ppchcalls [-h] [-p PID] [-t TID] [-i INTERVAL] [-d DURATION] [-T TOP] [-x] [-e ERRNO] [-L] [-m] [-P] [-l] [--hcall HCALL]
.SH DESCRIPTION
This tool traces hcall entry and exit raw tracepoints and summarizes either the
number of hcalls of each type, or the number of hcalls per process. It can
also collect min, max and average latency for each hcall or each process.

Since this uses BPF, only the root user can use this tool.
.SH REQUIREMENTS
CONFIG_BPF and bcc. Linux 4.17+ is required to attach a BPF program to the
raw_hcalls:hcall_{enter,exit} tracepoints, used by this tool.
.SH OPTIONS
.TP
\-h
Print usage message.
.TP
\-p PID
Trace only this process.
.TP
\-t TID
Trace only this thread.
.TP
\-i INTERVAL
Print the summary at the specified interval (in seconds).
.TP
\-d DURATION
Total duration of trace (in seconds).
.TP
\-T TOP
Print only this many entries. Default: 10.
.TP
\-x
Trace only failed hcalls (i.e., the return value from the hcall was < 0).
.TP
\-e ERRNO
Trace only hcalls that failed with that error (e.g. -e EPERM or -e 1).
.TP
\-m
Display times in milliseconds. Default: microseconds.
.TP
\-P
Summarize by process and not by hcall.
.TP
\-l
List the hcalls recognized by the tool (hard-coded list). Hcalls beyond this
list will still be displayed, as "[unknown: nnn]" where nnn is the hcall
number.
.TP
\--hcall HCALL
Trace this hcall only (use option -l to get all recognized hcalls).
.SH EXAMPLES
.TP
Summarize all hcalls by hcall:
#
.B ppchcalls
.TP
Summarize all hcalls by process:
#
.B ppchcalls \-P
.TP
Summarize only failed hcalls:
#
.B ppchcalls \-x
.TP
Summarize only hcalls that failed with EPERM:
#
.B ppchcalls \-e EPERM
.TP
Trace PID 181 only:
#
.B ppchcalls \-p 181
.TP
Summarize hcalls counts and latencies:
#
.B ppchcalls \-L
.SH FIELDS
.TP
PID
Process ID
.TP
COMM
Process name
.TP
HCALL
Hcall name, or "[unknown: nnn]" for hcalls that aren't recognized
.TP
COUNT
The number of events
.TP
MIN
The minimum elapsed time (in us or ms)
.TP
MAX
The maximum elapsed time (in us or ms)
.TP
AVG
The average elapsed time (in us or ms)
.SH OVERHEAD
For most applications, the overhead should be manageable if they perform 1000's
or even 10,000's of hcalls per second. For higher rates, the overhead may
become considerable.
.
.SH SOURCE
This is from bcc.
.IP
https://github.com/iovisor/bcc
.PP
Also look in the bcc distribution for a companion _examples.txt file containing
example usage, output, and commentary for this tool.
.SH OS
Linux
.SH STABILITY
Unstable - in development.
.SH AUTHOR
Harsh Prateek Bora
.SH SEE ALSO
syscount(8)
5 changes: 5 additions & 0 deletions tests/python/test_tools_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ def test_opensnoop(self):
def test_pidpersec(self):
self.run_with_int("pidpersec.py")

@skipUnless(kernel_version_ge(4,17), "requires kernel >= 4.17")
@mayFail("This fails on github actions environment, and needs to be fixed")
def test_syscount(self):
self.run_with_int("ppchcalls.py -i 1")

@skipUnless(kernel_version_ge(4,9), "requires kernel >= 4.9")
def test_profile(self):
self.run_with_duration("profile.py 1")
Expand Down
Loading

0 comments on commit 917b97b

Please sign in to comment.