Skip to content

Comments

Add CpuTimes and CpuPercent#28

Merged
borntyping merged 6 commits intorust-psutil:masterfrom
AdrienGaillard:cpu
Aug 1, 2018
Merged

Add CpuTimes and CpuPercent#28
borntyping merged 6 commits intorust-psutil:masterfrom
AdrienGaillard:cpu

Conversation

@AdrienGaillard
Copy link
Contributor

Adding some cpu features from psutil.

@AdrienGaillard
Copy link
Contributor Author

Any update on this issue ? Can I do something to help this PR to get merged ?

@borntyping
Copy link
Collaborator

I'll try and find some time to review this soon - there are a lot of changes here!

(In the future, it's probably best to make formatting changes to existing code in a separate PR, so that it's easy for reviewers to see what has been added.)

Copy link
Collaborator

@borntyping borntyping left a comment

Choose a reason for hiding this comment

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

I think this looks good. I've added a few comments in places where some minor cleanup is needed (mostly new() functions and repeated code).

@rkday, did you want to take a look at this too?

src/system.rs Outdated

impl CpuTimes {
/// Initialize CpuTimes struct
pub fn new(
Copy link
Collaborator

@borntyping borntyping Jul 31, 2018

Choose a reason for hiding this comment

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

I'm not sure this needs a new() method on the structs if the method does no additional processing. (Though I'm not very up to date on current standards.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it by coherence with the existing code but I didn't check that the existing new() methods had additional processing.

src/system.rs Outdated
if self.total_time() > past_cpu_times.total_time() {
let diff_total = (self.total_time() - past_cpu_times.total_time()) as f64;
CpuTimesPercent::new(
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

The blocks here seem to repeat multiple times, it may be worth using a function here to avoid repetition and make it easier to read.

src/system.rs Outdated
if fields.len() < 10 {
return Err(Error::new(
ErrorKind::InvalidData,
format!("Wrong format of /proc/stat line : {}, Maybe the kernel version is too older (Linux 2.6.33)", cpu_line),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be maybe the kernel version is too old.

src/system.rs Outdated
///
/// Use informations contains in '/proc/stat'
pub fn cpu_times_percent(interval: f64) -> Result<CpuTimesPercent> {
if interval <= 0. {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This block (line 908 to 918) gets used again in cpu_times_percent_percpu and should probably be moved into a private function.

@AdrienGaillard AdrienGaillard mentioned this pull request Aug 1, 2018
@borntyping
Copy link
Collaborator

Looks good - I merged #31 first and it's left some conflicts that need resolving but happy to merge after that.

@AdrienGaillard
Copy link
Contributor Author

Thanks! I just resolved the conflicts.

@borntyping borntyping merged commit 5cdef80 into rust-psutil:master Aug 1, 2018
@borntyping
Copy link
Collaborator

I'll try and look at the others soon - may be worth checking them for merge conflicts.

@AdrienGaillard AdrienGaillard deleted the cpu branch August 29, 2018 06:59
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