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

Add swapdevices method #1120

Merged
merged 1 commit into from Sep 29, 2021
Merged

Add swapdevices method #1120

merged 1 commit into from Sep 29, 2021

Conversation

tbarker25
Copy link
Contributor

@tbarker25 tbarker25 commented Aug 18, 2021

Add a mem.SwapDevices() method to get swap stats per device. See #1115.

Unfortunately I could not find a way to implement this in Darwin, so I have left that as unimplemented.

Note that I have run these tests on the following OSs and verified that they passed: Linux, MacOS, FreeBSD, OpenBSD and Solaris.

@tbarker25 tbarker25 changed the title Add swapdevices method for Linux. Add swapdevices method Aug 19, 2021
@tbarker25 tbarker25 marked this pull request as ready for review August 19, 2021 14:11
Copy link
Owner

@shirou shirou 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 for your great contribution. LGTM, but I want to ask some of changes. Thanks!

}

func SwapDevicesWithContext(ctx context.Context) ([]*SwapDevice, error) {
output, err := exec.Command(swapCommand, "-lk").Output()
Copy link
Owner

Choose a reason for hiding this comment

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

Could you use exec.LookPath like here?

}

func SwapDevicesWithContext(ctx context.Context) ([]*SwapDevice, error) {
f, err := os.Open(swapsFilePath)
Copy link
Owner

Choose a reason for hiding this comment

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

Could you change to common.HostProc("swaps") like here? It can enable to run on container environment.

}

func SwapDevicesWithContext(ctx context.Context) ([]*SwapDevice, error) {
output, err := exec.Command(swapsCommand, "-l").Output()
Copy link
Owner

Choose a reason for hiding this comment

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

same here, please use exec.LookPath.

@punya
Copy link
Contributor

punya commented Sep 8, 2021

Hi @shirou. I work with @tbarker25 and am continuing his work in #1131 (because he will be away from work for the next several weeks). I've incorporated your feedback in that PR, please let me know if you're okay with merging it.

shirou added a commit that referenced this pull request Sep 29, 2021
Add swapdevices method (continued from #1120)
@shirou shirou merged commit 84a665b into shirou:master Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants