streamdeck-cpu icon indicating copy to clipboard operation
streamdeck-cpu copied to clipboard

Reporting wrong CPU usage

Open sky0matic opened this issue 2 years ago • 10 comments

Hi there,

Is this plugin suppose to show the computer's CPU usage ? Because if so, I think there may be an issue somewhere, because it's not reporting the correct usage.

See the screenshots below :

image

image

OS : Windows 11 Pro 22H2 CPU: AMD Ryzen 7 5800U

sky0matic avatar Mar 02 '23 15:03 sky0matic

I'm having the same experience.

image

jdtemple avatar Apr 01 '23 13:04 jdtemple

Same issue, used to work before i formatted

Razer0123 avatar Oct 11 '23 19:10 Razer0123

Same issue here also on Windows. image

leecollings-sb avatar Nov 10 '23 11:11 leecollings-sb

Same. Number that appears does not come close to matching.

It seem the API that is being used for Windows requires averaging over time. The way it is called in this application, is more of an instantaneous CPU usage, and with this API, that will rarely match what is seen in Task Manager.

I don't currently have C++ setup on my dev workstation or I would create a submission.

Here's a sample that might work using WMI instead of the PDH methods being used in the current code.


#include <iostream.h>
#include <comdef.h>
#include <Wbemidl.h>
#pragma comment(lib, "wbemuuid.lib")

class CpuUsageWMI {
private:
    IWbemLocator *locator;
    IWbemServices *services;

public:
    CpuUsageWMI() : locator(nullptr), services(nullptr) {
        CoInitializeEx(0, COINIT_MULTITHREADED);
        CoInitializeSecurity(nullptr, -1, nullptr, nullptr, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, EOAC_NONE, nullptr);
        CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, reinterpret_cast<void**>(&locator));
        locator->ConnectServer(_bstr_t(L"ROOT\\CIMV2"), nullptr, nullptr, 0, nullptr, 0, 0, &services);
    }

    int getCurrentCpuUsage() {
        IEnumWbemClassObject* enumerator = nullptr;
        services->ExecQuery(bstr_t("WQL"), bstr_t("SELECT * FROM Win32_Processor"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, nullptr, &enumerator);

        IWbemClassObject *clsObj = nullptr;
        ULONG uReturn = 0;

        while (enumerator) {
            HRESULT hr = enumerator->Next(WBEM_INFINITE, 1, &clsObj, &uReturn);
            if (0 == uReturn) {
                break;
            }

            VARIANT vtProp;
            hr = clsObj->Get(L"LoadPercentage", 0, &vtProp, 0, 0);
            int cpuUsage = vtProp.intVal;
            VariantClear(&vtProp);

            clsObj->Release();
            return cpuUsage;
        }

        enumerator->Release();
        return -1; // In case of error or no data
    }

    ~CpuUsageWMI() {
        services->Release();
        locator->Release();
        CoUninitialize();
    }
};

int main() {
    try {
        CpuUsageWMI cpuUsage;
        std::cout << "Current CPU Usage: " << cpuUsage.getCurrentCpuUsage() << "%" << std::endl;
    }
    catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
    }
    return 0;
}

dwfinkelstein avatar Dec 04 '23 01:12 dwfinkelstein

Can confirm - same issue here

fcc48 avatar Dec 22 '23 14:12 fcc48

Taskmgr_snR0X7WCDw

Just to jump on the band wagon; can confirm this is an issue. In my case, it seems to report a value closer to its own CPU usage, rather than the total system CPU usage image

FreemoX avatar Dec 28 '23 01:12 FreemoX

+1 same issue for me - elgato CPU consistently reports significantly lower than task manager image

matthewboniface avatar Jan 09 '24 01:01 matthewboniface

Same problem for me, since Rainmeter is also showing a wrong CPU usage, this might have something to do with some Windows 11 update, because both programs stopped working at the same time.

misticx avatar Jan 16 '24 23:01 misticx

I think @FreemoX may be correct. My image only seems to cycle 0 - 1% and after reading through the thread, it does seem to really only show Stream Decks uses with the decimal dropped. If Stream Deck is at 1.8%, it just shows 1% / 0.7% is just 0%; at least anecdotally it matches Stream Deck's own usage. In either case, this isn't working as intended, and as @misticx points out, it is definitely possibly a Win 11 update issue - I've had some other non-Stream Deck processes affected semi-recently by Win 11 updates.

Will be nice to see an update to resolve this.

Venjjeance avatar Mar 01 '24 21:03 Venjjeance

Agreed - this is really poor and pretty much useless now unfortunately.

danielabbatt avatar Mar 12 '24 14:03 danielabbatt