fix(cpu): Bad value for total load percentage
This commit is contained in:
parent
f573fcc531
commit
af6ef01ea6
@ -37,11 +37,14 @@ bool CpuModule::update()
|
|||||||
if (!this->read_values())
|
if (!this->read_values())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this->current_total_load = 0;
|
this->current_total_load = 0.0f;
|
||||||
this->current_load.clear();
|
this->current_load.clear();
|
||||||
|
|
||||||
int cores_n = this->cpu_times.size();
|
int cores_n = this->cpu_times.size();
|
||||||
|
|
||||||
|
if (cores_n == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
repeat(cores_n)
|
repeat(cores_n)
|
||||||
{
|
{
|
||||||
auto load = this->get_load(repeat_i_rev(cores_n));
|
auto load = this->get_load(repeat_i_rev(cores_n));
|
||||||
@ -49,9 +52,10 @@ bool CpuModule::update()
|
|||||||
this->current_load.emplace_back(load);
|
this->current_load.emplace_back(load);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->current_total_load = this->current_total_load / float(cores_n);
|
||||||
|
|
||||||
this->label_tokenized->text = this->label->text;
|
this->label_tokenized->text = this->label->text;
|
||||||
this->label_tokenized->replace_token("%percentage%",
|
this->label_tokenized->replace_token("%percentage%", std::to_string((int)(this->current_total_load + 0.5f)) +"%");
|
||||||
std::to_string((int) this->current_total_load / cores_n)+"%");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -61,14 +65,14 @@ bool CpuModule::build(Builder *builder, const std::string& tag)
|
|||||||
if (tag == TAG_LABEL)
|
if (tag == TAG_LABEL)
|
||||||
builder->node(this->label_tokenized);
|
builder->node(this->label_tokenized);
|
||||||
else if (tag == TAG_BAR_LOAD)
|
else if (tag == TAG_BAR_LOAD)
|
||||||
builder->node(this->bar_load, (int) this->current_total_load);
|
builder->node(this->bar_load, this->current_total_load);
|
||||||
else if (tag == TAG_RAMP_LOAD)
|
else if (tag == TAG_RAMP_LOAD)
|
||||||
builder->node(this->ramp_load, (int) this->current_total_load);
|
builder->node(this->ramp_load, this->current_total_load);
|
||||||
else if (tag == TAG_RAMP_LOAD_PER_CORE) {
|
else if (tag == TAG_RAMP_LOAD_PER_CORE) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto &&load : this->current_load) {
|
for (auto &&load : this->current_load) {
|
||||||
if (i++ > 0) builder->space(1);
|
if (i++ > 0) builder->space(1);
|
||||||
builder->node(this->ramp_load_per_core, (int) load);
|
builder->node(this->ramp_load_per_core, load);
|
||||||
}
|
}
|
||||||
builder->node(builder->flush());
|
builder->node(builder->flush());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user