Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:02:26+00:00 2026-06-08T05:02:26+00:00

I’ve looked at WMI, negative CPU usage value and Timestamp_Sys100NS in past but I

  • 0

I’ve looked at WMI, negative CPU usage value and Timestamp_Sys100NS in past but I am not doing anything with boot time only delta time between two readings.

When CPU usage is very low i.e. System Idle Process shows as 99% I get Negative CPU usage readings.

I’ve adapted the code and formula from an MSDN article but can’t tell why it might be wrong.

http://msdn.microsoft.com/en-us/library/aa392397%28VS.85%29.aspx

The commented out line at the bottom was only giving me results of 0 or 100, I assume this was because of Integer rounding or something similar so I broke it out into separate parts as doubles before dividing.

        ulong N1 = 0;
        ulong D1 = 0;
        ulong N2 = 0;
        ulong D2 = 0;

        ManagementScope scope = new ManagementScope("\\\\" + Machine + "\\root\\cimv2");
        scope.Connect();

        WqlObjectQuery wqlQuery = new WqlObjectQuery("SELECT PercentProcessorTime, TimeStamp_Sys100NS FROM Win32_PerfRawData_PerfOS_Processor Where Name = '_Total'");
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, wqlQuery);

        foreach (ManagementObject proc in searcher.Get())
        {
            N1 = ulong.Parse(proc.Properties["PercentProcessorTime"].Value.ToString());
            D1 = ulong.Parse(proc.Properties["TimeStamp_Sys100NS"].Value.ToString());
        }

        System.Threading.Thread.Sleep(500);

        foreach (ManagementObject proc in searcher.Get())
        {
            N2 = ulong.Parse(proc.Properties["PercentProcessorTime"].Value.ToString());
            D2 = ulong.Parse(proc.Properties["TimeStamp_Sys100NS"].Value.ToString());
        }


        double cpu = N2 - N1;
        double time = D2 - D1;
        var x = (1 - (cpu / time)) * 100;
        //var x = (1 - ((N2 - N1) / (D2 - D1))) * 100;
        context.Response.Write(x);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:02:27+00:00Added an answer on June 8, 2026 at 5:02 am

    I had the exact same problem, I am working with Perl in the example but the logic as you can see below is the same, I used the formula described on that Microsoft document.

    $average = (1 - ( ($n2-$n1) / ($d2-$d1) ) ) * 100;
    

    I tried to solve this for days but in the end I just went for the most obvious solution:

    if ($average <0) { $average = 0; }
    

    In the end if the CPU is very low no one really cares. In my case I was looking for load spikes and long-range loads. Maybe you are interested in small changes I don’t know, to me 1% or 0% is exactly the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.