Skip to content

Conversation

@sczyh30
Copy link
Member

@sczyh30 sczyh30 commented Feb 21, 2020

Signed-off-by: Eric Zhao [email protected]

Describe what this PR does / why we need it

Add support for collecting CPU usage for SystemRule.

Does this pull request fix one issue?

NONE

Describe how you did it

Calculate the CPU usage:

  • u=user+nice, k=system+irq+sirq, total=u+k+idle+steal+iowait
  • usage=(udiff+kdiff)/tdiff, or 0 if tdiff=0
  • Unify value to [0.0, 1.0]

Describe how to verify it

Run the test cases and demo.

Special notes for reviews

NONE

@sczyh30 sczyh30 added the kind/enhancement Category issues or PRs related to enhancement label Feb 21, 2020
@sczyh30 sczyh30 added this to the 0.2.0 milestone Feb 21, 2020
@sczyh30 sczyh30 requested a review from louyuting February 21, 2020 03:13
}
}

func recordCpuUsage(prev, curCpuStat cpu.TimesStat) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In order to avoid struct copy, it might be better to use Pointer instead of struct here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. I've updated the code and added a stat.system.collectIntervalMs conf item. Please check.

Copy link
Collaborator

@louyuting louyuting left a comment

Choose a reason for hiding this comment

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

Thanks

@louyuting louyuting merged commit f806c59 into master Feb 22, 2020
@sczyh30 sczyh30 deleted the feature/system-cpu-stat branch February 22, 2020 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement Category issues or PRs related to enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants