How to get correctly the percent of used CPU per process

I'm trying to get the percent of used CPU per process on windows with Qt/C++. Firstly i get a list of running processes and after, for each process i try to get the used CPU, for most process the result looks valid (they match with task manager in windows), but with the AIDA64 process (that is running a CPU stress test in background), i got strange values like 312% what is wrong with my c++ code?
    sigar_t *sigarproclist;
    sigar_proc_list_t proclist;
    sigar_open(&sigarproclist);
    sigar_proc_list_get(sigarproclist, &proclist);
    for (size_t i = 0; i < proclist.number; i++)
        sigar_proc_cpu_t cpu;
        int status1 = sigar_proc_cpu_get(sigarproclist, proclist.data[i], &cpu);
        if (status1 == SIGAR_OK)
            Sleep(50);
            int status2 = sigar_proc_cpu_get(sigarproclist, proclist.data[i], &cpu);
            if (status2 == SIGAR_OK)
                sigar_proc_state_t procstate;
                sigar_proc_state_get(sigarproclist, proclist.data[i], &procstate);
                qDebug() << procstate.name << cpu.percent * 100 << "%";
    sigar_close(sigarproclist);

You may need to scale (divide) by the number of cores.  This is the code sigar is using on windows to get the process cpu:
SIGAR_DECLARE(int) sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
                                       sigar_proc_time_t *proctime)
    HANDLE proc = open_process(pid);
    FILETIME start_time, exit_time, system_time, user_time;
    int status = ERROR_SUCCESS;
    if (!proc) {
        return GetLastError();
    if (!GetProcessTimes(proc,
                         &start_time, &exit_time,
                         &system_time, &user_time))
        status = GetLastError();
    CloseHandle(proc);
    if (status != ERROR_SUCCESS) {
        return status;
    if (start_time.dwHighDateTime) {
        proctime->start_time =
            sigar_FileTimeToTime(&start_time) / 1000;
    else {
        proctime->start_time = 0;
    proctime->user = FILETIME2MSEC(user_time);
    proctime->sys  = FILETIME2MSEC(system_time);
    proctime->total = proctime->user + proctime->sys;
    return SIGAR_OK;
The windows api doc indicates that the time here is a sum over all threads and thus will need to be scaled by number of cores.
We had to do something like this in our use of the Java bindings of the 1.6.4 release of SIGAR.  I'm curious to know if this works for you.
Best,
Vishal

Similar Messages

  • Why do I get and how do I correct the message _ This video is only available in the US - when I am in the US - I am trying to view Downton Abbey on my Ipad using the PBS app.?

    why do I get and how do I correct the message _ This video is only available in the US - when I am in the US - I am trying to view Downton Abbey on my Ipad using the PBS ipad app.? Thanks for your help

    Privacy is an Option in the Settings App, its not in Safari as that applies only to Safaris browsing.  Its called Privacy in  IOS 6  In previous versions the same thing can be found under Location Services.

  • My mac book air can't start installation, because i use windows installation in DOS to make partion, now no mac os on it. How to get back the mac os? i have a window based iso image from a friend, because in my country there is no Apple service.

    my mac book air can't start installation, because i use windows installation in DOS to make partion, now no mac os on it. How to get back the mac os? i have a window based iso image from a friend, because in my country there is no Apple service.

    It sounds like you destroyed your boot partition and the recovery partition.  Depending on it's age, your MacBook Air might be able to do a net boot.  Plug and ethernet connection into it and attempt to boot.  If it has the right firmware, it will find a net boot configuration on the net and boot that.  Then it will give you a Recovery Partition like display and allow you to reinstall the OS X version that came with it.... assuming that it was Lion or ML.  If your computer came with Snow Leopard, then even the net boot won't work. 
    At that point you need a bootable USB Key, or an external DVD drive AND a Snow Leopard installation DVD. 
    An Apple Store, if there is one nearby, MAY be able to get you going again.  However, whatever is on the SSD now will be toast too.

  • I never used this program before. I tapped on the "budget form" and decided I'd rather use the "expense form".  I can't figure out how to get to the page that you choose which form you want

    I never used this program before. I tapped on the "budget form" and decided I'd rather use the "expense form".  I can't figure out how to get to the page that you choose which form you want. How would I do that?

    Pct,
    In the Numbers spreadsheets window where all your documents are shown as icons, tap the Plus Sign.
    Choose Create Spreadsheet
    Select the template you want to use
    Jerry

  • I keep getting an error -54 when attempting to back up and restore. How do I correct the issue?

    I keep getting an error -54 when attempting to back up my 4S and restore to my new 5S. How do I correct the issue?

    Can you try again with Firefox 4.0b8 (desktop) and 4.0b3 (Android)? We have changed the way that Sync setup works, and it no longer requires entering the password and sync key by hand.
    For details, see: http://blog.mozilla.com/services/2010/12/22/easy-setup-for-firefox-sync/

  • I had a "pdf export" plan and upgraded it to "pdf pack" plan and it was charged the full price of the new plan in my credit card. How to get back the non used part of the old plan?

    I had a "pdf export" plan and upgraded it to "pdf pack" plan and it was charged the full price of the new plan in my credit card. How to get back the non used part of the old plan?

    Hi edilsoncf,
    I've seen your question on several forums, and responded there. Did you get your subscription sorted out?
    See: How do I get a refund if I have multiple Acrobat service subscriptions?
    Best,
    Sara

  • When I open a pdf file, after a few seconds, it hides the toolbar and I don't know how to get it back.  I use multiple monitors and, without being able to grab the toolbar, I am unable to move the pdf file to a different monitor.  How do I stop this?

    When I open a pdf file, after a few seconds, it hides the toolbar and I don't know how to get it back.  I use multiple monitors and, without being able to grab the toolbar, I am unable to move the pdf file to a different monitor.  How do I stop this?

    Does Firefox switch to full screen if you press F11 ?
    You can also try the F10 key to see if that brings up the menu bar.
    * If the above steps didn't help then see http://kb.mozillazine.org/Corrupt_localstore.rdf
    Note: Do not delete localstore.rdf in the program folder (Windows: "C:\Program Files\Mozilla Firefox\defaults\profile\") (Mac: "/Applications/Firefox.app/defaults/profile/")

  • HT5621 I have changed my apple id recently and the changes have been reflected on my iPad for both the apps store and the iCloud, however, my iphone still insist on using my old apple id for the iCloud while the app store is fine. how can i correct the pr

    I have changed my apple id recently and the changes have been reflected on my iPad for both the apps store and the iCloud, however, my iphone still insist on using my old apple id for the iCloud while the app store is fine. how can i correct the problem?
    Thanks

    Hi Baem_leeds
    Welcome to the Support Communities!
    If you change your Apple ID you will need to sign in with the new information or password the next time you use an Apple service or feature that uses Apple ID. If you have multiple devices that use features and services that require an Apple ID, you will need to sign in again on each device.
    The links below will provide additional information:
    Where can I use my Apple ID?
    http://support.apple.com/kb/HT5616
    Using your Apple ID for Apple services
    http://support.apple.com/kb/HT4895
    iOS: Changing the signed-in iTunes Store Apple ID account
    http://support.apple.com/kb/HT1311
    Cheers,
    Judy

  • Alter a BAPI Result Table, how to get into the display "loop" ?

    Hello all,
    i have a problem regarding the result rows of a RFC/BAPI Call.
    There are three views, let's say 1,2,3. In View 1, i call a BAPI, and display the results in a table in View 2. I added a button in each row, which calls View 3 and displays some details concerning the selected row.
    I now want to store a flag for each row, that has been displayed in this way.
    In View 3 i store the key value of the displayed row in an own value node in the context.
    When i go back from View 3 to View 2, i want to see that flag (in an extra column) in every row, that has been selected in this session.
    So i do not know, how to alter a single row in the BAPI result table, how to get into the "loop" that is used by WD to display the table.
    already tried a supply function, but i was not able to alter single rows.
    Any suggestions/tips or perhaps code fragments of working supply functions ?
    Thank you !

    Hello,
    I'm not sure whether I understood your problem correctly, but I will try to give an answer.
    The easiest way I see is to copy the RFC Results to a Component Controller Context structure with an additional Flag field. You can use WDCopyService for copying.
    Then on the event of selecting you set your flag as appropriate for you (e.g. if you want to use an image as flag you set the Image path) on the current element of your table. Then display View 3.
    On going back View 2 should show now the new flag values...
    The trick is to copy the values (as at Time structures can not be expandend with new fields) and set the Flag on the onSelect event.
    Hope this helps,
    Frank

  • ICloud accidentally set-up with erroneous email acct. How do I reset the email originally used to start the Apple ID? I'm stuck in a loop...

    Hi Apple friends! Here's my frustrating situation. When I got the new computer (2012 Macbook Pro), I tried to set up iCloud but accidentally input an erroneous email acct. I cannot access iClod because the email was accidentally input as "[email protected]", not "[email protected]". How do I reset the email originally used to start the Apple ID? I'm stuck in a loop, and not only cannot use iCloud, but I keep getting messages popping up to register my iCloud with a non-existent email...
    Help?
    Sincerely,
    Cole
    [email protected]

    Have you tried to go into System Preferences > iCloud and entering the correct information there? You will first have to "sign out" of the wrong account and then log in with the correct information.
    If that does not work you should direct follow up to the iCloud for Mac forum.

  • How do you correct the merging of contacts, calendars, etc with other members of your family on your account?

    How do you correct the merging of contacts, calendars, etc with other members of your family on your account?

    Wow!
    I'm not going to be of much use regarding answers but I sure am going to watching this post like a hawk for any replies. My package is a slightly diluted version of this and I do find the BBtalk and data limits hard to make the most of as well.
    If nothing else this totally highlights how complicated BT have managed to make their packages.
    A cynic would assume that they are trying to catch us out at every step and for us to either be overspending or not really getting the moneys worth.

  • Our company has users on both Acrobat X and XI.  We have custom stamps in X that the XI users need to use. How do we transfer the stamps to use in the newer version?

    Our company has users on both Acrobat X and XI.  We have custom stamps in X that the XI users need to use. How do we transfer the stamps to use in the newer version?

    You just copy the stamp files from one machine and place them in the correct directory on the other. You can find the location of both the user and app stamp directories by running the following code in the interactive JavaScript console:
    app.getPath("user", "stamps");
    app.getPath("app", "stamps");
    Select both lines and press Ctrl+Enter (Windows) or cmd+enter (Mac). Here's what I get with this using Acrobat 11 on a Mac:
    user folder: /Macintosh HD/Users/georgejohnson/Library/Application Support/Adobe/Acrobat/11.0/Stamps/
    app folder: /Macintosh HD/Applications/Adobe Acrobat XI Pro/Adobe Acrobat Pro.app/Contents/Built-in/Comments.acroplugin/Stamps/
    The stamp files (PDFs) might have cryptic looking names, but you can safely open each to see what stamps they contain.

  • My itunes can not upgrade. it is looking for athe Itunes.MSI file, but it is unable to find it on the C:drive.  How do I correct the error, and reinstall Itune for my Iphone, Ipad and Ipod?

    My itunes can not upgrade. it is looking for athe Itunes.MSI file, but it is unable to find it on the C:drive.  How do I correct the error, and reinstall Itune for my Iphone, Ipad and Ipod?

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    (2) Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any iTunes entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

  • FAQ: Revel Transition basics: How does this affect the way I use my Adobe software?

    Q: How will this change the way I use my Elements software?
    A: Once you have migrated your files from Photoshop.com to Revel, it will be no longer be possible to sync your photo and video files between your Photoshop Elements Organizer and Photoshop.com.
    If you're using Photoshop Elements 11, you can share your JPEGs from the Elements Organizer to AdobeRevel.com.
    If you’re using Photoshop Elements 10 or earlier version, you won’t be able to directly import from Revel or export to Revel.
    Q: How will this change the way I use Photoshop.com?
    A: Photoshop.com accounts will be remain accessible until the end of the transition period CLICK HERE to see dates and details, but once we begin moving your photos to Revel you will no longer be able to upload photos to your Photoshop.com account.
    After the transition period CLICK HERE to see dates and details, all Photoshop.com accounts will be closed. The Photoshop.com website will remain live and continue to offer product information, trial software downloads, photo editing functionality, customer spotlights, tutorials, and other resources.

    very_nice wrote:
    The suggested advice in this support article http://support.apple.com/kb/HT1478 wasn't a help at all, because the option "enable disc use" in the summary window of itunes doesn't appear.
    *From the article*:
    Products Affected
    iTunes 7 for Mac, iTunes 7 for Windows, iPod nano, iPod shuffle, iPod mini, iPod, iTunes 8 for >Windows, iTunes 8 for Mac
    No mention of the Touch, it works differently from other iPods and has no "disk mode" as such.
    I think it can be used as a storage device by using a 3rd party App, search the the App Store for such items.
    Photos transferred to your Touch via iTunes will be of severely compromised quality i.e 640x480 pixel resolution and file size around 600-700 kb. These can be retrieved, again using a 3rd party application on your computer, such as [Touch Copy|http://www.wideanglesoftware.com/touchcopy> but you will not get back original quality images.
    Good luck,
    Dud.

  • How to get all the values from the dropdown menu

    How to get all the values from the dropdown menu
    I need to be able to extract all values from the dropdown menu; I know how to get all those values as a string, but I need to be able to access each item; (the value in a dropdown menu will change dynamically)
    How do I get number of item is selection dropdown?
    How do I extract a ?name? for each value, one by one?
    How do I change a selection by referring to particular index of the item in a dropdown menu?
    Here is the Path to dropdown menu that I'm trying to access (form contains number of similar dropdowns)
    RSWApp.om.GetElementByPath "window(index=0).form(id=""aspnetForm"" | action=""advancedsearch.aspx"" | index=0).formelement[SELECT](name=""ctl00$MainContent$hardwareBrand"" | id=""ctl00_MainContent_hardwareBrand"" | index=16)", element
    Message was edited by: testtest

    The findElement method allows various attributes to be used to search. Take the following two examples for the element below:
    <Select Name=ProdType ID=testProd>
    </Select>
    I can find the element based on its name or any other attribute, I just need to specify what I am looking for. To find it by name I would do the following:
    Set x = RSWApp.om.FindElement("ProdType","SELECT","Name")
    If I want to search by id I could do the following:
    Set x = RSWApp.om.FindElement("testProd","SELECT","ID")
    Usually you will use whatever is available. Since the select element has no name or ID on the Empirix home page, I used the onChange attribute. You can use any attribute as long as you specify which one you are using (last argument in these examples)
    You can use the FindElement to grab links, text boxes, etc.
    The next example grabs from a link on a page
    Home
    Set x = RSWApp.om.FindElement("Home","A","innerText")
    I hope this helps clear it up.

Maybe you are looking for