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

Error out when the given duration is negative #155

Merged
merged 2 commits into from
Nov 10, 2021

Conversation

el10savio
Copy link
Contributor

@el10savio el10savio commented Nov 10, 2021

Fixes: #154

Validate processInfo period & log a fatal error in the case of negative duration.

Now gops exits and returns a fatal error in the case when the user supplies a negative duration to gops <pid> <duration> instead of defaulting to 0 as shown below.

Previously:

$ gops 21794 -1.3s
parent PID:     21703
threads:        7
memory usage:   0.040%
cpu usage:      0.000%
username:       admin
cmd+args:       /tmp/go-build3005809368/b001/exe/main
elapsed time:   15:39
local/remote:   127.0.0.1:38793 <-> 0.0.0.0:0 (LISTEN)

Now:

$ go build && ./gops 21794 -1s  
2021/11/10 18:18:26 Cannot process with negative duration: -1s

Note:

In an attempt to validate the duration values, I skipped over validating floats as internally they get converted to the appropriate duration. for example 0.5s internally gets converted to 500ms

@google-cla
Copy link

google-cla bot commented Nov 10, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@el10savio
Copy link
Contributor Author

@googlebot I signed it!

@el10savio el10savio changed the title Exit gops when the given duration is negative Error out gops when the given duration is negative Nov 10, 2021
Copy link
Collaborator

@tklauser tklauser left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! One minor nit regarding the log message wording, otherwise LGTM.

main.go Outdated Show resolved Hide resolved
Co-authored-by: Tobias Klauser <tobias.klauser@gmail.com>
@el10savio el10savio changed the title Error out gops when the given duration is negative Error out when the given duration is negative Nov 10, 2021
@tklauser tklauser merged commit e6cb030 into google:master Nov 10, 2021
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.

gops does not validate time duration parameter
2 participants