RE: [PATCH] perf test: Fix shadow stat test for non-bash shells

From: David Laight
Date: Tue Jan 12 2021 - 06:19:20 EST


From: Jiri Olsa
> Sent: 12 January 2021 09:30
>
> On Fri, Jan 08, 2021 at 04:47:12PM +0900, Namhyung Kim wrote:
> > It was using some bash-specific features and failed to parse when
> > running with a different shell like below:
...

You don't need a temporary file, one option is:

> > index 249dfe48cf6a..e2c7ac4ed91d 100755
> > --- a/tools/perf/tests/shell/stat+shadow_stat.sh
> > +++ b/tools/perf/tests/shell/stat+shadow_stat.sh
...
> > perf stat -a -A --no-big-num -e cycles,instructions sleep 1 2>&1 | \
> > grep ^CPU | \
> > while read cpu num evt hash ipc rest
> > do
...
> > + if [ "$evt" = "cycles" ]; then
> > + echo $cpu $num >> $results

results="$results $cpu:$num"

> > continue
> > fi
> >
> > # skip if no cycles
> > - local cyc=${results[$cpu]}
> > - if [[ -z $cyc ]]; then
> > + local cyc=$(grep $cpu $results | cut -d' ' -f2)

cyc=${results##* $cpu:}
cyc=$(cyc%% *}

> > + if [ -z "$cyc" ]; then
> > continue
> > fi

I can't remember when 'local' was invented.
You may find shells that don't support it.
In any case, since this is a small standalone file I'd
remove them just in case.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)