It is currently April 23rd, 2024, 7:27 pm

Calc measure conditional, meter not showing value

Get help with creating, editing & fixing problems with skins
User avatar
InterClaw
Posts: 24
Joined: March 30th, 2022, 5:31 pm
Location: Sweden

Calc measure conditional, meter not showing value

Post by InterClaw »

I'm having a problem with a conditional in a calc measure and the meter not showing the result. Not sure what I'm doing wrong here, but hopefully somebody can help me out and point out the problem here.

A little background on what the skin is about if you're interested:
I want a truer visualization of CPU usage on hyperthreaded cores. I have a bar that represents the usage of a physical core. The bar has two segments though, which represent the load on the two threads running on the core. The top part of the bar is white and the bottom part is gray.
  • If both threads are loaded at 100%, then the bar should be half white and half gray. You're not getting 200% performance from the core. You're sharing the processing power 50/50 between the threads (disregarding any performance benefits that hyperthreading brings). Windows still reports it as 100% on each thread and this is what I don't like. 100% on one thread means different things depending on what's happening in the other thread.
  • If only one thread is loaded to 100% and the other idle, then the bar is all white, since you're getting all the performance of the core to that one thread.
  • And in a situation where one thread is at 100% and the other is at, say, 30%, then I want the bar to be 30 / (100 + 30) ≈ 23% gray and the rest of it white, since that is roughly how the performance you're getting is being split.
  • If neither thread is fully loaded, say 90% and 30%, then the math becomes 30 / (90 + 30) = 25% gray and the rest white, so still sharing the performance of the core, since the sum is over 100%.
  • And if the sum of the threads does not amount to 100%, say 50% and 30%, then the bar is simply 30% gray, 50% white, and 20% transparent.
So I'm trying to draw a gray bar partially over a white bar. The length of the gray bar I'm trying to determine using this formula:
Formula=(measureCore01Sum>100?measureCPU[&measureCore01Low]/measureCore01Sum:measureCPU[&measureCore01Low])

The problem is that if [measureCore01Sum] is greater than 100, then the gray bar is not drawn at all, so I'm not sure if there's something wrong with the resulting value of [measureCore01LowValue] due to a mistake in the formula, or if this is more of a problem with updating the skin. You can see I've tried to resolve it by adding FinishAction=[!UpdateMeter meterCore01Low][!Redraw]. I suspect a syntactical error in the conditional though.

Any ideas on how I can resolve this?

Here's what I have so far:

Code: Select all

[Rainmeter]
Update=1000
DefaultUpdateDivider=2
AccurateText=1
DynamicWindowSize=0
SkinWidth=122
BackGroundMode=1

[Variables]
@Include=#PROGRAMPATH#\Skins\HWiNFO\@Resources\HWiNFO.inc

[styleLongBar]
DynamicVariables=1
W=3
H=27

; Four CPU threads on remote computer.
; CPU0/CPU1 are on the first physical core and CPU2/CPU3 on the second.
[measureCPU0]
Measure=Plugin
Plugin=HWiNFO.dll
HWiNFOHostId=#HWiNFO-RemoteHost0#
HWiNFOSensorId=#HWiNFO-RemoteHost0-CPU0-SensorId#
HWiNFOSensorInstance=#HWiNFO-RemoteHost0-CPU0-SensorInstance#
HWiNFOEntryId=#HWiNFO-RemoteHost0-CPU0-Core0#
HWiNFOType=CurrentValue
HWiNFOLogHandler=0
MinValue=0
MaxValue=100

[measureCPU1]
Measure=Plugin
Plugin=HWiNFO.dll
HWiNFOHostId=#HWiNFO-RemoteHost0#
HWiNFOSensorId=#HWiNFO-RemoteHost0-CPU0-SensorId#
HWiNFOSensorInstance=#HWiNFO-RemoteHost0-CPU0-SensorInstance#
HWiNFOEntryId=#HWiNFO-RemoteHost0-CPU0-Core1#
HWiNFOType=CurrentValue
HWiNFOLogHandler=0
MinValue=0
MaxValue=100

[measureCPU2]
Measure=Plugin
Plugin=HWiNFO.dll
HWiNFOHostId=#HWiNFO-RemoteHost0#
HWiNFOSensorId=#HWiNFO-RemoteHost0-CPU0-SensorId#
HWiNFOSensorInstance=#HWiNFO-RemoteHost0-CPU0-SensorInstance#
HWiNFOEntryId=#HWiNFO-RemoteHost0-CPU0-Core2#
HWiNFOType=CurrentValue
HWiNFOLogHandler=0
MinValue=0
MaxValue=100

[measureCPU3]
Measure=Plugin
Plugin=HWiNFO.dll
HWiNFOHostId=#HWiNFO-RemoteHost0#
HWiNFOSensorId=#HWiNFO-RemoteHost0-CPU0-SensorId#
HWiNFOSensorInstance=#HWiNFO-RemoteHost0-CPU0-SensorInstance#
HWiNFOEntryId=#HWiNFO-RemoteHost0-CPU0-Core3#
HWiNFOType=CurrentValue
HWiNFOLogHandler=0
MinValue=0
MaxValue=100



; Core01

; Determine which of the two threads is least utilized.
; This is done to pick which thread to draw in gray, 
; since I want the bar to be mostly white.
[measureCore01Low]
Measure=Calc
Formula=(measureCPU0<measureCPU1?0:1)
DynamicVariables=1

; The sum of the two threads on one physical core.
; Up to 200%.
; Capping the value to 100% though.
[measureCore01Sum]
Measure=Calc
Formula=measureCPU0+measureCPU1
MinValue=0
MaxValue=100
DynamicVariables=1

; What value to set on the lower, gray bar for the less utilized thread.
; If the core is over 100% loaded in total, then the value should be a fraction of the sum of both threads.
; Otherwise, just the measured value of the thread.
[measureCore01LowValue]
Measure=Calc
Formula=(measureCore01Sum>100?measureCPU[&measureCore01Low]/measureCore01Sum:measureCPU[&measureCore01Low])
MinValue=0
MaxValue=100
DynamicVariables=1
FinishAction=[!UpdateMeter meterCore01Low][!Redraw]

; This is the white bar, technically showing the sum of both threads, capped at 100%.
; Gets partially occluded by the gray bar below though, 
; so the visible part of the white bar represents the part of the core's performance 
; utilized by the thread with the higher load.
[meterCore01High]
Meter=Bar
MeterStyle=styleLongBar
MeasureName=measureCore01Sum
BarColor=255,255,255,255
X=69
Y=7

; The gray bar, drawn on top of the white bar.
; Shows the utlization of the least utilized thread of the core.
; Occludes the same amount that it contributes with to the white bar underneath.
[meterCore01Low]
Meter=Bar
MeterStyle=styleLongBar
MeasureName=measureCore01LowValue
BarColor=192,192,192,255
X=0r
Y=0r



; Core02

; This core "works" in the sense that it always shows the gray bar.
; It has a bug though in that the gray bar will be too long, 
; since it doesn't take into account that the gray bar needs 
; to be shorter when the sum is greater than 100%. This core 
; doesn't adjust the gray bar's value.
; For example, if both threads are at 100%, then the gray bar 
; is at 100% and fully occludes the white bar underneath, 
; which is not the intended behavior.

[measureCore02Low]
Measure=Calc
Formula=(measureCPU2<measureCPU3?2:3)
DynamicVariables=1

[measureCore02Sum]
Measure=Calc
Formula=measureCPU2+measureCPU3
MinValue=0
MaxValue=100
DynamicVariables=1

[meterCore02High]
Meter=Bar
MeterStyle=styleLongBar
MeasureName=measureCore02Sum
BarColor=255,255,255,255
X=1R
Y=0r

[meterCore02Low]
Meter=Bar
MeterStyle=styleLongBar
MeasureName=measureCPU[&measureCore02Low]
BarColor=192,192,192,255
X=0r
Y=0r
User avatar
CodeCode
Posts: 1365
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Calc measure conditional, meter not showing value

Post by CodeCode »

You can try putting AutoScale=1 in the text meter.

Since you have made the maxvalue to be 100 the conditional will not work on that measure, for higher values.

So AutoScale will ensure the total value however higher than 100 will remain in the range of the conditional. (or should, I think).
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Calc measure conditional, meter not showing value

Post by balala »

InterClaw wrote: April 15th, 2022, 4:21 pm So I'm trying to draw a gray bar partially over a white bar. The length of the gray bar I'm trying to determine using this formula:
Formula=(measureCore01Sum>100?measureCPU[&measureCore01Low]/measureCore01Sum:measureCPU[&measureCore01Low])

The problem is that if [measureCore01Sum] is greater than 100, then the gray bar is not drawn at all, so I'm not sure if there's something wrong with the resulting value of [measureCore01LowValue] due to a mistake in the formula,
Sorry for the extremely late reply. Yep I know four days gone by since you've posted your question, but if you still are interested...
There definitely is a small mistake in the formula. In fact there is no formula. I mean that what do you want to achieve with for instance something like this: measureCPU[&measureCore01Low]? I think you want to concatenate the values of those measures ([measureCPU] and [measureCore01Low]), but am I right? In any case you can't simply put together measures, because a Formula option of a Calc measure (as well as an IfCondition) has to be entirely numeric. Joining those measures (or their names) is not a mathematical operation, you can't use this in a Formula option.
So question is what you want to achieve?
User avatar
InterClaw
Posts: 24
Joined: March 30th, 2022, 5:31 pm
Location: Sweden

Re: Calc measure conditional, meter not showing value

Post by InterClaw »

CodeCode wrote: April 18th, 2022, 10:35 am You can try putting AutoScale=1 in the text meter.

Since you have made the maxvalue to be 100 the conditional will not work on that measure, for higher values.

So AutoScale will ensure the total value however higher than 100 will remain in the range of the conditional. (or should, I think).
I'm sorry, but I'm not sure where you're suggesting I put AutoScale=1. I only have two bar meters, no text meter. Is it in one of the measures you mean?
User avatar
InterClaw
Posts: 24
Joined: March 30th, 2022, 5:31 pm
Location: Sweden

Re: Calc measure conditional, meter not showing value

Post by InterClaw »

balala wrote: April 19th, 2022, 7:37 pm Sorry for the extremely late reply. Yep I know four days gone by since you've posted your question, but if you still are interested...
I most definitely am. :)
balala wrote: April 19th, 2022, 7:37 pm There definitely is a small mistake in the formula. In fact there is no formula. I mean that what do you want to achieve with for instance something like this: measureCPU[&measureCore01Low]? I think you want to concatenate the values of those measures ([measureCPU] and [measureCore01Low]), but am I right? In any case you can't simply put together measures, because a Formula option of a Calc measure (as well as an IfCondition) has to be entirely numeric. Joining those measures (or their names) is not a mathematical operation, you can't use this in a Formula option.
So question is what you want to achieve?
Don't want to concatenate the values. [measureCore01Low] returns either 0 or 1, depending on which thread is least utilized on the physical core. Like this:

Code: Select all

[measureCore01Low]
Measure=Calc
Formula=(measureCPU0<measureCPU1?0:1)
DynamicVariables=1
(If they're exactly equal it doesn't really matter what it returns. With the formula above it will return 1. Fine, whatever)

Let's say [measureCPU0] = 30 and [measureCPU1] = 50. [measureCore01Low] is then 0, indicating that thread 0 is least utilized at the moment. Why am I doing this? I want the value coming from the least utilized thread to be used for the height of the gray bar overlaying the white bar. I'm faking having a segmented singular bar by actually having two bars drawn on top of each other. :oops:


So what I'm doing with measureCPU[&measureCore01Low] in the main formula is to dynamically refer to either [measureCPU0] or [measureCPU1] so I know what value to draw for the gray bar.

Meanwhile, the underlying white bar is simple. It just draws the sum ([measureCore01Sum]) of the two threads. In our example it's just 80, so it will draw an 80% full white bar. If the sum exceeds 100, then it doesn't matter; It can only draw a 100% full white bar. Doesn't matter if the sum is 150 or 200 etc. Ez.


The problem comes with the sum being greater than 100 and what to then draw for the gray bar. Let's adjust our example to [measureCPU0] = 30 and [measureCPU1] = 100 instead. [measureCore01Low] is still 0, so the gray bar will be drawing a value based on what thread 0 is doing.

However, the "30%" that Windows is reporting for that thread is no longer actually the same as what the 30% was in the first example. Since both threads share the core, you can't get "130%" of performance out of it (disregarding performance benefits of hyperthreading here). In reality, the performance you're getting out of thread 0 is more like 30 / (30 + 100) = 30 / 130 ≈ 23%.

So the gray bar should not be drawing 30%, it should be drawing 23%. This is what I'm trying to achieve with the main formula:
Formula=(measureCore01Sum>100?measureCPU[&measureCore01Low]/measureCore01Sum:measureCPU[&measureCore01Low])
So when [measureCore01Sum] is more than 100, then I should take either [measureCPU0] (30) or [measureCPU1] (100) and divide it by [measureCore01Sum] (130) to get the actual percentage to illustrate on the gray bar for the lower thread. Since [measureCore01Low] is 0 it will be the value of [measureCPU0] (30) to be divided by [measureCore01Sum] (130).


... and in the case of both threads being fully utilized and reporting "100%", then the white bar will be drawn as 100% full (even though [measureCore01Sum] is 200). The gray bar on top of it will be half full at 50%, since [measureCPU1] (100) divided by [measureCore01Sum] (200) = 50%. Meaning, the gray bar can never be taller than 50%. And having my "fake", composite bar showing as 50% gray and 50% white paints a truer picture of what's actually going on in that physical core, than what the "200%" utilization that Windows tells me does. :phhht


I hope that explains what I'm trying to do here! I think my logic is sound, but I'm having some sort of problem with the formula, because when the sum is more than 100, then the gray bar is suddenly not drawn at all, but below 100 the gray bar works fine.
User avatar
CodeCode
Posts: 1365
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Calc measure conditional, meter not showing value

Post by CodeCode »

InterClaw wrote: April 20th, 2022, 8:47 pm I'm sorry, but I'm not sure where you're suggesting I put AutoScale=1. I only have two bar meters, no text meter. Is it in one of the measures you mean?
AutyoScale would then go in the bar meter.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
InterClaw
Posts: 24
Joined: March 30th, 2022, 5:31 pm
Location: Sweden

Re: Calc measure conditional, meter not showing value

Post by InterClaw »

CodeCode wrote: April 21st, 2022, 12:45 am AutyoScale would then go in the bar meter.
Did this, but it doesn't seem to help. :/ Still no gray bar when above 100% total for the core.

Code: Select all

[meterCore02Low]
Meter=Bar
MeterStyle=styleLongBar
MeasureName=measureCPU[&measureCore02Low]
BarColor=192,192,192,255
X=0r
Y=0r
AutoScale=1
User avatar
SilverAzide
Rainmeter Sage
Posts: 2604
Joined: March 23rd, 2015, 5:26 pm

Re: Calc measure conditional, meter not showing value

Post by SilverAzide »

InterClaw wrote: April 21st, 2022, 5:40 pm Did this, but it doesn't seem to help. :/ Still no gray bar when above 100% total for the core.

Code: Select all

[meterCore02Low]
Meter=Bar
MeterStyle=styleLongBar
MeasureName=measureCPU[&measureCore02Low]
BarColor=192,192,192,255
X=0r
Y=0r
AutoScale=1
I suspect you are going to need DynamicVariables=1 on that meter... (You've added that to a bunch of measures elsewhere that probably don't need it.)
Gadgets Wiki GitHub More Gadgets...
User avatar
InterClaw
Posts: 24
Joined: March 30th, 2022, 5:31 pm
Location: Sweden

Re: Calc measure conditional, meter not showing value

Post by InterClaw »

SilverAzide wrote: April 21st, 2022, 6:14 pm I suspect you are going to need DynamicVariables=1 on that meter... (You've added that to a bunch of measures elsewhere that probably don't need it.)
Tried it like this. Still nothing I'm afraid. :/ Thanks for the suggestions though! Keep 'em coming! :D

Code: Select all

[meterCore02Low]
Meter=Bar
MeterStyle=styleLongBar
MeasureName=measureCPU[&measureCore02Low]
BarColor=192,192,192,255
X=0r
Y=0r
AutoScale=1
DynamicVariables=1
User avatar
InterClaw
Posts: 24
Joined: March 30th, 2022, 5:31 pm
Location: Sweden

Re: Calc measure conditional, meter not showing value

Post by InterClaw »

I was updating the wrong meter! This is the one to update.

Code: Select all

[meterCore01Low]
Meter=Bar
MeterStyle=styleLongBar
MeasureName=measureCore01LowValue
BarColor=192,192,192,255
X=0r
Y=0r
AutoScale=1
DynamicVariables=1
But unfortunately neither AutoScale=1 nor DynamicVariables=1 helped.