It is currently March 29th, 2024, 10:32 am

How can I get around the 100% CPU usage on refresh?

Get help with creating, editing & fixing problems with skins
Cheese Chaos
Posts: 23
Joined: April 3rd, 2012, 1:25 am

How can I get around the 100% CPU usage on refresh?

Post by Cheese Chaos »

I've had a couple of issues with measures and their initial values in conjunction with mins and maxes. Whenever I monitored a measure with a line meter, it would load zeros across the meter then spike up to 100% right before displaying the measure's value. Because all the zeros were being sent to the meter, my MinValue would be overwritten. I eventually got around this by shifting the range I wanted down to zero, so the rewriting wouldn't affect my meter visually.

I'm currently stuck trying to record a max value on a meter monitoring cpu usage. Since the measure spikes up to 100% at the start, my max value is now 100%. Now no matter what values load into the meter, that 100% will not change.

Image

Here's the code related to the green items. (CPU Load shown in string and roundline meters)

Code: Select all

[CPU]
Measure=CPU
Processor=0

[Arc1]
Meter=Roundline
MeasureName=CPU
MeterStyle=StyleArc | StyleArc1 | StyleFGColor

[TextOuter]
Meter=String
MeterStyle=StyleText | StyleOuterText | StyleFGColor
MeasureName=CPU
Text="Load: %1%"
Percentual=1
Here's the code related to the blue items. (max CPU load shown in the meters)

Code: Select all

[CPUMax]
Measure=Calc
Formula=CPU > CPUMax ? CPU : CPUMax

[Arc1Max]
Meter=Roundline
MeasureName=CPUMax
MeterStyle=StyleArc | StyleArc1 | StyleArcMax

[TextOuterMax1]
Meter=String
MeterStyle=StyleText | StyleOuterMaxText
MeasureName=CPUMax
Text="%1%"
Percentual=1
How might I go about getting the CPU Load max? Is there a way to reset a variable after the meter has been loaded? It looks like Bangs could reset variables, but it seems to require cursor events. I'd rather not have to mouseover the meter every time it's refreshed to correct the max value. I guess one other thing I could do is use another plugin, but I'd like to avoid that if I can.
Last edited by Cheese Chaos on April 5th, 2012, 2:57 am, edited 3 times in total.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How can I get around the 100% CPU usage on refresh?

Post by jsmorley »

I would do something like this:

Code: Select all

[Rainmeter]
Update=1000

[MeasureDelayStart]
Measure=Calc
Formula=(MeasureDelayStart %1) + 1
IfEqualValue=1
IfEqualAction=!Execute [!EnableMeasureGroup Delayed][!DisableMeasure MeasureDelayStart]

[CPU]
Measure=CPU
Group=Delayed
Disabled=1

[CPUMax]
Measure=Calc
Group=Delayed
Formula=CPU > CPUMax ? CPU : CPUMax
Disabled=1

[MeterOne]
Meter=String
What this is doing is starting with the measures in question disabled. [MeasureDelayStart] then waits till the second "update" of the skin, enables the two measures and puts itself to sleep.

This will still "reset" the max cpu value on a refresh. But it will ignore that initial spike to 100% you get on the first update (when the value and the MaxValue are both zero, which is 100%). You will get only real values.
Cheese Chaos
Posts: 23
Joined: April 3rd, 2012, 1:25 am

Re: How can I get around the 100% CPU usage on refresh?

Post by Cheese Chaos »

Awesome. Thanks for the advice, jsmorley. I have yet to mess with counters or disabling parts of a skin, so I'll get to do some exploring in those areas while working on this skin.
Cheese Chaos
Posts: 23
Joined: April 3rd, 2012, 1:25 am

Re: How can I get around the 100% CPU usage on refresh?

Post by Cheese Chaos »

I think I may have been in a bit hasty in thinking I could solve this right away. When I was first putting in the MeasureDelayStart, I started wondering where I would call it from. Previously every measure was always tied to some meter or used in another measure. I just figured the measures sat there doing nothing until you used them.

After taking your code and playing around for a bit, I'm now thinking every measure is called every update. That means the MeasureDelayStart will work on its own. That would also explain why I kept getting errors in the past when some of my measures were incomplete and I refreshed the skin.

In the code you gave, I was curious about Formula=(MeasureDelayStart %1) + 1. I think that measures start out at zero, so that ends up being (0%1) + 1 on the first time through. The thing is, x%1 evaluates to zero for all values of x. The formula is basically just equal to 1. Because of this, I don't see the reason for the modulo. Maybe if it was Formula=(MeasureDelayStart %2) + 1, the measure could alternate between 1 and 2.

Whichever the case, my understanding is that the measure should delay the other measures by 1 update cycle.

Pre-submission Edit: Before posting again, I wanted to see if I could figure out what was going on. After adding the delay, I was still getting 100% on the roundline and string meters. After messing with the delay for a bit, I finally started looking at the rainmeter log. When looking at the measures in the log, I was surprised to see that the max value was no longer 100. Yet my meters were showing 100% still.

I was a bit slow to think of it, but I eventually considered the scaling. Sure enough, my values were between 0 to 100. I also had the string meter set with Percentual=1. Being that pretty but that entire range is greater than 1, it was easy to hit 100%. I then had to set the min and max value of the measure to match the range. So by correcting the scales and adding the 1 cycle delay to the measures, I have avoided the 100% hump in the beginning.

What we've learned today:
All measures are called at each update cycle (UpdateDivider can affect this).
Only the first update cycle of the CPU measure returns 100%.
Measures can be added to groups. Measures or groups of measures can be enabled/disabled by actions.
Counters can be useful to get different effects in the skin.
When dealing with percentages, make sure you know what the ranges are on the values (0.0-1.0 or 0-100).
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How can I get around the 100% CPU usage on refresh?

Post by jsmorley »

You are right, I'm so used to using counters that way that I overcomplicated it...

Code: Select all

[MeasureDelayStart]
Measure=Calc
Formula=1
IfEqualValue=1
IfEqualAction=!Execute [!EnableMeasureGroup Delayed][!DisableMeasure MeasureDelayStart]
Would work just as well. The formula is 0 when the skin is first loaded, then will be 1 on the next update and will fire the action. The result is the same as with that counter that was basically just counting from 1 to 1.. ;-)
Cheese Chaos
Posts: 23
Joined: April 3rd, 2012, 1:25 am

Re: How can I get around the 100% CPU usage on refresh?

Post by Cheese Chaos »

Hehe, all's well that ends well. Sometimes you've gotta throw curve balls at the newbies to keep them thinking. :p
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: How can I get around the 100% CPU usage on refresh?

Post by poiru »

jsmorley wrote:You are right, I'm so used to using counters that way that I overcomplicated it...
Here's an even simpler method.. ;)

Code: Select all

[Rainmeter]
OnRefreshAction=!Execute [!EnableMeasureGroup Delayed]

[CPU]
Measure=CPU
Group=Delayed
Disabled=1

[CPUMax]
Measure=Calc
Group=Delayed
Formula=CPU > CPUMax ? CPU : CPUMax
Disabled=1
(This works because OnRefreshAction is executed after the 0th update)
Last edited by jsmorley on April 7th, 2012, 12:06 pm, edited 1 time in total.