This file is indexed.

/var/lib/pcp/config/pmchart/BusyCPU is in pcp-gui 4.0.1-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/sh
#
# Dynamic kmchart view for the most busy current processes ... note
# this is a snapshot at the time the view is instantiated and does
# not track the busiest processes over time
#
# Busy here means CPU consumption
#

# a token attempt to make this general
. /etc/pcp.env

tmp=`mktemp -d /var/tmp/pcp.XXXXXXXXX` || exit 1
trap "rm -rf $tmp; exit" 0 1 2 3 15

# bad stuff ...
#
_err()
{
    echo "Failed to fetch user mode CPU cycles metrics" >$tmp/msg
    echo >>$tmp/msg
    for f in $tmp/err.*
    do
	cat $f >>$tmp/msg
    done
    echo >>$tmp/msg
    echo "Sorry, there is nothing to display." >>$tmp/msg
    if $dialog
    then
	pmconfirm >/dev/null \
	    -header "pmchart view construction failure" \
	    -file $tmp/msg \
	    -icon error \
	    -B "OK"
    else
	cat >&2 $tmp/msg
    fi
    exit
    }

# find top 10 consumers of user mode CPU cycles and generate a plot for each
#
# top(1) is ill-suited for use in a script, so we have to emulate this
# using PCP tools as follows:
#    1. get cummulative user mode CPU cycles for all processes
#    2. sleep 5 seconds
#    3. get cummulative user mode CPU cycles for all processes
#    4. compute delta user mode CPU cycles from 1. and 2.
#    5. sort and select top 10 processes
#

# use $tmp/sed to remove this shell and its children from
# the list of busy processses
#
echo "/\[0*$$ /d" >$tmp/sed

dialog=true
if [ "${PCP_STDERR+set}" = set ]
then
    if [ -z "$PCP_STDERR" -o "$PCP_STDERR" != DISPLAY ]
    then
	dialog=false
    fi
fi

if $dialog
then
    # progress notifier while we do our job
    #
    pmquery >/dev/null 2>&1 \
	-timeout 5 \
	-header "pmchart view construction" \
	-t "Finding top CPU burners, please wait 5 seconds ..." &
    query=$!
    echo "/\[0*$query /d" >>$tmp/sed
fi

# deal with alternative metric names ...
#
i=0
fail=true
for metric in proc.psinfo.utime proc.psusage.utime
do
    nval=`pmprobe -ifF $* $metric 2>&1 \
          | tee $tmp/err.$i \
	  | $PCP_AWK_PROG '$1 == "'$metric'" && $2 > 0 {print $2}'`
    if [ -n "$nval" ] && [ "$nval" -gt 0 ]
    then
	fail=false
	break
    fi
    i=`expr $i + 1`
done
if $fail
then
    _err
    #NOTREACHED
fi

# note arguments from pmchart are nothing or -h host or -a archive
#
if pminfo -F $* $metric >$tmp/1 2>$tmp/err.a
then
    sleep 5
    if pminfo -F $* $metric >$tmp/2 2>$tmp/err.b
    then
	:
    else
	_err
	#NOTREACHED
    fi
else
    _err
    #NOTREACHED
fi

# get pid and user mode CPU cycles usage from lines like
#	inst [8072 or "08072 rlogin gonzo.melbourne "] value 28
# and turn them into this
# $tmp/1.list
#	8072 28
# $tmp/2.list
#	8072 28 08072 rlogin gonzo.melbourne
#

sed -f $tmp/sed $tmp/1 \
| sed -n -e '/inst \[/{
s/.*inst \[//
s/ or .* \([0-9][0-9]*\)$/ \1/p
}' \
| sort -k 1b,1 >$tmp/1.list

sed -n -e '/inst \[/{
s/.*inst \[//
s/or "\(.*\)".* \([0-9][0-9]*\)$/\2 \1/p
}' $tmp/2 \
| sort -k 1b,1 >$tmp/2.list

#DEBUG# echo "First list ..." >/tmp/busy.debug
#DEBUG# cat $tmp/1.list >>/tmp/busy.debug
#DEBUG# echo "Second list ..." >>/tmp/busy.debug
#DEBUG# cat $tmp/2.list >>/tmp/busy.debug

join -j1 $tmp/1.list $tmp/2.list \
| $PCP_AWK_PROG '
$3 > $2	{ # this process has consumed some user mode CPU cycles
	  printf "%d",$3-$2
	  for (i = 4; i <= NF; i++) printf " %s",$i
	  print""
	}' >$tmp/found

if [ ! -s $tmp/found ]
then
    # no processes qualify
    #
    if $dialog
    then
	pmconfirm >/dev/null \
	    -header "pmchart view construction failure" \
	    -t "No qualifying processes were found!" \
	    -icon warning \
	    -B "OK"
    else
	echo "pmchart view construction failure: No qualifying processes were found!"
    fi
    exit
fi

# chart preamble
#
cat <<End-of-File
#pmchart
Version 2.0 host dynamic

Chart Title "Top user mode CPU burners at `date +'%a %b %e %R'`" Style stacking
End-of-File

# plot specifications, one per process
#

sort -nr +0 -1 $tmp/found \
| sed 10q \
| while read cpuburn inst
do
    echo "  Plot Color #-cycle Host * Metric $metric Instance $inst"
done