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

High cpu on unoptimized code in process package #1343

Closed
1 task done
gnud opened this issue Aug 19, 2022 · 1 comment
Closed
1 task done

High cpu on unoptimized code in process package #1343

gnud opened this issue Aug 19, 2022 · 1 comment

Comments

@gnud
Copy link

gnud commented Aug 19, 2022

Describe the bug
I am going to produce process monitoring app to find which process is increasing the temperature, but I ended up producing high cpu (over 80%), can this be optimized to run in realtime and not produce much cpu?

To Reproduce

	processes, err := process.Processes()
	if err != nil {
		return
	}

	for true {
		time.Sleep(1000 * 5)

		for _, _process := range processes {
			var totalCpu, _ = _process.CPUPercent()
			if totalCpu < 30 {
				continue
			}

			fmt.Printf(
				"%d,%s,%f\n",
				_process.Pid,
				getOne(_process.Name()),
				getOne(_process.CPUPercent()),
			)
		}
	}

Expected behavior
Smooth realtime recording/printing.

Environment (please complete the following information):

Linux damjan 5.4.0-42-generic #46~18.04.1-Ubuntu SMP Fri Jul 10 07:21:24 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

@Lomanic Lomanic changed the title High cpu on unoptimized code High cpu on unoptimized code in process package Oct 23, 2022
@Lomanic
Copy link
Collaborator

Lomanic commented Oct 23, 2022

This is a duplicate of #842, #1283 and #1070

@Lomanic Lomanic closed this as completed Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants