-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Winfetch 2.1.0 taking ages to get disk info #93
Comments
Can you try commenting out all the segments, except the disk info in the config file? Also, does it happen every time in a session, or just once in a session? |
Happens every time in a session. As for the config, if I comment out every line there except Please note that anything that is commented out by default was left commented out the whole time. |
Just tried commenting out only |
Please paste your config file here, I'd like to test it on my system. |
I will tomorrow when I can get back to my computer. If it helps I did use Scoop to install winfetch (not a global installation). |
Here's the version right now that works. Just uncomment the line for |
The config file works fine here. Maybe the disk function is problematic. Can you run the following function and paste the output here? $showdisks = @($env:SystemDrive)
[System.Collections.ArrayList]$lines = @()
function to_units($value) {
if ($value -gt 1tb) {
return "$([math]::round($value / 1tb, 1)) TiB"
} else {
return "$([math]::floor($value / 1gb)) GiB"
}
}
$disks = Get-CimInstance -ClassName Win32_LogicalDisk -Property Size, FreeSpace
foreach ($diskInfo in $disks) {
foreach ($diskLetter in $showDisks) {
if ($diskInfo.DeviceID -eq $diskLetter -or $diskLetter -eq "*") {
$total = $diskInfo.Size
$used = $total - $diskInfo.FreeSpace
if ($total -gt 0) {
$usage = [math]::floor(($used / $total * 100))
[void]$lines.Add(@{
title = "Disk ($($diskInfo.DeviceID))"
content = "$(to_units $used) / $(to_units $total) ($usage%)"
})
}
break
}
}
}
return $lines This will tell if the SystemDrive (usually C:) is getting read properly. If this runs fine, replace |
Here is the output of the original function:
Here is the output of the modified function:
The first function took roughly 20 seconds to run each time, new session or not. The second function only took about 15 seconds to run but if I ran it multiple times in the same session it ran instantaneously each time after the first. The time for the first function did not change if I ran it multiple times in the same session. |
Looks like the WMIC call itself is very slow on your system - I don't think there's any way to fix it in winfetch since it's the only possible method for getting all the disk info. Regarding the discrepancy between |
I can confirm, running |
Yeah, WMIC is weird in it's own way. For example, the command |
.NET drives me up the wall sometimes... |
...I don't know what WMIC is written in, but how is it related to .NET? |
The problem here is that PowerShell compiles down to .NET runtime during operation (afaik) and the .NET runtime's binding to the WMIC is extraordinarily convoluted. See https://community.spiceworks.com/topic/1417087-poor-performance-with-cim-commands |
I don't think .NET is the culprit here, because running the command |
I will try that. I may also start looking for ways to get this data without WMIC, possibly through a system dll. |
There shouldn't be any difference between using these, if there appears to be then it's probably related to something else. PowerShell is based in .NET, (I've heard that's one of the reasons it's so slow to startup) and the methods it calls are using the .NET methods, but it's unlikely that these methods would behave differently on different systems. My guess is that it's caused by the underlying WMI interface, which is separate from PowerShell and .NET. I'm not sure why it would be so slow unless you have to some odd hardware configuration, like lots or drives or something. There are ways to fetch disk information without WMI, such as this, however, I'm not sure how easy it would be to implement in PowerShell, as the language really struggles to do complex or low-level interactions. |
@jcwillox maybe winfetch could break out to C# for low level operations like that. I’m not 100% sure what they’re doing because I don’t know Go at all, but I think C# has a better handle on low level stuff and I know it can run dll calls. |
That's not really true, in fact, PowerShell is the only shell/scripting language that allows using DLLs directly. And it's fairly easy, see |
That's not technically using PowerShell, but yes using C# would probably be your best bet. |
I have fiddled with PS/C# and DLLs before. I read through that Go code again and saw references to |
That'd be awesome |
All we need is an array of drive letters and their free space/total space, right? |
Precisely! |
Sweet! I think I have what I need, I’m going to rename the function for drive usage to something like |
Looking forward to it! (if you need to refer a script that uses C#, look no further than PS2Exe; it's one behemoth of an example!) |
I think I got the whole deal working now. |
Following the release of winfetch 2.0.0 or something close to that, I have noticed that winfetch hangs somewhere between printing RAM info and pritnign disk info. I usually Ctrl+C it after about 5 seconds, but I left it running once and PS reported roughly 50 seconds to get through it.
I am using PowerShell 7, winfetch 2.1.0, Windows 10, disk is 1 TB WD Blue SSD.
The text was updated successfully, but these errors were encountered: