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

gops does not validate time duration parameter #154

Closed
el10savio opened this issue Nov 9, 2021 · 2 comments · Fixed by #155
Closed

gops does not validate time duration parameter #154

el10savio opened this issue Nov 9, 2021 · 2 comments · Fixed by #155

Comments

@el10savio
Copy link
Contributor

el10savio commented Nov 9, 2021

It looks like gops does not validate the input time duration parameter & defaults to 0 for invalid inputs. When testing out the hello world example adding values such as 0,-1,1.2,.. defaults to 0 and does not return an error as shown below.

$ gops 24966 3
parent PID:     24876                                        
threads:        6                                     
memory usage:   0.039%
cpu usage:      0.000%
cpu usage (3s): 0.000%
username:       admin
cmd+args:       /tmp/go-build400100092/b001/exe/main
elapsed time:   08:04
local/remote:   127.0.0.1:34409 <-> 0.0.0.0:0 (LISTEN)
$ gops 24966 0
parent PID:     24876
threads:        6
memory usage:   0.039%
cpu usage:      0.000%
username:       admin
cmd+args:       /tmp/go-build400100092/b001/exe/main
elapsed time:   08:06
local/remote:   127.0.0.1:34409 <-> 0.0.0.0:0 (LISTEN)
$ gops 24966 0.5
parent PID:     24876
threads:        6
memory usage:   0.039%
cpu usage:      0.000%
username:       admin
cmd+args:       /tmp/go-build400100092/b001/exe/main
elapsed time:   08:10
local/remote:   127.0.0.1:34409 <-> 0.0.0.0:0 (LISTEN)
$ gops 24966 1.2
parent PID:     24876
threads:        6
memory usage:   0.039%
cpu usage:      0.000%
username:       admin
cmd+args:       /tmp/go-build400100092/b001/exe/main
elapsed time:   08:19
local/remote:   127.0.0.1:34409 <-> 0.0.0.0:0 (LISTEN)
$ gops 24966 -7
parent PID:     24876
threads:        6
memory usage:   0.039%
cpu usage:      0.000%
username:       admin
cmd+args:       /tmp/go-build400100092/b001/exe/main
elapsed time:   08:26
local/remote:   127.0.0.1:34409 <-> 0.0.0.0:0 (LISTEN)

This is a very minor issue but would be helpful to fix to validate the user's input. It looks like this line here is not validating the returned values from period, err = time.ParseDuration(os.Args[2])

var period time.Duration
if len(os.Args) >= 3 {
	period, err = time.ParseDuration(os.Args[2])
	if err != nil {
		secs, _ := strconv.Atoi(os.Args[2])
		period = time.Duration(secs) * time.Second
	}
}
@tklauser
Copy link
Collaborator

@el10savio thanks for the report. I think it'd make sense to fix this. Want to open a PR?

@el10savio
Copy link
Contributor Author

Thanks @tklauser. Sure, I can pick it up :)

tklauser added a commit that referenced this issue Jul 7, 2022
The change in #154 lead to the CPU usage being reported for a 0s
duration:

cpu usage (0s):	NaN%

Fix this by only reporting CPU usage per period if the user specified a
positive duration.
tklauser added a commit that referenced this issue Jul 7, 2022
The change in #154 lead to the CPU usage being reported for a 0s
duration:

cpu usage (0s):	NaN%

Fix this by only reporting CPU usage per period if the user specified a
positive duration.
tklauser added a commit that referenced this issue Jul 8, 2022
The change in #154 lead to the CPU usage being reported for a 0s
duration:

cpu usage (0s):	NaN%

Fix this by only reporting CPU usage per period if the user specified a
positive duration.
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 a pull request may close this issue.

2 participants