It is currently April 27th, 2024, 12:35 pm

CPU usage of processes

Get help with creating, editing & fixing problems with skins
User avatar
SilverAzide
Rainmeter Sage
Posts: 2611
Joined: March 23rd, 2015, 5:26 pm

Re: CPU usage of processes

Post by SilverAzide »

Yincognito wrote: May 8th, 2023, 12:58 pm Ah, that explains it, thanks - was sure I missed something in the measure! Although... the Rainmeter percentage of all processes should be greater than its percentage of the total CPU, if that makes sense, right? Meaning raw PerfMon provides the former, while Task Manager provides the latter. So why needing the Percent=1 then? :???:

Anyway, just curious, how does the UsageMonitor measure value without Percent=1 compare to Windows 11 reporting in Task Manager? Is there any similarity whatsoever?
Well, what PerfMon is giving you in your example is the "percentage of CPU time" for the Rainmeter process. What it is not giving you is the "percentage of CPU time" for all processes. For example, PerfMon might say Rainmeter is using 10% of the CPU time. But all the processes on the machine (the total) is taking, say, 50% of the CPU time. The remaining 50% is idle time. So to know what portion of total CPU time is Rainmeter, it would be 10% of the 50%, or 5%. 5% is what you will see in Rainmeter (with Percent=1) and in Task Manager.

In theory you should be able to see this if you create two measures, one for Rainmeter with Percent=0, and another for "_Total" (with Percent=0). Then do the division yourself and it should come out the same as a measure for Rainmeter with Percent=1.
Gadgets Wiki GitHub More Gadgets...
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: CPU usage of processes

Post by Yincognito »

SilverAzide wrote: May 8th, 2023, 2:28 pm Well, what PerfMon is giving you in your example is the "percentage of CPU time" for the Rainmeter process. What it is not giving you is the "percentage of CPU time" for all processes. For example, PerfMon might say Rainmeter is using 10% of the CPU time. But all the processes on the machine (the total) is taking, say, 50% of the CPU time. The remaining 50% is idle time. So to know what portion of total CPU time is Rainmeter, it would be 10% of the 50%, or 5%. 5% is what you will see in Rainmeter (with Percent=1) and in Task Manager.

In theory you should be able to see this if you create two measures, one for Rainmeter with Percent=0, and another for "_Total" (with Percent=0). Then do the division yourself and it should come out the same as a measure for Rainmeter with Percent=1.
Yep, I was understanding that already, and it checked out after testing like you said, of course. My earlier "although" reasoning was based on incorrectly equaling a percentage from 100 (like all 3 variants, aka alias, counter with percent and raw division method give) to the "% Processor Time" which is a "percentage" (so to speak) of a variable base larger than 100:
Processor Times And Percentages.jpg
In other words, the 4.69 above isn't a standard percentage (might not even be one and represent some value in raw time or computer clock units), therefore my comparison with "true percentages" earlier was faulty because of nonmatching units. Thanks again for correcting my mistake in thinking - had that one in the back of my brain since it's not the first time dealing with these, but somehow the idea didn't get to the surface. :oops:
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Jose Hidalgo
Posts: 60
Joined: September 7th, 2018, 4:47 pm

Re: CPU usage of processes

Post by Jose Hidalgo »

Hi guys. Win 11 user here :Whistle So, no solution or workaround as of today?

I have a basic CPU meter that used to work perfectly under Win 7. Here's a part of the code:

Code: Select all

[MeasureCPU]
Measure=CPU
IfCondition=(#CURRENTSECTION#<60)
IfTrueAction=[!SetOption MeterCPUBar BarColor "185,250,160"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition2=((#CURRENTSECTION#>=60)&&(#CURRENTSECTION#<80))
IfTrueAction2=[!SetOption MeterCPUBar BarColor "255,255,153"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition3=(#CURRENTSECTION#>=80)
IfTrueAction3=[!SetOption MeterCPUBar BarColor "205,175,180"][!UpdateMeter "MeterCPUBar"][!Redraw]
On Win 11 this leads to my CPU bar being at 0% most of the time, when the Task Manager shows higher CPU scores.

Any chance this code could be at least "adapted" to work with Win 11?

Thank you. :oops:
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: CPU usage of processes

Post by Yincognito »

Jose Hidalgo wrote: February 8th, 2024, 2:42 am Hi guys. Win 11 user here :Whistle So, no solution or workaround as of today?

I have a basic CPU meter that used to work perfectly under Win 7. Here's a part of the code:

Code: Select all

[MeasureCPU]
Measure=CPU
IfCondition=(#CURRENTSECTION#<60)
IfTrueAction=[!SetOption MeterCPUBar BarColor "185,250,160"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition2=((#CURRENTSECTION#>=60)&&(#CURRENTSECTION#<80))
IfTrueAction2=[!SetOption MeterCPUBar BarColor "255,255,153"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition3=(#CURRENTSECTION#>=80)
IfTrueAction3=[!SetOption MeterCPUBar BarColor "205,175,180"][!UpdateMeter "MeterCPUBar"][!Redraw]
On Win 11 this leads to my CPU bar being at 0% most of the time, when the Task Manager shows higher CPU scores.

Any chance this code could be at least "adapted" to work with Win 11?

Thank you. :oops:
Well, the links in this thread already answer that, but since you probably didn't check them, something like:

Code: Select all

[MeasureCPU]
Measure=Plugin
Plugin=UsageMonitor
Category=Processor Information
Counter=% Processor Utility
Name=0,_Total
...
will probably do. Unfortunately, in the case of the CPU usage of individual processes, the adjusted method based on the above will not yield the Win 11's Task Manager values. If you're curious on the details, SilverAzide mentioned this quite a few times here on the forum. Personally, I'm not on Win 11 so can't contribute more to the whole story or try to identify possible (though improbable) solutions for that latter part.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Jose Hidalgo
Posts: 60
Joined: September 7th, 2018, 4:47 pm

Re: CPU usage of processes

Post by Jose Hidalgo »

Don't get me wrong: I have tried already. Yesterday I spent about 30min trying to make it work with the infos I found in this topic. Unfortunately I'm too unexperienced with Rainmeter to make it work. Just like I couldn't make it work today with your own bit of code. I must be doing something wrong.

Here's the whole skin I'm using. I have tried replacing "Measure=CPU" with your five lines of code, but it doesn't work. If you can help with this, I'll be most grateful. A vague measure of my average %CPU, even a bit inaccurate, will be much better than my current 0%. Thank you.

Code: Select all

[Rainmeter]
Update=2000
Background=#@#bg_small.png

LeftMouseUpAction=["taskmgr.exe"]

---------------

[Variables]

[MeasureCPU]
Measure=CPU
IfCondition=(#CURRENTSECTION#<60)
IfTrueAction=[!SetOption MeterCPUBar BarColor "185,250,160"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition2=((#CURRENTSECTION#>=60)&&(#CURRENTSECTION#<80))
IfTrueAction2=[!SetOption MeterCPUBar BarColor "255,255,153"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition3=(#CURRENTSECTION#>=80)
IfTrueAction3=[!SetOption MeterCPUBar BarColor "205,175,180"][!UpdateMeter "MeterCPUBar"][!Redraw]

[MeasureRAM]
Measure=PhysicalMemory
MinValue=0
MaxValue=[MeasureRAMTotal]
DynamicVariables=1

[MeasureRAMTotal]
Measure=PhysicalMemory
Total=1

[MeasureRAMPercent]
Measure=Calc
Formula=( 100 * MeasureRAM / MeasureRAMTotal)
IfCondition=(#CURRENTSECTION#<80)
IfTrueAction=[!SetOption MeterRAMBar BarColor "185,250,160"][!UpdateMeter "MeterRAMBar"][!Redraw]
IfCondition2=((#CURRENTSECTION#>=80)&&(#CURRENTSECTION#<90))
IfTrueAction2=[!SetOption MeterRAMBar BarColor "255,255,153"][!UpdateMeter "MeterRAMBar"][!Redraw]
IfCondition3=(#CURRENTSECTION#>=90)
IfTrueAction3=[!SetOption MeterRAMBar BarColor "205,175,180"][!UpdateMeter "MeterRAMBar"][!Redraw]

[MeasureMaxTemp]
Measure=Plugin
Plugin=CoreTemp
CoreTempType=MaxTemperature
IfCondition=(#CURRENTSECTION#<70)
IfTrueAction=[!SetOption MeterMaxTempBar BarColor "185,250,160"][!UpdateMeter "MeterMaxTempBar"][!Redraw]
IfCondition2=((#CURRENTSECTION#>=70)&&(#CURRENTSECTION#<85))
IfTrueAction2=[!SetOption MeterMaxTempBar BarColor "255,255,153"][!UpdateMeter "MeterMaxTempBar"][!Redraw]
IfCondition3=(#CURRENTSECTION#>=85)
IfTrueAction3=[!SetOption MeterMaxTempBar BarColor "205,175,180"][!UpdateMeter "MeterMaxTempBar"][!Redraw]

[MeasureMaxTempPercent]
Measure=Calc
Formula=( 100 * MeasureMaxTemp / 95)
MinValue=0
MaxValue=100

---------------

[MeterCPUSmallText]
Meter=STRING
UpdateDivider=-1
X=68
Y=20
FontColor=220,220,220
FontSize=7
FontFace=Segoe UI
StringStyle=BOLD
StringEffect=Shadow
StringEffectColor=0,0,0
StringAlign=RightCenter
AntiAlias=1
Text=CPU

[MeterCPU]
Meter=STRING
MeasureName=MeasureCPU
X=68
Y=33
FontColor=220,220,220
FontSize=12
FontFace=Segoe UI
StringStyle=BOLD
StringEffect=Shadow
StringEffectColor=0,0,0
StringAlign=RightCenter
AntiAlias=1
Text=%1%

[MeterCPUBar]
Meter=Bar
MeasureName=MeasureCPU
X=73
Y=22
W=97
H=12
SolidColor=150,150,150,100
BarOrientation=Horizontal

---------------

[MeterRAMSmallText]
Meter=STRING
UpdateDivider=-1
X=68
Y=53
FontColor=220,220,220
FontSize=7
FontFace=Segoe UI
StringStyle=BOLD
StringEffect=Shadow
StringEffectColor=0,0,0
StringAlign=RightCenter
AntiAlias=1
Text=RAM

[MeterRAM]
Meter=STRING
MeasureName=MeasureRAMPercent
X=68
Y=66
FontColor=220,220,220
FontSize=12
FontFace=Segoe UI
StringStyle=BOLD
StringEffect=Shadow
StringEffectColor=0,0,0
StringAlign=RightCenter
AntiAlias=1
Text=%1%

[MeterRAMBar]
Meter=Bar
MeasureName=MeasureRAM
X=73
Y=55
W=97
H=12
SolidColor=150,150,150,100
BarOrientation=Horizontal

---------------

[MeterMaxTempSmallText]
Meter=STRING
UpdateDivider=-1
X=68
Y=86
FontColor=220,220,220
FontSize=7
FontFace=Segoe UI
StringStyle=BOLD
StringEffect=Shadow
StringEffectColor=0,0,0
StringAlign=RightCenter
AntiAlias=1
Text=TEMP

[MeterMaxTemp]
Meter=String
MeasureName=MeasureMaxTemp
X=68
Y=99
FontColor=220,220,220
FontSize=12
FontFace=Segoe UI
StringStyle=BOLD
StringEffect=Shadow
StringEffectColor=0,0,0
StringAlign=RightCenter
AntiAlias=1
Text=%1 C

[MeterMaxTempBar]
Meter=Bar
MeasureName=MeasureMaxTempPercent
X=73
Y=88
W=97
H=12
SolidColor=150,150,150,100
BarOrientation=Horizontal
User avatar
balala
Rainmeter Sage
Posts: 16176
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: CPU usage of processes

Post by balala »

Jose Hidalgo wrote: February 8th, 2024, 2:42 am On Win 11 this leads to my CPU bar being at 0% most of the time, when the Task Manager shows higher CPU scores.
Are you sure? Your code works perfectly here, the bar is varying according to value of the [MeasureCPU] measure. I'm now on Windows 11 Pro 23H2.
User avatar
Jose Hidalgo
Posts: 60
Joined: September 7th, 2018, 4:47 pm

Re: CPU usage of processes

Post by Jose Hidalgo »

Yup, pretty sure :???: The code works perfectly, but it displays about 8 times less % than the Task Manager.
I'm on Win 11 Pro 23H2 too.
And for the record, my new rig has a Ryzen 7700 + B650M mobo.

Image
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: CPU usage of processes

Post by Yincognito »

Well, this plugin yields different string and number values, and you're only interested in the number value, so try using this:

Code: Select all

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

[MeasureCPU]
Measure=Calc
Formula=MeasureCPUStringAndNumber
The above should replace this:

Code: Select all

[MeasureCPU]
Measure=CPU
IfCondition=(#CURRENTSECTION#<60)
IfTrueAction=[!SetOption MeterCPUBar BarColor "185,250,160"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition2=((#CURRENTSECTION#>=60)&&(#CURRENTSECTION#<80))
IfTrueAction2=[!SetOption MeterCPUBar BarColor "255,255,153"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition3=(#CURRENTSECTION#>=80)
IfTrueAction3=[!SetOption MeterCPUBar BarColor "205,175,180"][!UpdateMeter "MeterCPUBar"][!Redraw]
Once it works, you can add your IfConditions back to the contents of your new [MeasureCPU] measure.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Jose Hidalgo
Posts: 60
Joined: September 7th, 2018, 4:47 pm

Re: CPU usage of processes

Post by Jose Hidalgo »

Thank you :) That formula seems to be good enough for me. The skin displays a % value that's close to what the Task Manager displays.

Unfortunately the bar doesn't work yet. I have tried adding the IF conditions but it doesn't work. The skin displays either an empty bar or a full bar. What am I missing here?

Code: Select all

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

[MeasureCPU]
Measure=Calc
Formula=MeasureCPUStringAndNumber
IfCondition=(#CURRENTSECTION#<60)
IfTrueAction=[!SetOption MeterCPUBar BarColor "185,250,160"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition2=((#CURRENTSECTION#>=60)&&(#CURRENTSECTION#<80))
IfTrueAction2=[!SetOption MeterCPUBar BarColor "255,255,153"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition3=(#CURRENTSECTION#>=80)
IfTrueAction3=[!SetOption MeterCPUBar BarColor "205,175,180"][!UpdateMeter "MeterCPUBar"][!Redraw]
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: CPU usage of processes

Post by Yincognito »

Jose Hidalgo wrote: February 8th, 2024, 6:08 pm Thank you :) That formula seems to be good enough for me. The skin displays a % value that's close to what the Task Manager displays.

Unfortunately the bar doesn't work yet. I have tried adding the IF conditions but it doesn't work. The skin displays either an empty bar or a full bar. What am I missing here?

Code: Select all

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

[MeasureCPU]
Measure=Calc
Formula=MeasureCPUStringAndNumber
IfCondition=(#CURRENTSECTION#<60)
IfTrueAction=[!SetOption MeterCPUBar BarColor "185,250,160"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition2=((#CURRENTSECTION#>=60)&&(#CURRENTSECTION#<80))
IfTrueAction2=[!SetOption MeterCPUBar BarColor "255,255,153"][!UpdateMeter "MeterCPUBar"][!Redraw]
IfCondition3=(#CURRENTSECTION#>=80)
IfTrueAction3=[!SetOption MeterCPUBar BarColor "205,175,180"][!UpdateMeter "MeterCPUBar"][!Redraw]
The bar meters work with the percentual value of measures:
https://docs.rainmeter.net/manual/meters/bar/
So, to use that in your meters, you'd have to add a suited MinValue and MaxValue to your MeasureCPU, so that the measure knows what values you consider as 0% and 100%:
https://docs.rainmeter.net/manual/measures/general-options/#MaxValue
Be aware though that MeasureCPU might produce values larger than 100 (percent), so your MaxValue should potentially account for that.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth