CPU usage amd memory usage

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sirisha

    CPU usage amd memory usage

    I am using the following code to get the CPU usage

    PerformanceCoun ter myCounter;
    myCounter = new PerformanceCoun ter();

    myCounter.Categ oryName = "Processor" ;
    myCounter.Count erName = "% Processor Time";
    myCounter.Insta nceName = "_Total";

    for(int i=0; i < 20; i++)
    myCounter.NextV alue();

    I ran this progam i am seeing values 0 or 100%, but when i see the task
    manager the CPU usage is 6 to 22 %.

    Am i missing something

    --
    Sirisha
  • Bruce Wood

    #2
    Re: CPU usage amd memory usage


    Sirisha wrote:
    I am using the following code to get the CPU usage
    >
    PerformanceCoun ter myCounter;
    myCounter = new PerformanceCoun ter();
    >
    myCounter.Categ oryName = "Processor" ;
    myCounter.Count erName = "% Processor Time";
    myCounter.Insta nceName = "_Total";
    >
    for(int i=0; i < 20; i++)
    myCounter.NextV alue();
    >
    I ran this progam i am seeing values 0 or 100%, but when i see the task
    manager the CPU usage is 6 to 22 %.
    First of all, 20 reptitions aren't going to show you anything. You need
    to take samples over 20,000, 200,000, or 2,000,000 reptitions, or
    something of that order.

    Second, the task manager is showing you an average CPU usage over
    slices of time. Your program will finish in the blink of an eye and so
    won't really register on the task manager's CPU monitor.

    Third, since your program is doing nothing but processing, clearly
    _while it's running_ it's using up 100% of the CPU, so your results are
    not surprising.

    Comment

    • Sirisha

      #3
      Re: CPU usage amd memory usage

      Hi Bruce,

      I wnat to get the values that the task manager is showing for the memory
      usage and the CPU. How can i do that?
      --
      Sirisha


      "Bruce Wood" wrote:
      >
      Sirisha wrote:
      I am using the following code to get the CPU usage

      PerformanceCoun ter myCounter;
      myCounter = new PerformanceCoun ter();

      myCounter.Categ oryName = "Processor" ;
      myCounter.Count erName = "% Processor Time";
      myCounter.Insta nceName = "_Total";

      for(int i=0; i < 20; i++)
      myCounter.NextV alue();

      I ran this progam i am seeing values 0 or 100%, but when i see the task
      manager the CPU usage is 6 to 22 %.
      >
      First of all, 20 reptitions aren't going to show you anything. You need
      to take samples over 20,000, 200,000, or 2,000,000 reptitions, or
      something of that order.
      >
      Second, the task manager is showing you an average CPU usage over
      slices of time. Your program will finish in the blink of an eye and so
      won't really register on the task manager's CPU monitor.
      >
      Third, since your program is doing nothing but processing, clearly
      _while it's running_ it's using up 100% of the CPU, so your results are
      not surprising.
      >
      >

      Comment

      • Mugunth

        #4
        Re: CPU usage amd memory usage

        you must average out the CPU usage over a time slice.
        CPU is either busy or idle, never 60% busy at anypoint of time.
        When task manager reports 60% usage, it reports that, over a particular
        time slice,
        say 2000 ms, the CPU usage was 100% for 1200 ms.
        It should be interpreted like this.


        Instead of looping 20 times, check CPU usage over a period of time and
        average out your timing.

        Hope that helps...

        Mugunth

        On Oct 11, 1:43 am, Sirisha <spusap...@hotm ail.comwrote:
        Hi Bruce,
        >
        I wnat to get the values that the task manager is showing for the memory
        usage and the CPU. How can i do that?
        --
        Sirisha
        >
        "Bruce Wood" wrote:
        >
        Sirisha wrote:
        I am using the following code to get the CPU usage
        >
        PerformanceCoun ter myCounter;
        myCounter = new PerformanceCoun ter();
        >
        myCounter.Categ oryName = "Processor" ;
        myCounter.Count erName = "% Processor Time";
        myCounter.Insta nceName = "_Total";
        >
        for(int i=0; i < 20; i++)
        myCounter.NextV alue();
        >
        I ran this progam i am seeing values 0 or 100%, but when i see the task
        manager the CPU usage is 6 to 22 %.
        >
        First of all, 20 reptitions aren't going to show you anything. You need
        to take samples over 20,000, 200,000, or 2,000,000 reptitions, or
        something of that order.
        >
        Second, the task manager is showing you an average CPU usage over
        slices of time. Your program will finish in the blink of an eye and so
        won't really register on the task manager's CPU monitor.
        >
        Third, since your program is doing nothing but processing, clearly
        _while it's running_ it's using up 100% of the CPU, so your results are
        not surprising.

        Comment

        Working...