process-stats/README.md

4.1 KiB

process-stats.sh

License: MIT License: Apache Stability: experimental

Collect and visualise resource usage statistics for a single Linux process.

This script is a wrapper around pidstat (from the sysstat package), NetHogs (which usually requires root access to capture network packages with libpcap) and RRDtool.

Other requirements: Bash, gawk, getopt from "util-linux".

example.svg

How to use

Usage: process-stats.sh --pid <process ID> [OTHER OPTIONS]
E.g.: process-stats.sh --pid 12345 --out bla # produces bla.rrd, bla.sh and bla.svg

  -p, --pid		the process ID of the target program (mandatory
			argument)
  -h, --help		this help message
  -v, --verbose		show raw data on stdout
  -o, --output		base filename for the generated .rrd, .sh and .svg files
			(defaults to "out")
  -r, --rows		maximum number of rows in the RRD file (defaults to
			100000 and, at one datapoint per second, it's also the
			maximum duration of recorded and visualised data)
  -g, --graph-generation-interval
			interval in seconds at which the SVG graph is being
			regenerated during data collection (default: 60, set it
			to 0 to disable)
      --height		graph height (in pixels, default: 800)
      --min-width	minimum graph width (default: 1000)

Real-life example

(Taken from here: https://github.com/status-im/nimbus/issues/262)

# in one terminal:
rm -rf ~/.cache/nimbus/db; time ./build/nimbus --prune:archive --port:30304 &>output3.log
# in another terminal, logged in as root, knowing that there is only one "nimbus" process running,
# collecting a maximum of 100000 rows (the default), once per second, showing the raw data on stdout:
./process-stats.sh -v -p $(pidof nimbus) -o nimbus3

The data collection ends when the target process exits or when Ctrl+C is pressed. After this, you'll find three new files in your current directory:

  • "nimbus3.rrd" - collected data
  • "nimbus3.sh" - graphing script that can you edit and run again to process "nimbus3.rrd" and regenerate "nimbus3.svg"
  • "nimbus3.svg" - resulting graph, with a minimum width of 1000 and a maximum width equal to the number of collected rows (that is to say, the duration in seconds)

As you can see, in this case the duration was almost five hours and a half, making it hard to see the big picture:

nimbus3-long.svg

I modified "nimbus3.sh" to divide the graph width by five, in order to show five seconds per pixel and ran it again:

nimbus3-short.svg

Now the memory leak is clear, while maintaining enough info about the serial nature of the program and its bottlenecks.

Bonus feature: the SVG graph is regenerated every minute, during data collection, so you don't have to wait until the end to see what's what. Some image viewers (like Geeqie) refresh the image automatically when the file changes.

TODO

  • show voluntary context switches

License

Licensed and distributed under either of

or

at your option. These files may not be copied, modified, or distributed except according to those terms.

Homepage

https://github.com/status-im/process-stats