-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Implement time
#141
Implement time
#141
Conversation
This comment has been minimized.
This comment has been minimized.
e283304
to
b8ccc8a
Compare
Sorry, but could you change the commit messages to use the project standard commit message style, I decided on this standard because the project is a workspace crate of several other crates, so it's hard to know what commit is related to what crate. Formatting is using nightly because several features in the rustfmt are still as unstable feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments for us to talk.
I feel that rusage.rs
could be a module in the coreutils_core crate, but that can be done at any time, even in another PR.
time/Cargo.toml
Outdated
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap = { version = "^2.33.0", features = ["yaml", "wrap_help"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you're using yaml feature of clap. We dropped that due some problems with it. You can find the template used now here
Cargo.toml
Outdated
@@ -22,4 +22,5 @@ members = [ | |||
"tty", | |||
"wc", | |||
"yes", | |||
"time", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add this to all toml files related to the OS that this utility can be compiled? The reason behind this is because no all OS works the same, and sometimes (like fuchsia and haiku) doesn't even has a way to do something. The CI also uses the toml files os respective OS to build and test the crates
time/src/rusage.rs
Outdated
let seconds = u64::try_from(tv.tv_sec).expect("Unable to convert tv_sec to u64"); | ||
let micros = u64::try_from(tv.tv_usec).expect("Unable to convert tv_usec to u64"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is any case where this conversion will fail? Because panic exit with a different message than the tools messages.
Or is it the case where failing to convert in any OS with this tool should be considered a bug in the utility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't expect the conversion to fail, since libc::getrusage
won't return negative values for the timeval struct.
The latter is true. I would think it's a bug in time
, since this is an implementation detail.
Because panic exit with a different message than the tools messages
I'm not sure I follow, this message corresponds to an internal error, if that helps clarify my usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't expect the conversion to fail, since
libc::getrusage
won't return negative values for the timeval struct.The latter is true. I would think it's a bug in
time
, since this is an implementation detail.
In this case panic is fine
I'm not sure I follow, this message corresponds to an internal error, if that helps clarify my usage.
I was just worried that panic exit may happen in a non-bug case where the error message should be similar to user error messages like the other tools
85b4688
to
0fb3819
Compare
1b13de4
to
089004d
Compare
A few questions:
|
6002e6f
to
61d4f86
Compare
- Initial structure taken from .template with tool specific info filled in
- Wraps getrusage(2)
No longer use number_of_values(true) as that implies an option Also use "ARGUMENT" to match from clap
- Refactor enum declaration to use `Self` - Add test cases for `TimeOpts` creation - Rename 'OutputFormat' to 'OutputFormatter'
Unspecified errors are arbitrarily mapped to the 1-125 range
Returns a zeroed RUsage struct
Yes, if is something required to support POSIX standard. We have this many toml files for 2 reasons
That is totally fine, in most tools we only require for POSIX compliance to consider the tool complete, and extensions, being OS specific or a available on all OSes, are greatly accepted additions
That's odd, It is working fine for me just doing |
Gotcha, it's been commented out of
Great, thanks! I'll make an issue with the TODO items from this PR, and set up machinery for platform extensions in a follow-up PR.
Are you using an ubuntu/debian machine? Also, I think the build is failing because it seems there is a crate called |
Yes 😄
That's great to hear, we're always happy to receive contributions 😄
I use Manjaro, it is Arch-based
Yes, it's the crate we use to handle time in some other tools. It's a possible segfault by using a non-thread-safe function call on UNIX platforms, but since for now all tools are single threaded, it's fine (for now). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the from function that should be a From
impl, the only other thing that caught my attention are the public fields of the structs in coreutils_core::os::resource
considering that coreutils_core is suppose to be of a medium to high level of API abstraction for the raw API used to implement the utilities, so the access to the field is suppose to be done using functions that return references to the fields, but I think that is kinda of a big change that can be addressed in another PR.
Besides that, nothing else seems out of place.
coreutils_core/src/os/resource.rs
Outdated
impl RUsage { | ||
fn from(ru: rusage) -> Self { | ||
RUsage { | ||
timing: Timing { user_time: ru.ru_utime, sys_time: ru.ru_stime }, | ||
mem: MemoryUsage { | ||
max_rss: ru.ru_maxrss as u64, | ||
num_minor_page_flt: ru.ru_minflt as u64, | ||
num_major_page_flt: ru.ru_majflt as u64, | ||
num_vol_ctx_switch: ru.ru_nvcsw as u64, | ||
num_invol_ctx_switch: ru.ru_nivcsw as u64, | ||
shared_mem_size: ru.ru_ixrss as u64, | ||
unshared_data_size: ru.ru_idrss as u64, | ||
unshared_stack_size: ru.ru_isrss as u64, | ||
num_swaps: ru.ru_nswap as u64, | ||
}, | ||
io: IOUsage { | ||
num_block_in: ru.ru_inblock as u64, | ||
num_block_out: ru.ru_oublock as u64, | ||
num_sock_recv: ru.ru_msgrcv as u64, | ||
num_sock_send: ru.ru_msgsnd as u64, | ||
num_signals: ru.ru_nsignals as u64, | ||
}, | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be better as a impl From<rusage> for RUsage
I see, I was considering implementing functions for "derived" properties (per GNU time's Ack on implementing the |
coreutils_core/src/os/resource.rs
Outdated
@@ -6,6 +6,8 @@ use super::TimeVal; | |||
use libc::getrusage; | |||
use libc::{c_int, rusage, RUSAGE_CHILDREN, RUSAGE_SELF}; | |||
|
|||
use std::convert::From; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From is in the Rust prelude, so you don't need to pull it into the scope
That depends, I personally think about the contract I want with the library usage. For example, in the But since in this case all possible fields are |
This test is truly arbitrary and more of a benchmark than a test
bors r+ |
This PR will track building
time
Partially fixes #53