It is currently April 8th, 2020, 3:14 pm

Skin that measures how long a process has been running?

Help with creating, editing & fixing problems with skins
LurkedLurkingLurker
Posts: 3
Joined: March 20th, 2020, 9:01 pm

Skin that measures how long a process has been running?

Post by LurkedLurkingLurker »

Hello, I'm completely new to all of this, so it's a bit overwhelming. Essentially, I'm trying to keep a constant reminder of how long I have been using Google Chrome since system uptime, and I don't know where to look to find this.

I found the process plugin, which tells me that Chrome is running, but is there a way to measure how long the process has been running since system startup? i.e. Total Chrome usage since startup? I'm guessing this would have something to do with measure, but I don't know where to look.

Sorry if this is the wrong place to ask this.

-Tom
LurkedLurkingLurker
Posts: 3
Joined: March 20th, 2020, 9:01 pm

Re: Skin that measures how long a process has been running?

Post by LurkedLurkingLurker »

So I found this thread:

https://forum.rainmeter.net/viewtopic.php?t=26085

Which measures the amount of uptime Rainmeter had, and when I tried to copy-paste everything into a new skin, replacing Rainmeter with chrome, I think I got the amount of uptime chrome had since its first opening. It still continues counting even after I close chrome, which isn't what I wanted since I want net chrome time.

I saw that the Plugin=PerfMon has been deprecated with Plugin=UsageMonitor, which doesn't seem drastically different.

I still don't exactly know what I'm doing, but I guess I'm learning.
User avatar
Yincognito
Posts: 1152
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Skin that measures how long a process has been running?

Post by Yincognito »

LurkedLurkingLurker wrote:
March 20th, 2020, 9:13 pm
Hello, I'm completely new to all of this, so it's a bit overwhelming. Essentially, I'm trying to keep a constant reminder of how long I have been using Google Chrome since system uptime, and I don't know where to look to find this.

I found the process plugin, which tells me that Chrome is running, but is there a way to measure how long the process has been running since system startup? i.e. Total Chrome usage since startup? I'm guessing this would have something to do with measure, but I don't know where to look.

Sorry if this is the wrong place to ask this.

-Tom
First, you should decide what you want to get:
- how long you've been using Chrome since your logon ... or ...
- how much average (total doesn't make sense here, really) CPU did Chrome use since your logon

You might want to take a look at:
- Time measure (getting to know a bit how this works is useful to ease your understanding of the following measure)
- Uptime measure (check the note on Windows 10 and the sample skin at the bottom of the page, as that might be useful)
- Process plugin (just mentioning it, as you said you took a look at it)
- UsageMonitor plugin (check the samples there as well, I think some of them might suit your case)

Bottom line, a skin doing one (or both) of the things I mentioned at the beginning would almost certainly involve a mix of the "reading recommendations" I iterated above.

Personally, I have a skin measuring the current and the average CPU usage of Rainmeter (can be adapted to another program, of course) over a period of up to one hour, but it isn't exactly what you need. In the end, if Rainmeter (and your skin) starts with Windows, I guess you could do without the time measures, just by measuring the - current and average - CPU usage of Chrome (using the UsageMonitor plugin) while Chrome is running (i.e. while the Process plugin's measure value is 1 for Chrome). Let me see what I can come up with.
User avatar
Brian
Developer
Posts: 1968
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Skin that measures how long a process has been running?

Post by Brian »

You could use powershell to get the "uptime" of a process.

Here is a really crude example (no error checking):

Code: Select all

[Rainmeter]
Update=-1
DynamicWindowSize=1
AccurateText=1

[Variables]
Program="Google Chrome"
;Program="Notepad"

[RunCommand]
Measure=Plugin
Plugin=RunCommand
Parameter=powershell "(New-TimeSpan -Start (Get-Process | Where-Object {$_.MainWindowTitle -like '*#Program#'}).StartTime).TotalSeconds"
OutputType=ANSI
FinishAction=[!EnableMeasure ProgramUpTime][!UpdateMeasure ProgramUpTime][!ShowMeter Output][!UpdateMeter Output][!Redraw]

[ProgramUpTime]
Measure=UpTime
Format="%4!i!d %3!i!h %2!i!m %1!i!s"
SecondsValue=[RunCommand]
DynamicVariables=1
Disabled=1

[Style]
Padding=5,5,5,5
SolidColor=47,47,47
FontColor=220,220,220
FontSize=12

[Label]
Meter=String
MeterStyle=Style
Text=Click me
LeftMouseUpAction=[!CommandMeasure RunCommand Run]

[Output]
Meter=String
MeasureName=ProgramUpTime
MeterStyle=Style
Y=2R
Text="#Program#" uptime: %1
Hidden=1
Please note that this uses the "window's title" to identify its process, then getting it's "StartTime". There is no error checking, so invalid process's will throw an error, and the UpTime measure will just show 0d 0h 0m 0s.

Hopefully that gets you started.

-Brian
User avatar
Yincognito
Posts: 1152
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Skin that measures how long a process has been running?

Post by Yincognito »

Ok, so this is relatively accurate - it doesn't involve counting up the time, but rather counting the 1000 ms Rainmeter updates while Chrome has been running (coupled with computing the average CPU usage of Chrome in that time):

Code: Select all

[Variables]

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[MeasureChromeRunning]
Measure=Plugin
Plugin=Process
ProcessName=chrome.exe

[MeasureChromeElapsedUpdates]
Measure=Calc
Formula=(MeasureChromeElapsedUpdates+((MeasureChromeRunning=1)?(1):(0)))
DynamicVariables=1

[MeasureUpdatesToTime]
Measure=Uptime
SecondsValue=[MeasureChromeElapsedUpdates]
Format="%4!02i!d %3!02i!h %2!02i!m %1!02i!s"
DynamicVariables=1

[MeasureChromeCurrentCPUUsage]
Measure=Plugin
Plugin=UsageMonitor
Alias=CPU
Name=chrome

[MeasureChromeAggregateCPUUsage]
Measure=Calc
Formula=Round((MeasureChromeAggregateCPUUsage+((MeasureChromeRunning=1)?(MeasureChromeCurrentCPUUsage):(0))),2)
DynamicVariables=1

[MeasureChromeAverageCPUUsage]
Measure=Calc
Formula=(Round(MeasureChromeAggregateCPUUsage/((MeasureChromeElapsedUpdates=0)?(1):(MeasureChromeElapsedUpdates)),2))
DynamicVariables=1

---Meters---

[MeterTest]
Meter=STRING
X=0
Y=0
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
Text="Chrome  (current CPU usage) = [MeasureChromeCurrentCPUUsage:2] %#CRLF#Chrome  (average CPU usage) = [MeasureChromeAverageCPUUsage:2] %#CRLF#Chrome (total running time) = [MeasureUpdatesToTime]"
DynamicVariables=1
This skin needs to "run with Windows" in order for its output to be close to accurate. Basically, instead of messing up with logon times, startup times and such, the skin load / refresh is when the counting / computing starts. While Chrome's current CPU usage runs all the time, the elements needed to compute its average CPU usage change only when Chrome itself is running (otherwise just adding zeros to the result).

Now of course, this isn't going to be 100% accurate, since Rainmeter updates, although set at 1000 ms (i.e. one second), are influenced by various factors, including how busy the CPU is - but it's going to be as close as it can get to that. If anyone has other ideas (like using logon time and such), please share - I found this approach accurate and simple enough.
LurkedLurkingLurker
Posts: 3
Joined: March 20th, 2020, 9:01 pm

Re: Skin that measures how long a process has been running?

Post by LurkedLurkingLurker »

Thanks for all the help. I'll take some time to play with these things. I was starting to think this was a lost cause.