diff mbox series

[1/2] core/intrumetnation: don't spawn to get seconds-since-EPOCH

Message ID ef3b9c4c1ca910423b06f1374ee9461c77aaeed1.1521146096.git.yann.morin.1998@free.fr
State Rejected
Headers show
Series [1/2] core/intrumetnation: don't spawn to get seconds-since-EPOCH | expand

Commit Message

Yann E. MORIN March 15, 2018, 8:35 p.m. UTC
No need to spawn $(date) to get the number of seconds-since-EPOCH, as
bash's printf can do it as easily.

This is just a micro-optimisation, though. Probably not noticeable.

Reported-by: Trent Piepho <tpiepho@impinj.com>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Trent Piepho <tpiepho@impinj.com>
---
 package/pkg-generic.mk | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Cam Hutchison March 17, 2018, 11:54 a.m. UTC | #1
On 16 March 2018 at 07:35, Yann E. MORIN <yann.morin.1998@free.fr> wrote:
> No need to spawn $(date) to get the number of seconds-since-EPOCH, as
> bash's printf can do it as easily.
>
> This is just a micro-optimisation, though. Probably not noticeable.
>
> Reported-by: Trent Piepho <tpiepho@impinj.com>
> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
> Cc: Trent Piepho <tpiepho@impinj.com>
> ---
>  package/pkg-generic.mk | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
> index 9eddaeee57..2a82025a04 100644
> --- a/package/pkg-generic.mk
> +++ b/package/pkg-generic.mk
> @@ -49,8 +49,8 @@ endef
>
>  # Time steps
>  define step_time
> -       printf "%s:%-5.5s:%-20.20s: %s\n"           \
> -              "$$(date +%s)" "$(1)" "$(2)" "$(3)"  \
> +       printf "%(%s)T:%-5.5s:%-20.20s: %s\n"           \
> +              -1 "$(1)" "$(2)" "$(3)"  \

Should you note somewhere that this needs bash 4.2? I remember some
re-working of bash patches in the past to avoid the use of associative arrays
as they were not supported in the oldest version of bash supported by
buildroot. Is bash 4.2 ok now?

See http://tiswww.case.edu/php/chet/bash/NEWS for when features were
added to bash.

>                >>"$(BUILD_DIR)/build-time.log"
>  endef
>  GLOBAL_INSTRUMENTATION_HOOKS += step_time
> --
> 2.14.1
>
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
Yann E. MORIN March 18, 2018, 4:16 p.m. UTC | #2
Cam, All,

On 2018-03-17 22:54 +1100, Cam Hutchison spake thusly:
> On 16 March 2018 at 07:35, Yann E. MORIN <yann.morin.1998@free.fr> wrote:
> > No need to spawn $(date) to get the number of seconds-since-EPOCH, as
> > bash's printf can do it as easily.
> >
> > This is just a micro-optimisation, though. Probably not noticeable.
> >
> > Reported-by: Trent Piepho <tpiepho@impinj.com>
> > Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
> > Cc: Trent Piepho <tpiepho@impinj.com>
> > ---
> >  package/pkg-generic.mk | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
> > index 9eddaeee57..2a82025a04 100644
> > --- a/package/pkg-generic.mk
> > +++ b/package/pkg-generic.mk
> > @@ -49,8 +49,8 @@ endef
> >
> >  # Time steps
> >  define step_time
> > -       printf "%s:%-5.5s:%-20.20s: %s\n"           \
> > -              "$$(date +%s)" "$(1)" "$(2)" "$(3)"  \
> > +       printf "%(%s)T:%-5.5s:%-20.20s: %s\n"           \
> > +              -1 "$(1)" "$(2)" "$(3)"  \
> 
> Should you note somewhere that this needs bash 4.2? I remember some
> re-working of bash patches in the past to avoid the use of associative arrays
> as they were not supported in the oldest version of bash supported by
> buildroot. Is bash 4.2 ok now?
> 
> See http://tiswww.case.edu/php/chet/bash/NEWS for when features were
> added to bash.

OK, I'm dropping this change, then. Thanks for noticing. :-)

Regards,
Yann E. MORIN.
Trent Piepho March 19, 2018, 4:15 p.m. UTC | #3
On Sun, 2018-03-18 at 17:16 +0100, Yann E. MORIN wrote:
> > >  define step_time
> > > -       printf "%s:%-5.5s:%-20.20s: %s\n"           \
> > > -              "$$(date +%s)" "$(1)" "$(2)" "$(3)"  \
> > > +       printf "%(%s)T:%-5.5s:%-20.20s: %s\n"           \
> > > +              -1 "$(1)" "$(2)" "$(3)"  \
> > 
> > Should you note somewhere that this needs bash 4.2? I remember some
> > re-working of bash patches in the past to avoid the use of associative arrays
> > as they were not supported in the oldest version of bash supported by
> > buildroot. Is bash 4.2 ok now?
> > 
> 
> OK, I'm dropping this change, then. Thanks for noticing. :-)

If it weren't for the space padding of the fields, you could go the
other way and avoid the printf call and just use date.

define step_time
	date +"%s.%N:$(1):$(2):$(3)"

Not as pretty to look at, but just as parsable to a script.
diff mbox series

Patch

diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
index 9eddaeee57..2a82025a04 100644
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -49,8 +49,8 @@  endef
 
 # Time steps
 define step_time
-	printf "%s:%-5.5s:%-20.20s: %s\n"           \
-	       "$$(date +%s)" "$(1)" "$(2)" "$(3)"  \
+	printf "%(%s)T:%-5.5s:%-20.20s: %s\n"           \
+	       -1 "$(1)" "$(2)" "$(3)"  \
 	       >>"$(BUILD_DIR)/build-time.log"
 endef
 GLOBAL_INSTRUMENTATION_HOOKS += step_time