[PATCH 1/3] test: add functions to count how much times notmuch was called
Tomi Ollila
tomi.ollila at iki.fi
Wed Nov 30 03:53:24 PST 2011
On Wed, 30 Nov 2011 01:03:27 +0400, Dmitry Kurochkin <dmitry.kurochkin at gmail.com> wrote:
> Hi Tomi.
>
> On Tue, 29 Nov 2011 14:58:00 +0200, Tomi Ollila <tomi.ollila at iki.fi> wrote:
> > Hi Dmitry.
[ ... ]
> >
> > The (posix) shell command language defines 'Arithmetic Expansion' in
> >
> > http://pubs.opengroup.org/onlinepubs/007908799/xcu/chap2.html#tag_001_006_004
> >
> > I.e. using format $(( expression )) makes shell doing the arithetic itself
> > instead of forking a process (or two!) to do so.
> >
>
> I though expr was a builtin. Now I agree that it is better to replace
> it with $(()), even though I still prefer the expr syntax.
Actually, I thought also that expr was a builtin. That makes the resolution
'forks subshell to execute builtin expr' below wrong. If it were a builtin
then bash would also fork only once (to get details right). I re-tested
with zsh using 'builtin pwd' and '/bin/pwd' instead of 'expr' -- only one fork
in each case. So, those who examined my tests with deep interest also note
this correction.
> > Normally in this case it is not so big deal (and still it isn't, but...)
> > In this particular case the shell wrapper counting notmuch launches and
> > exec'ing it the wrapper could do this without fork(2)ing a single time
> > (i.e. keep the process count unchanged compared to execing notmuch
> > directly)
> >
> > Anyway, many opinions; as far as it works I'm fine with it :)
> >
> > Now that you feel relaxed, check the results of some further
> > experimentation ;) :
> >
> > excerpt from man strace:
> >
> > -ff If the -o filename option is in effect, each processes
> > trace is written to filename.pid where pid is the
> > numeric process id of each process.
> >
> > Executing rm -f forked.*; strace -ff -o forked bash -c 'echo $(( 5 + 5 ))'
> >
> > will output '10' and create just one 'forked.<pid>' file
> >
> > Executing rm -f forked.*; strace -ff -o forked bash -c 'echo $(expr 5 + 5)'
> >
> > output 10 as expected, but there is now *3* forked.<pid> files !
> >
> > bash does not optmize; it forks subshell to execute $(...) and then
> > there just works as usual (forks subshell to execute builtin expr))
> >
> > Executing rm -f forked.*; strace -ff -o forked bash -c 'echo $(exec expr 5 + 5)'
> >
> > (the added 'exec' takes off one fork -- just 2 forked.<pid> files appear).
> >
> > I did the same tests using dash, ksh & zsh on linux system, and every one
> > of these managed to optimize one fork out in the above 3 fork case.
> >
>
> Thanks for details.
>
> Regards,
> Dmitry
>
> >
> > Tomi
Tomi
More information about the notmuch
mailing list