473,326 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

CPU usage amd memory usage

I am using the following code to get the CPU usage

PerformanceCounter myCounter;
myCounter = new PerformanceCounter();

myCounter.CategoryName = "Processor";
myCounter.CounterName = "% Processor Time";
myCounter.InstanceName = "_Total";

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

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
Oct 10 '06 #1
3 9366

Sirisha wrote:
I am using the following code to get the CPU usage

PerformanceCounter myCounter;
myCounter = new PerformanceCounter();

myCounter.CategoryName = "Processor";
myCounter.CounterName = "% Processor Time";
myCounter.InstanceName = "_Total";

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

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.

Oct 10 '06 #2
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

PerformanceCounter myCounter;
myCounter = new PerformanceCounter();

myCounter.CategoryName = "Processor";
myCounter.CounterName = "% Processor Time";
myCounter.InstanceName = "_Total";

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

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.

Oct 10 '06 #3
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...@hotmail.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
PerformanceCounter myCounter;
myCounter = new PerformanceCounter();
myCounter.CategoryName = "Processor";
myCounter.CounterName = "% Processor Time";
myCounter.InstanceName = "_Total";
for(int i=0; i < 20; i++)
myCounter.NextValue();
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.
Oct 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: rbt | last post by:
Would a Python process consume more memory on a PC with lots of memory? For example, say I have the same Python script running on two WinXP computers that both have Python 2.4.0. One computer has...
2
by: tomvr | last post by:
Hello I have noticed some 'weird' memory usage in a vb.net windows app The situation is as follows I have an app (heavy on images) with 2 forms (actually there are more forms and on starting...
2
by: Jarvis | last post by:
I've made a testing program to test the memory usage of some Data Forms. I create a MDI parent form with one single MDI child form, which is a Data Form generated by .NET Data Form Wizard. To...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
7
by: George Gre | last post by:
Hi, I wrote a c# programme that listens to incoming TCP requests and services them. This programme is meant to be running as long as the server its installed on is running. So we assume for...
20
by: Philip Carnstam | last post by:
How come .Net applications use so much memory? Every application I compile uses at least 10 MB of memory, even the ones consisting of only a form and nothing else. If I minimize them though the...
4
by: RH | last post by:
Hi, I am building a windows application that has a feature that retrieves a set of records when a button is clicked. When the records are being retrieved I experience a complete system...
8
by: Greg Merideth | last post by:
I've written a basic windows service to provide some helper xml functions for my web methods and even thou the service is only about 1k lines long with 1 timer, its mem usage is 10m and its vm mem...
5
by: SDS | last post by:
I am writing an ASP.NET application (in C#) that, as part of a particular response, populates a MemoryStream object with binary data that is being collected from a Process object's StandardOutput. ...
2
by: jld | last post by:
Hi, I developed an asp.net based eCommerce Website for a client and it is hosted at discount asp. The site is quite interactive, queries a database a lot and uses ajax.asp.net to spice up...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.