All of lore.kernel.org
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: Bart Van Assche <bvanassche@acm.org>
Cc: Omar Sandoval <osandov@fb.com>,
	linux-block@vger.kernel.org,
	Johannes Thumshirn <jthumshirn@suse.de>
Subject: Re: [PATCH blktests 1/2] Move and rename uptime_s()
Date: Thu, 24 Oct 2019 10:44:03 -0700	[thread overview]
Message-ID: <20191024174403.GC137052@vader> (raw)
In-Reply-To: <931f12af-d28f-0b32-9b09-42ad206827e8@acm.org>

On Thu, Oct 24, 2019 at 10:41:49AM -0700, Bart Van Assche wrote:
> On 10/24/19 10:27 AM, Omar Sandoval wrote:
> > On Mon, Oct 21, 2019 at 03:57:18PM -0700, Bart Van Assche wrote:
> > > +# System uptime in seconds.
> > > +_uptime_s() {
> > > +	local a b
> > > +
> > > +	echo "$(</proc/uptime)" | {
> > 
> > What's wrong with cat /proc/uptime? Or even better,
> > 
> >    { read ... } < /proc/uptime
> 
> Hi Omar,
> 
> As you probably know 'cat' triggers a fork() system call but echo $(<...)
> not. This is a performance optimization. Input redirection would also work.
> 
> > > +		read -r a b && echo "$b" >/dev/null && echo "${a%%.*}";
> > 
> > What's the point of the echo "$b" here?
> 
> That echo "$b" statement suppresses a shellcheck warning about $b not being
> used.
> 
> > Seems like this could all be condensed to:
> > 
> >    { read -r s && echo "${s%%.*}" } < /proc/uptime
> > 
> > But that's more cryptic than it needs to be. Can we just do:
> > 
> >    awk '{ print int($1) }' /proc/uptime
> 
> That's a valid alternative, but an alternative that triggers a fork() system
> call. I don't have a strong opinion about which alternative to choose. Do
> you perhaps have a preference?

The awk option is more readable, and we're not trying to win any
performance awards in blktests. Let's just go with that.

  reply	other threads:[~2019-10-24 17:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-21 22:57 [PATCH blktests 0/2] Add a test that triggers blk_mq_update_nr_hw_queues() Bart Van Assche
2019-10-21 22:57 ` [PATCH blktests 1/2] Move and rename uptime_s() Bart Van Assche
2019-10-22 17:55   ` Chaitanya Kulkarni
2019-10-24 17:27   ` Omar Sandoval
2019-10-24 17:41     ` Bart Van Assche
2019-10-24 17:44       ` Omar Sandoval [this message]
2019-10-21 22:57 ` [PATCH blktests 2/2] Add a test that triggers blk_mq_update_nr_hw_queues() Bart Van Assche
2019-10-22 17:59   ` Chaitanya Kulkarni
2019-10-24 17:42   ` Omar Sandoval
2019-10-24 17:55     ` Bart Van Assche
2019-10-24 17:58       ` Omar Sandoval

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191024174403.GC137052@vader \
    --to=osandov@osandov.com \
    --cc=bvanassche@acm.org \
    --cc=jthumshirn@suse.de \
    --cc=linux-block@vger.kernel.org \
    --cc=osandov@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.