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

Enable parsing of '/proc/[pid]/mountstats' #30

Merged
merged 1 commit into from
Dec 6, 2016
Merged

Enable parsing of '/proc/[pid]/mountstats' #30

merged 1 commit into from
Dec 6, 2016

Conversation

mdlayher
Copy link
Contributor

@mdlayher mdlayher commented Nov 29, 2016

Tested on my system using NFS mounts from my desktop to server. Reduced some of the per-operation stats in the fixture to save time. Kernel is 3.13.0-37.

@mdlayher
Copy link
Contributor Author

Is it okay to make use of subtests now that Go 1.7 is out? Regarding the CI failure. Could update CI to Go 1.7.

@beorn7
Copy link
Member

beorn7 commented Dec 1, 2016

About the Go 1.7 features: This is a library, so we can expect it to be used in certain contexts where older Go compilers are used. Thus, I'd shy away from using Go-1.7 features if I can avoid it.
(Travis should also test with Go 1.7, but we should keep 1.6 (and probably 1.5) for a while.)

@SuperQ @brian-brazil Is this PR doing what you discussed in prometheus/node_exporter#108 ?

@grobie as you are the maintainer of this repo, could you signal if you are able/unable to review this?

Thanks everybody.

@SuperQ
Copy link
Member

SuperQ commented Dec 1, 2016

@beorn7 Yes, it looks OK to me for prometheus/node_exporter#108

@mdlayher
Copy link
Contributor Author

mdlayher commented Dec 1, 2016

@beorn7 Updated to remove subtests. It appears there is a failure unrelated to my change in CI for Go 1.5.

@grobie
Copy link
Member

grobie commented Dec 1, 2016 via email

@mdlayher
Copy link
Contributor Author

mdlayher commented Dec 5, 2016

Hey @grobie, any chance you can look this over soon?

fieldTransport11Len = 13
)

// A Mount is a device mount parsed from /proc/[pid]mountstats.
Copy link
Member

Choose a reason for hiding this comment

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

TIL (with optional leading article) is a thing now.

Copy link
Member

@grobie grobie left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you @mdlayher and sorry for the late review (/me waves from Mexico City).

I added a couple of questions and a few nits, but nothing serious really. Julius added a warning about the unstable API, so if anything comes up we're not in a bad situation anyway.

fieldTransport11Len = 13
)

// A Mount is a device mount parsed from /proc/[pid]mountstats.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Missing slash after [pid].

@@ -192,6 +192,18 @@ func (p Proc) FileDescriptorsLen() (int, error) {
return len(fds), nil
}

// MountStats retrieves statistics and configuration for mount points in a
// process's name space.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Isn't namespace one word?


// Does this mount also possess statistics information?
if len(ss) > deviceEntryLen {
// Only NFSv3 and v4 are supported for parsing statistics
Copy link
Member

Choose a reason for hiding this comment

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

Do you know other possible types providing statistics? I wonder if we should just leave Stats empty in this case, but being explicit is probably the right decision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The manpage mentions:

              (4)  Optional  statistics  and configuration information.  Currently (as at Linux 2.6.26), only NFS filesystems export information
                   via this field.

So as far as I can tell, no other filesystem type exposes statistics here.


// Check for specific words appearing at specific indices to ensure
// the format is consistent with what we expect
format := []struct {
Copy link
Member

Choose a reason for hiding this comment

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

What do you think, would it make sense to extract this struct to a global variable in order to not rebuild it on function invocation? Or is the compiler already smart enough to do that for us?

Have you thought about using fmt.Scanf here?

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'll make some benchmarks for this logic and see which approach is fastest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://gist.github.com/mdlayher/0e5db14dd6a2468bab343f2890d499d4

According to these results, moving this to a package variable results in about a 2 nanosecond savings per run. fmt.Sscanf() is nowhere near competitive.

My gut tells me that the very slight speedup is not worth adding a variable used in a single function to the package namespace, but I'd be okay with changing it if requested.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, thanks for checking.

@mdlayher
Copy link
Contributor Author

mdlayher commented Dec 6, 2016

Will rebase this once #31 is merged.

@grobie
Copy link
Member

grobie commented Dec 6, 2016

Thanks! Given the build error is fixed already in master, in going to merge it.

@grobie
Copy link
Member

grobie commented Dec 6, 2016

Pull requests that have a failing status can’t be merged on a phone.

Well, or not.

@mdlayher
Copy link
Contributor Author

mdlayher commented Dec 6, 2016

@grobie all fixed!

@grobie
Copy link
Member

grobie commented Dec 6, 2016

Thanks again!

@grobie grobie merged commit fcdb11c into prometheus:master Dec 6, 2016
@mdlayher mdlayher deleted the mountstats branch December 7, 2016 07:54
bobrik pushed a commit to bobrik/procfs that referenced this pull request Jan 14, 2023
Use `c_char`, which is the proper alias to use with `CStr`
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.

4 participants