Skip to content
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

stat times decimals are off #5422

Closed
jdv opened this issue Oct 15, 2023 · 2 comments · Fixed by #5441
Closed

stat times decimals are off #5422

jdv opened this issue Oct 15, 2023 · 2 comments · Fixed by #5441

Comments

@jdv
Copy link
Collaborator

jdv commented Oct 15, 2023

The Problem

Decimal "stat" time values have mangled decimal portion.

Expected Behavior

The decimal portion to be exactly what the stat command kicks back.

Actual Behavior

The decimal portion is not exactly what the stat command kicks back.

Steps to Reproduce

jdv@jdv-lap:~$ cat test.raku

use nqp;

my $p = 'foo.txt'.IO;

qqx{touch $p.path()} unless $p.e;

qqx{stat $p.path()}.lines.grep(/^Mod/).say;

$p.modified.raku.say;

my $s := nqp::dispatch("boot-syscall", "file-stat", "foo.txt", 0);
my $m = nqp::dispatch(
"boot-syscall", "stat-time", $s, nqp::const::STAT_MODIFYTIME);
$m.raku.say;

jdv@jdv-lap:$ raku test.raku
(Modify: 2023-10-15 10:56:04.952796960 -0400)
Instant.from-posix(1697381764.952796928)
1697381764.952797e0
jdv@jdv-lap:
$

Environment

  • Operating system: debian 11
  • Compiler version (rakudo -v or raku -v): v2023.08-277-g9866e7a1f
@MasterDuke17
Copy link
Contributor

I believe this is "just" a num/float vs int problem (i.e., a difference in representation of the same underlying data, not incorrect data in the rakudo/moarvm case). "stat-time" returns a num (https://github.com/MoarVM/MoarVM/blob/main/src/disp/syscall.c#L1377) and I assume the stat command is printing the actual integer nanoseconds. Currently .modified() returns Instant.from-posix(nqp::dispatch("boot-syscall", "stat-time", $stat, nqp::const::STAT_MODIFYTIME)) (https://github.com/rakudo/rakudo/blob/main/src/core.c/IO/Path.rakumod#L964), but I wonder if instead it could do Instant.from-posix-nanos(nqp::dispatch("boot-syscall", "stat-time-int", $stat, nqp::const::STAT_MODIFYTIME)) (where stat-time-int is a new syscall that returns the seconds+nanoseconds, but as an int64 instead of a num)?

@MasterDuke17
Copy link
Contributor

A quick test confirms it.

[dan@alexandria perl6]$ re 'use nqp; my $stat := nqp::dispatch("boot-syscall", "file-stat", "words.txt", 0); say "num: " ~ "words.txt".IO.modified; say "int: " ~ Instant.from-posix-nanos(nqp::dispatch("boot-syscall", "stat-time-nanos", $stat, nqp::const::STAT_MODIFYTIME));'
num: Instant:1490550860.46225894
int: Instant:1490550823.462259075
[dan@alexandria perl6]$ stat words.txt | grep Modify
Modify: 2017-03-26 13:53:43.462259075 -0400
[dan@alexandria perl6]$

It's also quite a bit faster. Running Instant.from-posix(nqp::dispatch("boot-syscall", "stat-time", $stat, nqp::const::STAT_MODIFYTIME)) 100k times takes ~0.093s, but running Instant.from-posix-nanos(nqp::dispatch("boot-syscall", "stat-time-nanos", $stat, nqp::const::STAT_MODIFYTIME)) 100k times takes only ~0.029s.

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 a pull request may close this issue.

2 participants