Skip to content
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

Reporting wrong CPU usage #24

Open
sky0matic opened this issue Mar 2, 2023 · 10 comments
Open

Reporting wrong CPU usage #24

sky0matic opened this issue Mar 2, 2023 · 10 comments

Comments

@sky0matic
Copy link

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

@jdtemple
Copy link

jdtemple commented Apr 1, 2023

I'm having the same experience.

image

@Razer0123
Copy link

Same issue, used to work before i formatted

@leecollings-sb
Copy link

Same issue here also on Windows.
image

@dwfinkelstein
Copy link

dwfinkelstein commented Dec 4, 2023

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;
}

@fcc48
Copy link

fcc48 commented Dec 22, 2023

Can confirm - same issue here

@FreemoX
Copy link

FreemoX commented Dec 28, 2023

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

@matthewboniface
Copy link

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

@misticx
Copy link

misticx commented Jan 16, 2024

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.

@Venjjeance
Copy link

Venjjeance commented Mar 1, 2024

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.

@danielabbatt
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests