Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Ensure that process.IOStat is non-nil #202

Merged
merged 1 commit into from
Nov 6, 2018

Conversation

kevinconaway
Copy link
Contributor

No description provided.

@kevinconaway kevinconaway requested a review from a team November 5, 2018 21:44
@@ -181,7 +181,7 @@ func formatIO(fp *process.FilledProcess, lastIO *process.IOCountersStat, before

diff := time.Now().Unix() - before.Unix()
if before.IsZero() || diff <= 0 {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we change the signature to return a non-pointer struct if we never return nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right or wrong, the current approach is consistent with formatMemory and formatCommand.

Whats the benefit on returning a non pointer?

Copy link
Contributor

Choose a reason for hiding this comment

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

The only benefit is that the compiler will force us to return a struct with zero-ed out fields instead of nil. Since we never return nil (and none of the callers handle nil returns) it feels off to allow it to be returned in the function signature.

However, going by https://stackoverflow.com/questions/23542989/pointers-vs-values-in-parameters-and-return-values it looks like pointers are recommended for "big structs" which IOStat is.

@kevinconaway kevinconaway merged commit 8d6cbed into master Nov 6, 2018
@kevinconaway kevinconaway deleted the kevinconaway/proc-iostat-non-nil branch November 6, 2018 19:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants