Skip to content

[SCB-1096]change the method calculate process cpu rate to same with top#1047

Merged
liubao68 merged 4 commits intoapache:masterfrom
heyile:htopMetrix
Jan 14, 2019
Merged

[SCB-1096]change the method calculate process cpu rate to same with top#1047
liubao68 merged 4 commits intoapache:masterfrom
heyile:htopMetrix

Conversation

@heyile
Copy link
Contributor

@heyile heyile commented Dec 28, 2018

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SCB-XXX] Fixes bug in ApproximateQuantiles, where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@coveralls
Copy link

coveralls commented Dec 28, 2018

Coverage Status

Coverage decreased (-0.1%) to 86.583% when pulling c6a1626 on heyile:htopMetrix into 5f618ab on apache:master.

@heyile heyile changed the title [SCB-1096]change the method to calculate process cpu rate same with htop [SCB-1096]change the method to calculate process cpu rate same with top Dec 30, 2018

public void update() {
String[] stats;
@SuppressWarnings("deprecation")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not use deprecated method, we can write a new one if no other available

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@heyile heyile changed the title [SCB-1096]change the method to calculate process cpu rate same with top [SCB-1096]change the method calculate process cpu rate to same with top Jan 8, 2019
long currentIdle = Long.parseLong(stats[4]);
idle.update(currentIdle);

long totalCpu = 0L;
Copy link
Contributor

Choose a reason for hiding this comment

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

1.delete useless empty lines.
2.why not just invoke CpuUtils.summary?

String[] stats = CpuUtils.readAndSplitFirstLine(PROC_STAT);
total.update(CpuUtils.summary(stats, 1, 8));
idle.update(Double.parseDouble(stats[4]));
super.updateUsage(total.period - idle.period, total.period, false);


public long getLastTotalTime() {
return lastTotalTime;
protected void updateUsage(double periodBusy, double periodTotal) {
Copy link
Contributor

Choose a reason for hiding this comment

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

move to parent class

  protected void updateUsage(double periodBusy, double periodTotal, boolean irixMode) {
    usage = periodTotal == 0 ? 0 : periodBusy / periodTotal;
    if (usage > 1) {
      usage = 1;
    }
    if (irixMode) {
      usage *= cpuCount;
    }
  }

long busy = 0L;
for (int i = 13; i <= 16; i++) {
busy += Long.parseLong(stats[i]);
protected void updateUsage(double periodBusy, double periodTotal) {
Copy link
Contributor

Choose a reason for hiding this comment

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

move to parent class

return name.substring(0, idx);
public void update() {
String[] stats = CpuUtils.readAndSplitFirstLine(CpuUtils.SELF_PROCESS);
String[] uptime = CpuUtils.readAndSplitFirstLine(CpuUtils.UPTIME);
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just invoke readUptimeTotal?

appendLine(sb, " cpu:");
appendLine(sb, " all: %.2f%% process: %.2f%%", allRate * 100, processRate * 100);
appendLine(sb, " all: %.2f%% process: %.2f%% idle: %.2f%%", allRate * 100, processRate * 100,
(1 - allRate) * 100);
Copy link
Contributor

Choose a reason for hiding this comment

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

appendLine(sb, " all usage: %.2f%% all idle: %.2%% process: %.2f%%", allRate * 100, (1 - allRate) * 100, processRate * 100);

@liubao68 liubao68 merged commit f601b62 into apache:master Jan 14, 2019
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