Skip to content

Conversation

mkoeppe
Copy link
Contributor

@mkoeppe mkoeppe commented Apr 11, 2024

A minor follow-up after #37391:

Seen for example in
https://github.com/sagemath/sage/actions/runs/8626379356/job/23644513913?pr=37570#step:11:3227:

#24 4091.8 /sage/build/bin/sage-logger: line 66: /usr/bin/time: No such file or directory
#24 4091.8 [sagemath_doc_html-none] installing. Log file: /sage/logs/pkgs/sagemath_doc_html-none.log
#24 5807.5 cat: /sage/logs/pkgs/sagemath_doc_html-none.time: No such file or directory

We suppress these (harmless) messages which show up when /usr/bin/time is not available.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

⌛ Dependencies

Copy link

Documentation preview for this PR (built with commit ededb59; changes) is ready! 🎉

Copy link
Member

@DavidAyotte DavidAyotte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me!

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 13, 2024

Thanks!

@@ -63,15 +63,15 @@ fi

timefile="$logdir/$logname.time"
rm -f "$timefile"
if /usr/bin/time -h -o /dev/null true; then
if /usr/bin/time -h -o /dev/null true 2>/dev/null; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure ubuntu has /usr/bin/time available. The problem is that you are using nonstandard arguments to time(1):

$ /usr/bin/time -h -o /dev/null
/usr/bin/time: invalid option -- 'h'
Try '/usr/bin/time --help' for more information.
$ echo $?
125

Also, if you want to parse the time you should pass -p to ensure the standard format is used (https://www.man7.org/linux/man-pages/man1/time.1p.html), and then you can just use the bash builtin.

For what you are trying to acomplish, you could also use bash variables $EPOCHSECONDS (or $EPOCHREALTIME for more precision).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reviewer specifically asked for the human-readable format to be used.
The whole thing is just a convenience.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reviewer specifically asked for the human-readable format to be used. The whole thing is just a convenience.

I don't know what is "the human-readable format" but -h is not supported by gnu time(1) nor by the bash builtin.

Gnu time does support -o but not -h.

If you want to bypass the bash builtin, the better approach is to use \time which will still search in PATH.

For what you are trying to acomplish, you could also use bash variables $EPOCHSECONDS (or $EPOCHREALTIME for more precision).

There's also $SECONDS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reviewer specifically asked for the human-readable format to be used. The whole thing is just a convenience.

I see, but then the bash builtin time is just what the reviewer asked for.

You could

  • do the redirect 2>&1 inside the sh -c "..."
  • capture with 2> the output of time

(since the bash builtin doesn't support -o)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to prepare a follow-up PR, I can test it for its portability. I don't have time to work on it myself at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to prepare a follow-up PR, I can test it for its portability. I don't have time to work on it myself at the moment.

Please don't tell me what I should do with my time.

My comment before was just remarking that the current PR does not fix the issue but only hides it. Reverting cb4e718 for the time being seems to be easier workaround, until you or someone else gets the time to improve the output in a portable way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't tell me what I should do with my time.

@tornaria And I am not, so don't tell me what I shouldn't tell you.

@tornaria
Copy link
Contributor

Please revert cb4e718 so this works on all supported platforms.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 16, 2024

No, that's outside of the scope of this PR.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 16, 2024

Per PR description, this PR resolves the messages displayed /usr/bin/time: No such file or directory when there is no /usr/bin/time binary.

@tornaria
Copy link
Contributor

No, that's outside of the scope of this PR.

It's in scope for #37391 which was incorrect in this regard. The follow-up should be fixing, not hiding it.

The error you showed is

cat: /sage/logs/pkgs/sagemath_doc_html-none.time: No such file or directory

this has nothing to do with the absence of /usr/bin/time, rather with the fact that time -h fails because of the non-standard option.

Reverting cb4e718 seems easy enough; this ends up with your original PR which is the one I assume you tested most. Trying to satisfy a very reasonable request by @kwankyu is great, but not at the expense of breaking in a lot of supported systems.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 16, 2024

Please, Gonzalo, the PR author sets scope of the PR.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 16, 2024

If you look at the actual ticket description, line 1:

#24 4091.8 /sage/build/bin/sage-logger: line 66: /usr/bin/time: No such file or directory
#24 4091.8 [sagemath_doc_html-none] installing. Log file: /sage/logs/pkgs/sagemath_doc_html-none.log
#24 5807.5 cat: /sage/logs/pkgs/sagemath_doc_html-none.time: No such file or directory

So yes, this PR is about absence of /usr/bin/time as indicated.

@tornaria
Copy link
Contributor

If you look at the actual ticket description, line 1:

#24 4091.8 /sage/build/bin/sage-logger: line 66: /usr/bin/time: No such file or directory
#24 4091.8 [sagemath_doc_html-none] installing. Log file: /sage/logs/pkgs/sagemath_doc_html-none.log
#24 5807.5 cat: /sage/logs/pkgs/sagemath_doc_html-none.time: No such file or directory

So yes, this PR is about absence of /usr/bin/time as indicated.

But #37391 is also broken on boxes where /usr/bin/time is available but

$ /usr/bin/time -h -o /dev/null true
/usr/bin/time: invalid option -- 'h'
Try '/usr/bin/time --help' for more information.
$ echo $?
125

This includes most linux boxes.

I grant you that changing this to use the builtin time or $SECONDS is more work, so I understand not doing that. But changing this to not use -h seems very easy.

I'll show myself the exit. I was only trying to help since I know (and appreciate) you are always concerned about portability.

PS: note that time bash builtin output cannot be captured:

$ time 2> /dev/null

real	0m0.000s
user	0m0.000s
sys	0m0.000s
$

so the obvious using time or time -p and capture with 2> doesn't seem to work. What you can do is run the time in a subshell like so:

$ ( time true ) 2> /dev/null
$

In fact, you could do something like the following:

$ cmd="echo some stdout; sleep 1; echo and some stderr; exit 42"
$ timeit=$( (>>logfile.txt 2>&1 time sh -c "$cmd") 2>&1 ) ; status=$?
$ echo $status
42
$ echo $timeit
real 0m1.004s user 0m0.003s sys 0m0.002s
$ cat logfile.txt 
some stdout
and some stderr
$

PS2: when you want to skip a bash builtin, the common idiom is \time which will still search for time in PATH so you avoid hardcoding it and allow the user to replace the command if they so wish.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 17, 2024

I'll show myself the exit. I was only trying to help

That's appreciated, and I will benefit from the details and suggestions that you made when I work on the follow-up PR. Thank you.

@tornaria
Copy link
Contributor

I'll show myself the exit. I was only trying to help

That's appreciated, and I will benefit from the details and suggestions that you made when I work on the follow-up PR. Thank you.

I think my last suggestion might be useful. It seems to me that the format for the bash builtin time is similar to the output of time -h that you parse, so possibly you don't need to change report_time.

Since all of our scripts already depend on bash (as the shebang shows) depending on bashisms of the time builtin is "kind of" ok (at least it should be the same everywhere).

vbraun pushed a commit to vbraun/sage that referenced this pull request Apr 20, 2024
… messages

<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

A minor follow-up after sagemath#37391:

Seen for example in
https://github.com/sagemath/sage/actions/runs/8626379356/job/23644513913
?pr=37570#step:11:3227:
```
sagemath#24 4091.8 /sage/build/bin/sage-logger: line 66: /usr/bin/time: No such
file or directory
sagemath#24 4091.8 [sagemath_doc_html-none] installing. Log file:
/sage/logs/pkgs/sagemath_doc_html-none.log
sagemath#24 5807.5 cat: /sage/logs/pkgs/sagemath_doc_html-none.time: No such
file or directory
```
We suppress these (harmless) messages which show up when `/usr/bin/time`
is not available.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->

URL: sagemath#37785
Reported by: Matthias Köppe
Reviewer(s): David Ayotte, Gonzalo Tornaría, Matthias Köppe
@vbraun vbraun merged commit e7cf269 into sagemath:develop Apr 27, 2024
vbraun pushed a commit to vbraun/sage that referenced this pull request May 18, 2024
sagemathgh-37840: `sage-logger`: Replace use of `/usr/bin/time` by bash keyword `time`
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Follow-up after
- sagemath#37391
- sagemath#37785

... to make the display of package build times available on Linux too.

Fixes
sagemath#37785 (comment),
closes sagemath#37832.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
- Depends on sagemath#37785
    
URL: sagemath#37840
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
vbraun pushed a commit to vbraun/sage that referenced this pull request May 18, 2024
sagemathgh-37840: `sage-logger`: Replace use of `/usr/bin/time` by bash keyword `time`
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Follow-up after
- sagemath#37391
- sagemath#37785

... to make the display of package build times available on Linux too.

Fixes
sagemath#37785 (comment),
closes sagemath#37832.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
- Depends on sagemath#37785
    
URL: sagemath#37840
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
vbraun pushed a commit to vbraun/sage that referenced this pull request May 24, 2024
sagemathgh-37840: `sage-logger`: Replace use of `/usr/bin/time` by bash keyword `time`
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Follow-up after
- sagemath#37391
- sagemath#37785

... to make the display of package build times available on Linux too.

Fixes
sagemath#37785 (comment),
closes sagemath#37832.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
- Depends on sagemath#37785
    
URL: sagemath#37840
Reported by: Matthias Köppe
Reviewer(s): Gonzalo Tornaría, Kwankyu Lee, Matthias Köppe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants