Last active
December 12, 2019 00:30
-
-
Save devblackops/f84afe23c37233d6be8ade53a7fd16f2 to your computer and use it in GitHub Desktop.
Track Chrome processes for graphing at the console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put these functions in the profile.ps1 to start and stop Chrome usage tracking. | |
# Display your Chrome usage by running "Show-ChromeUsage" | |
# Track Chrome usage | |
function Start-ChromeUsageTracking { | |
$job = Start-Job -Name ChromeTracker -ScriptBlock { | |
while ($true) { | |
$now = [datetime]::Now.ToString('s') | |
$tabs = (Get-Process chrome -ErrorAction SilentlyContinue).Count | |
$log = Join-Path ([IO.Path]::GetTempPath()) 'chrome_usage.csv' | |
"$now,$tabs" >> $log | |
Start-Sleep -Seconds 5 | |
} | |
} | |
} | |
function Stop-ChromeUsageTracking { | |
Stop-Job -Name ChromeTracker | |
} | |
function Show-ChromeUsage { | |
param( | |
[int]$Last = 50, | |
[ValidateSet('Bar', 'Line', 'Scatter')] | |
[string]$Type = 'Line' | |
) | |
Import-Module Graphical | |
$data = Join-Path ([IO.Path]::GetTempPath()) 'chrome_usage.csv' | |
$points = Import-Csv $data -Header Time,Tabs | Select-Object -Last $last | |
Show-Graph -Datapoints $points.Tabs -YAxisTitle Tabs -GraphTitle 'Chrome Usage' -Type $Type | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment