Skip to content

Use EPOCHREALTIME in build_data timing logic #1881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 22, 2025

Conversation

dzuelke
Copy link
Contributor

@dzuelke dzuelke commented Aug 22, 2025

Built-in Bash (5.0+) variable, a float with microseconds precision. Faster, simpler, and more portable (no longer requires GNU date).

GUS-W-19404492

@dzuelke dzuelke requested review from edmorley and a team as code owners August 22, 2025 14:06
Built-in Bash (5.0+) variable, a float with microseconds precision. Faster, simpler, and more portable (no longer requires GNU date).

Logging it with six digits worth of precision instead of the previous three, but a float is a float ;)

(without a precision indicator, awk gives the usual hand-wavy float result of possibly a few more digits, we just discard that)

GUS-W-19404492
@dzuelke dzuelke force-pushed the current_unix_time_ms-epochrealtime branch from c633034 to 022d606 Compare August 22, 2025 14:29
Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

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

Thank you! Good to switch to something more lightweight than the date subprocess call :-)

Signed-off-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Since the `print` causes less precision, eg:

```
root@d4d36b9d6a56:/# awk -v start="${start_time}" -v end="${end_time}" 'BEGIN { print (end - start) }'
13.2063
```

So it would be better to either switch back to `printf`:

```
root@d4d36b9d6a56:/# awk -v start="${start_time}" -v end="${end_time}" 'BEGIN { printf "%f", (end - start) }'
13.206290
```

Or use `OFMT` with `print`:
```
root@d4d36b9d6a56:/# awk -v start="${start_time}" -v end="${end_time}" -v OFMT="%f" 'BEGIN { print (end - start) }'
13.206290
```

Given that we don't want the trailing newline (albeit the command substitution removes it for us), lets go with `printf` again (plus it saves people having to understand `OFMT`).
@edmorley edmorley enabled auto-merge (squash) August 22, 2025 16:13
@edmorley edmorley merged commit 30086f2 into main Aug 22, 2025
9 of 10 checks passed
@edmorley edmorley deleted the current_unix_time_ms-epochrealtime branch August 22, 2025 16:14
schneems added a commit to heroku/heroku-buildpack-ruby that referenced this pull request Aug 22, 2025
Inspired by heroku/heroku-buildpack-python#1881. This works locally and on Heroku. It works in bash, but not zsh by default (have to `zmodload zsh/datetime` to get it to work). We're explicitly using bash in these scripts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants