FreeBSD Bugzilla – Attachment 235776 Details for
Bug 262743
Memory leak in security/strongswan's charon daemon when communicating over vici socket.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Script for tracing memory footprint fof process given by pid or its name
memlogger.sh (text/plain), 4.23 KB, created by
Michał Skalski
on 2022-08-08 15:37:21 UTC
(
hide
)
Description:
Script for tracing memory footprint fof process given by pid or its name
Filename:
MIME Type:
Creator:
Michał Skalski
Created:
2022-08-08 15:37:21 UTC
Size:
4.23 KB
patch
obsolete
>#!/bin/sh ># -- coding: utf-8 -- ># Simple script for monitoring memory usage of given process > > >PS_GETPID_OPTS='-ax -ocomm= -opid=' >PS_STATS_OPTS='-opid= -orss= -ovsz=' >PRINT_HEADER=true >WAIT=5 > ># find process pid by its executable name >process_pid() >{ > local procname > procname="$1" > ps ${PS_GETPID_OPTS} | sed -ne "s/^$procname[ ][ ]*//p" >} > > ># Gets process statistics by process pid >proc_stats() >{ > ps -p "$1" ${PS_STATS_OPTS} >} > >timestamp() >{ > local fmt > > fmt="$1" > [ -z "$fmt" ] && fmt='%s %Y-%m-%d %H:%M:%S' > date "+$fmt" >} > >print_stat() >{ > printf '%10s %10s %-9s %5d %10d %10d\n' "$@" >} > >print_header() >{ > printf '%10s %-10s %9s %-5s %10s %10s\n' 'UNIX_STAMP' 'DATETIME' '' 'PID' 'RSS ' 'VMS ' >} > ># Monitors usage of memory for given by pid process >monitor_process() >{ > local memstats tstamp procpid wait msg ret > > procpid="$1" > wait="$2" > > msg=`kill -0 "$procpid" 2>&1` > ret=$? > if [ $ret -ne 0 ] && ! echo "$msg" | grep -q 'Operation not permitted'; then > echo "Error: Process given by pid $procpid does not exist or is not readable: $msg" 1>&2 > return 2 > fi > > while :; do > memstats=`proc_stats "$procpid"` || break > if ${PRINT_HEADER}; then > print_header > PRINT_HEADER=false > fi > print_stat `timestamp` ${memstats} > [ -n "$wait" ] && sleep "$wait" > done > > return 1 >} > >setup_options() >{ > case "`uname -s`" in > Linux) > PS_GETPID_OPTS='hax -ocomm,pid' > PS_STATS_OPTS='h -opid,rss,vsz' > ;; > esac >} > > >usage() >{ > local myname > myname=`basename "$0"` > >cat <<EOF >Usage: $myname [options] [logfile [procname]] > $myname --help > >Options: > -p|--pid <pid> monitor process given by its pid > -n|--name <name> monitor process given by its name > same as 'procname' parameter > -w|--wait <time> wait <time>s beetween each check > -a|--append append to logfile instead of overwriting it > -x|--exit-on-fail Exit when given process is unavailable >EOF >} > ># Pobranie argumentu dla parametru, jeÅli $1 jest --allow-numeric, ># to dopuszczalne sÄ jeszcze jako argumenty liczby ujemne (zaczynajÄ ce siÄ od `-`) >get_arg() >{ > if [ "$#" -lt 2 ]; then > echo "$0: Error: $1 requires argument" 1>&2 > return 1; > fi > > case "$2" in > -*) > echo "$0: Error: $1 requires argument" 1>&2 > return 1 > ;; > esac > echo "$2" >} > >die() >{ > local myname > myname=`basename "$0"` > echo "$myname: $*" 1>&2 > exit 1 >} > >main() >{ > local t pid name exit_on_fail logfile wait msg append ret > > exit_on_fail=false > > name='charon' > append=false > > # Parse few options > while :; do > case "$1" in > --help) usage; exit 0;; > -p|--pid) > pid=`get_arg "$@"` || return 1 > shift; shift > ;; > -n|--name) > name=`get_arg "$@"` || return 1 > shift; shift > ;; > -w|--wait) > wait=`get_arg "$@"` || return 1 > shift; shift > ;; > -a|--append) > append=true > shift > ;; > -x|--exit-on-fail) > exit_on_fail=true > shift > ;; > --) shift; break ;; > -*) die "Unrecognized option: $1" ;; > *) break ;; > esac > done > > [ "$#" -ge 1 ] && logfile="$1" > [ "$#" -ge 2 ] && name="$2" > > setup_options > > [ -z "$wait" ] && wait="${WAIT}" > [ -z "$logfile" ] || [ "$logfile" = "-" ] && logfile=/dev/stdout > > if [ -n "$pid" ]; then > # Only monitor process by its pid, exit when finished or when process finishes > if $append; then > monitor_process "$pid" "$wait" >> "$logfile" > else > monitor_process "$pid" "$wait" > "$logfile" > fi > elif [ -n "$name" ]; then > msg='' > while :; do > pid=`process_pid "$name"` > if [ -z "$pid" ]; then > if [ -z "$msg" ]; then > msg="No process $name found" > echo `timestamp '%Y-%m-%d %H:%M:%S:'` "$msg" 1>&2 > fi > [ -n "$wait" ] && sleep "$wait" > continue > fi > msg='' > if ! $append; then > monitor_process "$pid" "$wait" > "$logfile" > append=true > else > monitor_process "$pid" "$wait" >> "$logfile" > fi > ret=$? > if $exit_on_fail && [ $ret -ne 0 ]; then > echo `timestamp '%Y-%m-%d %H:%M:%S:'` "Failed to read process memory stats" 1>&2 > return $ret > fi > done > else > echo "No process name nor its pid given" 1>&2 > return 2 > fi >} > >main "$@"
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 262743
:
232660
|
232661
| 235776 |
235777
|
235778
|
239436