# GNU time



## balanga (Jul 8, 2018)

(Not sure if this is the correct forum for this topic)

I'm trying to use GNU time but can't work how. There is no pkg gtime or gnutime, but the FreeBSD man page does mention it. It says 





> *GNU VERSION*
> Below  a     description of    the GNU    1.7 version of *time*.  Disregarding the
> name of the utility, GNU    makes it output    lots  of  useful  information,
> not  only about time used, but also on other resources like memory, I/O
> ...


So, how do I invoke GNU time?


----------



## Deleted member 48958 (Jul 8, 2018)

balanga said:


> *GNU VERSION*


You're reading Red Hat Linux 8.0 i386 "time" manual page.





So this utility shouldn't be available in FreeBSD.
Here is FreeBSD time(1) man page.


----------



## unitrunker (Jul 8, 2018)

You're actually looking at the red hat man page.

Edit: beat me to it.


----------



## balanga (Jul 8, 2018)

So why does FreeBSD have a man page for a Linux program?

And how can I run the equivalent of GNU time on FreeBSD?


----------



## ShelLuser (Jul 8, 2018)

balanga said:


> So why does FreeBSD have a man page for a Linux program?


It doesn't. Well, not unless you install said Linux program through the Ports collection of course. 

The FreeBSD website on other other hand does, yet where's the problem in that?



balanga said:


> And how can I run the equivalent of GNU time on FreeBSD?


By using time(1)?  See also /usr/bin/time.


----------



## phoenix (Jul 9, 2018)

balanga said:


> And how can I run the equivalent of GNU time on FreeBSD?



FreeBSD includes the time(1) program. Are there specific features of GNU time you are trying to use that aren't available in FreeBSD time?


----------



## SirDice (Jul 9, 2018)

Note that there's a time shell builtin and a /usr/bin/time executable. They're both different, have different options and different outputs.


----------



## balanga (Jul 9, 2018)

SirDice said:


> Note that there's a time shell builtin and a /usr/bin/time executable. They're both different, have different options and different outputs.



So when execute `time` how do you know which you are running?


----------



## SirDice (Jul 9, 2018)

Most likely the shell builtin (it has precedence over one on the path). Execute `/usr/bin/time` if you need to use time(1).


----------



## balanga (Jul 9, 2018)

phoenix said:


> FreeBSD includes the time(1) program. Are there specific features of GNU time you are trying to use that aren't available in FreeBSD time?



There probably are, but I don't know specifically what. A configure script runs OK on Linux but fails on FreeBSD when checking `time`. I installed all the GNU utils on FreeBSD one by one as I ran the script checking where it failed. Eventually it stopped at the time check, but I could not find a FreeBSD port of GNU time.

Here's what I got initially:-

```
root@Vbox:~/openwrt # ls -al[6D./scripts/update -a[4hf[4l[4he[4l[4he[4l[4hd[4l[4hs[4l[4h [4l

Updating feed 'packages' from '[URL]https://git.openwrt.org/feed/packages.git[/URL]' ...
Already up to date.
Create index file './feeds/packages.index' 
Checking 'working-make'... ok.
Checking 'case-sensitive-fs'... ok.
Checking 'proper-umask'... ok.
Checking 'gcc'... ok.
Checking 'working-gcc'... ok.
Checking 'g++'... ok.
Checking 'working-g++'... ok.
Checking 'ncurses'... ok.
Checking 'perl-thread-queue'... ok.
Checking 'tar'... failed.
Checking 'find'... failed.
Checking 'bash'... ok.
Checking 'patch'... failed.
Checking 'diff'... ok.
Checking 'cp'... failed.
Checking 'seq'... failed.
Checking 'awk'... failed.
Checking 'grep'... ok.
Checking 'getopt'... failed.
Checking 'stat'... failed.
Checking 'unzip'... ok.
Checking 'bzip2'... ok.
Checking 'wget'... ok.
Checking 'time'... failed.
Checking 'perl'... ok.
Checking 'python'... ok.
Checking 'git'... ok.
Checking 'file'... ok.
Prerequisite check failed. Use FORCE=1 to override.
gmake: *** [/root/openwrt/include/toplevel.mk:168: staging_dir/host/.prereq-build] Error 1
awk: calling undefined function asort
```

and finally after installing the GNU programs:

```
Create index file './feeds/packages.index' 
Checking 'working-make'... ok.
Checking 'case-sensitive-fs'... ok.
Checking 'proper-umask'... ok.
Checking 'gcc'... ok.
Checking 'working-gcc'... ok.
Checking 'g++'... ok.
Checking 'working-g++'... ok.
Checking 'ncurses'... ok.
Checking 'perl-thread-queue'... ok.
Checking 'tar'... ok.
Checking 'find'... ok.
Checking 'bash'... ok.
Checking 'patch'... ok.
Checking 'diff'... ok.
Checking 'cp'... ok.
Checking 'seq'... ok.
Checking 'awk'... ok.
Checking 'grep'... ok.
Checking 'getopt'... ok.
Checking 'stat'... ok.
Checking 'unzip'... ok.
Checking 'bzip2'... ok.
Checking 'wget'... ok.
[B]Checking 'time'... failed.[/B]
Checking 'perl'... ok.
Checking 'python'... ok.
Checking 'git'... ok.
Checking 'file'... ok.
Prerequisite check failed. Use FORCE=1 to override.
gmake: *** [/root/source/include/toplevel.mk:168: staging_dir/host/.prereq-build] Error 1
/bin/sh: mkhash: not found
```

I can't work out where these checks are made, but apparently it was possibly to run this on FreeBSD at one point.


----------



## Deleted member 48958 (Jul 9, 2018)

balanga said:


> So when execute  time how do you know which you are running?


Also, when you don't want to use shell built-in commands, add "\" to the begining of
command, so, when you need to start /usr/bin/time instead of shell built-in "time",
you should use `% \time`, this method also useful, when you don't want 
to use shell aliases, set in your shell configuration file. For example 




It's working with tcsh, bash, zsh and some other shells.


----------



## Maxnix (Jul 9, 2018)

ILUXA said:


> It's working with tcsh, bash, zsh and some other shells.


Thank you. Works with /bin/sh too, so it should be pretty universal.


----------



## sko (Jul 10, 2018)

balanga said:


> So when execute `time` how do you know which you are running?



To find out which (if any) binary/script is used, just use which(1):


```
% which time
time: shell built-in command.
% which \time
/usr/bin/time
```


----------



## jef (Jul 11, 2018)

The feature of GNU time in question is, I believe, the non-standard -f flag that is used by the build system that OpenWRT presently uses. The version of sysutils/busybox installed by pkg(8) apparently does not include the time applet (used by the OpenWRT build system as a fall-back option). The Makefile for the FreeBSD port of busybox, at least by my reading of it, does not supply options to enable/disable specific applets.

Once an appropriate "time" is selected by the build system, it appears to be called from include/subdir.mk

```
41 log_make = \
     42          $(if $(call debug,$(1),v),,@)+ \
     43          $(if $(BUILD_LOG), \
     44                 set -o pipefail; \
     45                 mkdir -p $(BUILD_LOG_DIR)/$(1)$(if $(4),/$(4));) \
     46         env time -f "time: $(1)$(if $(4),/$(4))/$(if $(3),$(3)-)$(2)\#%U\#%S\#%e" -- \
     47         $$(SUBMAKE) $(subdir_make_opts) $(if $(3),$(3)-)$(2) \
     48                 $(if $(BUILD_LOG),SILENT= 2>&1 | tee $(BUILD_LOG_DIR)/$(1)$(if $(4),/$(4))/$(if $(3),$(3)-)$(2).txt)
```


----------



## balanga (Jul 11, 2018)

jef said:


> The feature of GNU time in question is, I believe, the non-standard -f flag that is used by the build system that OpenWRT presently uses. The version of sysutils/busybox installed by pkg(8) apparently does not include the time applet (used by the OpenWRT build system as a fall-back option). The Makefile for the FreeBSD port of busybox, at least by my reading of it, does not supply options to enable/disable specific applets.



Are you suggesting that if I built sysutils/busybox from ports, making some changes to the Makefile I would be able to use the OpenWrt build system on FreeBSD?


----------



## balanga (Jul 16, 2018)

phoenix said:


> FreeBSD includes the time(1) program. Are there specific features of GNU time you are trying to use that aren't available in FreeBSD time?




Apparently GNU time supports an '-f' parameter which is required by the OpenWrt build system, otherwise I need to make changes to the build system to accomodate FreeBSD.

It seems strange the most of the GNU utils have been ported to FreeBSD, but gtime is an exception...


----------



## balanga (Aug 3, 2018)

jef said:


> The feature of GNU time in question is, I believe, the non-standard -f flag that is used by the build system that OpenWRT presently uses. The version of sysutils/busybox installed by pkg(8) apparently does not include the time applet (used by the OpenWRT build system as a fall-back option). The Makefile for the FreeBSD port of busybox, at least by my reading of it, does not supply options to enable/disable specific applets.
> 
> Once an appropriate "time" is selected by the build system, it appears to be called from include/subdir.mk
> 
> ...



Can I just omit the '-f' parameter from line 46?

Any idea where the actual checking of required components is done?


----------



## balanga (Aug 3, 2018)

After getting some help from the OpenWrt Forum I managed to run make menuconfig as part of the OpenWrt build system and it looked the same as it does on Linux, but at the end when running `make` I was hit by the lack of a GNU time again.

It's strange that GNU time hasn't been ported since many other GNU utilities are available under FreeBSD.

Does anyone know what is involved in getting a simple utility like time built on FreeBSD? Looking at gsed in ports there is only a makefile - no patches. gawk has a single one line patch. But if it hasn't already been ported it may be trickier than it seems...


----------



## balanga (Aug 4, 2018)

I managed to build it! This is all it took:-

```
wget https://ftp.gnu.org/gnu/time/time-1.9.tar.gz
tar zxf time-1.9.tar.gz
cd time-1.9
./configure
make
```
For my purposes I can simply copy time  as gtime  to /usr/local/bin/  but is there a way of doing it properly using `make install`? ie like FreeBSD pkg would handle it...


----------



## chrbr (Aug 5, 2018)

Dear balanga,
please have a look at https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/.
The effort of generating a port is surprisingly simple if there are almost no dependencies. You can even have the port in your ports tree as an alien.


----------

