| Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 | # | 
| YAMAMOTO Takashi | 42373c7 | 2014-11-18 12:30:16 +0900 | [diff] [blame] | 3 | # lib/dstat | 
| Joe Gordon | e0b08d0 | 2014-08-20 00:34:55 -0700 | [diff] [blame] | 4 | # Functions to start and stop dstat | 
|  | 5 |  | 
|  | 6 | # Dependencies: | 
|  | 7 | # | 
|  | 8 | # - ``functions`` file | 
|  | 9 |  | 
|  | 10 | # ``stack.sh`` calls the entry points in this order: | 
|  | 11 | # | 
| Federico Ressi | 19e4d97 | 2020-01-24 11:44:46 +0100 | [diff] [blame] | 12 | # - install_dstat | 
| Joe Gordon | e0b08d0 | 2014-08-20 00:34:55 -0700 | [diff] [blame] | 13 | # - start_dstat | 
|  | 14 | # - stop_dstat | 
|  | 15 |  | 
|  | 16 | # Save trace setting | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 17 | _XTRACE_DSTAT=$(set +o | grep xtrace) | 
| Joe Gordon | e0b08d0 | 2014-08-20 00:34:55 -0700 | [diff] [blame] | 18 | set +o xtrace | 
|  | 19 |  | 
| Federico Ressi | 19e4d97 | 2020-01-24 11:44:46 +0100 | [diff] [blame] | 20 | # install_dstat() - Install prerequisites for dstat services | 
|  | 21 | function install_dstat { | 
|  | 22 | if is_service_enabled memory_tracker; then | 
|  | 23 | # Install python libraries required by tools/mlock_report.py | 
|  | 24 | pip_install_gr psutil | 
|  | 25 | fi | 
|  | 26 | } | 
|  | 27 |  | 
| Sean Dague | 0eebeb4 | 2017-08-30 14:16:58 -0400 | [diff] [blame] | 28 | # start_dstat() - Start running processes | 
| Joe Gordon | e0b08d0 | 2014-08-20 00:34:55 -0700 | [diff] [blame] | 29 | function start_dstat { | 
|  | 30 | # A better kind of sysstat, with the top process per time slice | 
| Tim Buckley | a83e90b | 2015-08-05 10:25:00 -0600 | [diff] [blame] | 31 | run_process dstat "$TOP_DIR/tools/dstat.sh $LOGDIR" | 
| Ian Wienand | 72a8be6 | 2015-04-09 13:51:23 +1000 | [diff] [blame] | 32 |  | 
| Ihar Hrachyshka | 2b4735f | 2017-02-10 06:17:37 +0000 | [diff] [blame] | 33 | # To enable memory_tracker add: | 
|  | 34 | #    enable_service memory_tracker | 
| Ian Wienand | 72a8be6 | 2015-04-09 13:51:23 +1000 | [diff] [blame] | 35 | # to your localrc | 
| Sean Dague | 5edae54 | 2017-03-21 20:50:24 -0400 | [diff] [blame] | 36 | run_process memory_tracker "$TOP_DIR/tools/memory_tracker.sh" "" "root" | 
| Ihar Hrachyshka | 2b4735f | 2017-02-10 06:17:37 +0000 | [diff] [blame] | 37 |  | 
| Jens Harbott | 95634d9 | 2019-02-21 12:24:17 +0000 | [diff] [blame] | 38 | # TODO(jh): Fail when using the old service name otherwise consumers might | 
|  | 39 | # never notice that is has been removed. | 
| Ihar Hrachyshka | 2b4735f | 2017-02-10 06:17:37 +0000 | [diff] [blame] | 40 | if is_service_enabled peakmem_tracker; then | 
| Jens Harbott | 95634d9 | 2019-02-21 12:24:17 +0000 | [diff] [blame] | 41 | die $LINENO "The peakmem_tracker service has been removed, use memory_tracker instead" | 
| Ihar Hrachyshka | 2b4735f | 2017-02-10 06:17:37 +0000 | [diff] [blame] | 42 | fi | 
| Joe Gordon | e0b08d0 | 2014-08-20 00:34:55 -0700 | [diff] [blame] | 43 | } | 
|  | 44 |  | 
|  | 45 | # stop_dstat() stop dstat process | 
|  | 46 | function stop_dstat { | 
| Ian Wienand | c00d2a5 | 2015-04-09 19:57:13 +1000 | [diff] [blame] | 47 | stop_process dstat | 
| Ihar Hrachyshka | 2b4735f | 2017-02-10 06:17:37 +0000 | [diff] [blame] | 48 | stop_process memory_tracker | 
| Joe Gordon | e0b08d0 | 2014-08-20 00:34:55 -0700 | [diff] [blame] | 49 | } | 
|  | 50 |  | 
|  | 51 | # Restore xtrace | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 52 | $_XTRACE_DSTAT |