It is currently March 28th, 2024, 3:40 pm

problem hiding not existing cores per CPU measure

Get help with creating, editing & fixing problems with skins
Yue
Posts: 59
Joined: March 23rd, 2023, 1:10 pm

problem hiding not existing cores per CPU measure

Post by Yue »

Hi!

I tried to rework my code using new gained knowledge but hit a [this time] simple problem. I created measures and meters for n cores. The intention is to automatically only show as many as exist. The idea is to check if the value of a core equals the average. If true, don´t show, because probably doesn´t exist, otherwise show. It´s the easiest way I could think of to do this, although there is a slight risk an existing core would be missed. Of course, I am open to better suggestions.

The few times I wanted something being blended out before everything worked fine, so I don´t know what I am missing here. I put up an example code which already is set up to [only] check for a fifth core, because I thought it would suite most of you. If you have an octa, feel free to change it to 9.
My problem: the core that shouldn´t be shown either stays or is blended in and out, i.E. blinking if I use hidden=1 on the meters.

Does anybody know what I don´t see while it´s right in front of me? :???:

post scriptum: The measures exist two times, I thought of using the UpdateDivider-option to check for existing cores once [and not all the time on every update] on the first block and using a second for the "real" stuff. If there is a shorter way to combine both and stress the computer less, I am curious.

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1

[Variables]
bgX=0
coreY=2

;------------------------------------

[Measure.CORE01check]
Measure=CPU
Processor=1
;<test whether core exists>

[Measure.CORE02check]
Measure=CPU
Processor=2
;<test whether core exists>

[Measure.CORE03check]
Measure=CPU
Processor=3
;<test whether core exists>

[Measure.CORE04check]
Measure=CPU
Processor=4
;<test whether core exists>

[Measure.CORE05check]
Measure=CPU
Processor=5
;UpdateDivider=-1
IfCondition=(#CURRENTSECTION#=[Measure.CORES])
IfTrueAction=[!HideMeterGroup "core05"][!UpdateMeterGroup "core05"][!Redraw]
IfFalseAction=[!ShowMeterGroup "core05"][!UpdateMeterGroup "core05"][!Redraw]

;these measures are for real working processes being used on different meters:
;[I skipped the meters for percentages and that stuff]
[Measure.CORES]
Measure=CPU
Processor=0

[Measure.CORE01]
Measure=CPU
Processor=1

[Measure.CORE02]
Measure=CPU
Processor=2

[Measure.CORE03]
Measure=CPU
Processor=3

[Measure.CORE04]
Measure=CPU
Processor=4

[Measure.CORE05]
Measure=CPU
Processor=5

;------------------------------------

[TitleStyle]
FontFace=tahoma
AntiAlias=1
FontSize=12
StringAlign=left
StringStyle=Normal
FontColor=255,255,255,255

[COREbg1Style]
X=[#bgX]
Y=0R
W=80
H=30
SolidColor=0,0,0,255

[CORETitleStyle]
Text=[#CURRENTSECTION]
X=(5+[#bgX])

;------------------------------------

[core01bg]
Group=core01
Meter=Image
MeterStyle=COREbg1Style

[core02bg]
Group=core02
Meter=Image
MeterStyle=bg1Style | COREbg1Style

[core03bg]
Group=core03
Meter=Image
MeterStyle=bg1Style | COREbg1Style

[core04bg]
Group=core04
Meter=Image
MeterStyle=bg1Style | COREbg1Style

[core05bg]
Group=core05
Meter=Image
MeterStyle=bg1Style | COREbg1Style

;------------------------------------

[core01]
Group=core01
Meter=String
MeterStyle=TitleStyle | CORETitleStyle
Y=([#coreY]+[core01bg:Y])

[core02]
Group=core02
Meter=String
MeterStyle=TitleStyle | CORETitleStyle
Y=([#coreY]+[core02bg:Y])

[core03]
Group=core03
Meter=String
MeterStyle=TitleStyle | CORETitleStyle
Y=([#coreY]+[core03bg:Y])

[core04]
Group=core04
Meter=String
MeterStyle=TitleStyle | CORETitleStyle
Y=([#coreY]+[core04bg:Y])

[core05]
Group=core05
Meter=String
MeterStyle=TitleStyle | CORETitleStyle
Y=([#coreY]+[core05bg:Y])


User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: problem hiding not existing cores per CPU measure

Post by SilverAzide »

Yue wrote: May 5th, 2023, 2:06 pm Hi!

I tried to rework my code using new gained knowledge but hit a [this time] simple problem. I created measures and meters for n cores. The intention is to automatically only show as many as exist. The idea is to check if the value of a core equals the average. If true, don´t show, because probably doesn´t exist, otherwise show. It´s the easiest way I could think of to do this, although there is a slight risk an existing core would be missed. Of course, I am open to better suggestions.

The few times I wanted something being blended out before everything worked fine, so I don´t know what I am missing here. I put up an example code which already is set up to [only] check for a fifth core, because I thought it would suite most of you. If you have an octa, feel free to change it to 9.
My problem: the core that shouldn´t be shown either stays or is blended in and out, i.E. blinking if I use hidden=1 on the meters.

Does anybody know what I don´t see while it´s right in front of me? :???:

post scriptum: The measures exist two times, I thought of using the UpdateDivider-option to check for existing cores once [and not all the time on every update] on the first block and using a second for the "real" stuff. If there is a shorter way to combine both and stress the computer less, I am curious.
You don't need two sets of measures for this. There are multiple ways to solve this. Not all ways are perfectly reliable if you have a more complex system, but if all you want is a simple skin that disables/hides measures and meters based on core count, you can just do this:

Code: Select all

[Measure.CORE01]
Measure=CPU
Processor=1
Disabled=(%NUMBER_OF_PROCESSORS% < 1)

[Measure.CORE02]
Measure=CPU
Processor=2
Disabled=(%NUMBER_OF_PROCESSORS% < 2)

[Measure.CORE03]
Measure=CPU
Processor=3
Disabled=(%NUMBER_OF_PROCESSORS% < 3)

;--------------------------

[Meter.CORE01]
Meter=String
...
; position core #1 where you need it, the remaining cores should be handled using relative positioning as defined in a style meter (not provided)
Y=0
Hidden=(%NUMBER_OF_PROCESSORS% < 1)

[Meter.CORE02]
Meter=String
...
Y=20r
Hidden=(%NUMBER_OF_PROCESSORS% < 2)

[Meter.CORE03]
Meter=String
...
Y=20r
Hidden=(%NUMBER_OF_PROCESSORS% < 3)
NUMBER_OF_PROCESSORS is a Windows environment variable that indicates the number of logical processors in your machine. This value cannot be relied on if using CPUs with more than 64 logical processors, or on SMP machines. Note the above sample code uses relative positioning for Y. The way you are doing it in your code is overly-complicated and will not work anyway since you are not taking into account the hidden cores.

As a side note, the CPU measure does not return "correct" values in Windows 22H2 and later ("correct" means "doesn't match Task Manager"; actually, it hasn't returned "correct" values since Windows 8, but it is super-obvious in 22H2 thanks to some undocumented changes by Microsoft in the way usage is calculated). This has been posted about elsewhere on the forums.
User avatar
Yincognito
Rainmeter Sage
Posts: 7024
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: problem hiding not existing cores per CPU measure

Post by Yincognito »

Yue wrote: May 5th, 2023, 2:06 pmI tried to rework my code using new gained knowledge but hit a [this time] simple problem. I created measures and meters for n cores. The intention is to automatically only show as many as exist.
Fortunately, like you guessed, this is a simpler problem than your previous drive one, because here you can't have gaps of non existing cores between existing ones, i.e. you can't have core 1 exists, core 2 exists, core 3 doesn't, core 4 doesn't, while core 5 and a few others after do exist. That being said, there are better ways to detect how many "cores" (well, actually, "logical processors") exist in a system. One of them was mentioned by SilverAzide. Another (or maybe the same?), largely copy pasted from a skin from my suite:

Code: Select all

[LogicalProcessorCount]
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=SYSTEM\CurrentControlSet\Control\Session Manager\Environment
RegValue=NUMBER_OF_PROCESSORS
UpdateDivider=...
IfCondition=(LogicalProcessorCount>=1)
IfTrueAction=...show or enable the "cpu1" group of measures/meters and such...
IfCondition2=(LogicalProcessorCount>=2)
IfTrueAction2=...show or enable the "cpu2" group of measures/meters and such...
...
This is based on the fact that the number of logical processors exists in the Windows registry, at:

Code: Select all

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\NUMBER_OF_PROCESSORS
So, you'll be able to get the number of "cores" directly, no need for other tests. After that, you can selectively show things or whatever based on that, like SilverAzide also pointed out.
User avatar
Yincognito
Rainmeter Sage
Posts: 7024
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: problem hiding not existing cores per CPU measure

Post by Yincognito »

As for the "accurate" reading of CPU / cores usages mentioned above, while I can't guarantee for Win 11 since I don't use it (SilverAzide and others can tell you more about that when it comes to Rainmeter), on Win 10 this will provide closer values to the Task Manager ones than the standard CPU measures:

Code: Select all

[CPUUsage]
Measure=Plugin
Plugin=UsageMonitor
Category=Processor Information
Counter=% Processor Utility
Name=0,_Total

[CPU1Usage]
Measure=Plugin
Plugin=UsageMonitor
Category=Processor Information
Counter=% Processor Utility
Name=0,0

...
You'll have to get the number value of these measures by either using a Calc measure having a corresponding Formula value (e.g. CPUUsage, CPU1Usage, etc.) or use the measure's numerical value directly via [CPUUsage:], [CPU1Usage:] and so on, because the measures have a different string value, which is used by default in String meters, unless specified otherwise like already explained.

Also, in case it's not obvious, for variable frequency CPUs or setups, the usage alone isn't capturing the entire thing. That usage is a percent of the CPUs current frequency, so it "should" be corroborated with that to get the full picture. That brings other "complications" like getting the "standard" CPU speed via a Registry measure from HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0\~MHz, getting the "processor performance" in relation to that speed via a % Processor Performance counter in an Usage Monitor measure similar to the CPUUsage above, then computing the actual / current frequency in a Calc by multiplying the processor performance percent with its speed ... if the counter for the former exists on the system, to begin with.

Yep, I know, should - and used to - be simpler. Blame MS for this, lol.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: problem hiding not existing cores per CPU measure

Post by SilverAzide »

Yincognito wrote: May 5th, 2023, 5:02 pm
This is based on the fact that the number of logical processors exists in the Windows registry, at:

Code: Select all

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\NUMBER_OF_PROCESSORS
So, you'll be able to get the number of "cores" directly, no need for other tests.
I assume you are aware that you don't need to fetch environment variables from the registry? You can use them directly in Rainmeter with the %% variable decoration. Like so:

Code: Select all

[LogicalProcessorCount]
Measure=Calc
Formula=%NUMBER_OF_PROCESSORS%
IfCondition=(LogicalProcessorCount>=1)
IfTrueAction=...show or enable the "cpu1" group of measures/meters and such...
IfCondition2=(LogicalProcessorCount>=2)
IfTrueAction2=...show or enable the "cpu2" group of measures/meters and such...
...
UpdateDivider=-1
:great:
User avatar
Yincognito
Rainmeter Sage
Posts: 7024
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: problem hiding not existing cores per CPU measure

Post by Yincognito »

SilverAzide wrote: May 5th, 2023, 8:00 pm I assume you are aware that you don't need to fetch environment variables from the registry? You can use them directly in Rainmeter with the %% variable decoration. Like so:

Code: Select all

[LogicalProcessorCount]
Measure=Calc
Formula=%NUMBER_OF_PROCESSORS%
IfCondition=(LogicalProcessorCount>=1)
IfTrueAction=...show or enable the "cpu1" group of measures/meters and such...
IfCondition2=(LogicalProcessorCount>=2)
IfTrueAction2=...show or enable the "cpu2" group of measures/meters and such...
...
UpdateDivider=-1
:great:
I vaguely remember seeing that approach somewhere in the past, but yeah, I probably forgot about it and wasn't consciously aware of it, or at least, not anymore. Thanks for pointing that out! :thumbup:

P.S. I'll probably continue to use a Registry value for this next time though, and the reason is simple: it helps me avoid having to remember precisely which is an environment variable and which is not (I know where to look and see what those are, it's just the lazy bastard in me talking, lol)... :oops:
Yue
Posts: 59
Joined: March 23rd, 2023, 1:10 pm

Re: problem hiding not existing cores per CPU measure

Post by Yue »

SilverAzide » May 5th, 2023, 4:54 pm
You don't need two sets of measures for this.
Disabled=
Thank you, I rarely remember reading about disabling. That makes things easier.
NUMBER_OF_PROCESSORS is a Windows environment variable [...]
At least that suits the "what´s right in front of me". I should have thought of the possibility to use system environment variables, especially since I use many self-created to organise my system. :oops:
This value cannot be relied on if using CPUs with more than 64 logical processors, or on SMP machines.
Oh, that I did not know [and I don´t know SMP]. But that shouldn´t become a problem.
Note the above sample code uses relative positioning for Y.
Yes, saw that. It´s similar to your earlier hint on positioning in my other thread. But that´s something I understand now and can use in at least a few different ways.
The way you are doing it in your code is overly-complicated and will not work anyway since you are not taking into account the hidden cores.
Yeah, I know. I didn´t like the idea of using all measures doubled, but thought it would be a small minus to resources usage if I use updatedivider=-1 to check for existing processors not on every update.
By "taking into account" you meant the missing hidden=? That I only wrote in the question post and left it out in the example code in case there is an easier way, so you or others wouldn´t have to tell me to scratch that approach.
As a side note, the CPU measure does not return "correct" values in Windows 22H2 and later ("correct" means "doesn't match Task Manager"; actually, it hasn't returned "correct" values since Windows 8, but it is super-obvious in 22H2 thanks to some undocumented changes by Microsoft in the way usage is calculated). This has been posted about elsewhere on the forums.
Oh, that´s interesting new to me, because for at least a few months I will continue working on an older Windows and then switch to newer version. Thank you!
Yincognito » May 5th, 2023, 5:02 pm
[...] there are better ways to detect how many "cores" (well, actually, "logical processors") exist in a system.
As far as I know, even in English people tend to switch between both words meaning the same? But we can stick to "logical" since it makes things undoubtedly clear.
Another (or maybe the same?), largely copy pasted from a skin from my suite:
After SilverAzide reminded me of using Windows variables, that´s something I can tell about. More or less it is the same, because the path in the registry you pointed out is where the system environoment variables are kept by Windows [not sure if it´s the same for user environment variables because I always use them on system level].
So, you'll be able to get the number of "cores" directly, no need for other tests. After that, you can selectively show things or whatever based on that, like SilverAzide also pointed out.
Jep, that will be the first step now. Thank you two! :welcome:
As for the "accurate" reading of CPU / cores usages mentioned above, [...]
You'll have to get the number value of these measures by either using a Calc measure having a corresponding Formula value (e.g. CPUUsage, CPU1Usage, etc.) or use the measure's numerical value directly via [CPUUsage:], [CPU1Usage:] and so on, because the measures have a different string value, which is used by default in String meters, unless specified otherwise like already explained.
Thanks, that answers the question I don´t have to aks now - if the usagemonitor would be a better approach, although I have read just a tiny bit about it. That will be step 2 then.^^ First I will use SilverAzide´s hint to blend in and out the meters, then closing up to accurate values.
Also, in case it's not obvious, for variable frequency CPUs or setups, the usage alone isn't capturing the entire thing. That usage is a percent of the CPUs current frequency, so it "should" be corroborated with that to get the full picture. That brings other "complications" like getting the "standard" CPU speed [...], the "processor performance" in relation to that speed via a % Processor Performance counter in an Usage Monitor measure similar to the CPUUsage above, then computing the actual / current frequency in a Calc by multiplying the processor performance percent with its speed ... if the counter for the former exists on the system, to begin with.
It should have been obvious, but I am pretty much no resource of knowledge if it comes to hardware [I know, shame on me] so I wouldn´t have thought of that and missed it. Thanks you mentioned that. I will get back to you on that later.

Once again, thank you two. Next days I will implement your helping hints and then report back! :)
User avatar
Yincognito
Rainmeter Sage
Posts: 7024
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: problem hiding not existing cores per CPU measure

Post by Yincognito »

Yue wrote: May 7th, 2023, 9:54 amAs far as I know, even in English people tend to switch between both words meaning the same? But we can stick to "logical" since it makes things undoubtedly clear.
Correct, because without proper differentiation, they're not the same, at least not technically. A core is an individual physical processing unit of the CPU, that can handle single or multiple virtual sequences of instructions, aka threads. The number of logical processors in a CPU is the product of the number of physical cores with the number of threads each core can handle (or schedule to be processed by a single core):
Cores vs Logical Processors.jpg
Basically, logical processors are the number of "virtual / logical cores" the OS sees and can address. Hence why the additional "logical" makes things quite clear.
Yue
Posts: 59
Joined: March 23rd, 2023, 1:10 pm

Re: problem hiding not existing cores per CPU measure

Post by Yue »

Yincognito » Yesterday, 6:07 pm
The number of logical processors in a CPU is the product of the number of physical cores with the number of threads each core can handle
I meant something else, so thanks. Now, after your post and a little reading on actual articles, I see, what I read once, was neither a complete explanation nor a correct one. :( Back in the picture now...but the part about taking the frequency into account will become fun [more or less] later. I already read a little about it, but first things first.
I will apply the helping hints so far [and rename my measures and meters because wrong naming always looks stupid], i.E. only showing the percentages of the actual frequency to be sure everything works so far, and after that I guess, I will need some help with what to calculate how. I will do some digging, because after my little reading session it´s already clear why and what has to be taken into account when it comes to variable frequencies, that´s simple math. How to do it technically in Rainmeter might not be that easy because I only have read about usage monitor plugin and not used it yet. Give me some time and I will report back! :)
User avatar
Yincognito
Rainmeter Sage
Posts: 7024
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: problem hiding not existing cores per CPU measure

Post by Yincognito »

Yue wrote: May 8th, 2023, 12:10 pm Give me some time and I will report back! :)
Sure thing - take your time. :thumbup:
Post Reply