473,396 Members | 1,779 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,396 software developers and data experts.

Monitor CPU Usage for 2 processors with active multithreading

4
Hello!

Can somebody give me a hint?

I am trying to obtain the CPU usage for 2 processors (or more ) with active
multithreading. i tried all methods - using the API and using the performance counter and it doesn't work, the results are not like the one's in taskmanager.
I tried getting the _Total or (200 minus Idle time). I will dispose the last try number 7 i guess.

The code is:

PerformanceCounter counter = new PerformanceCounter();
foreach (Process pro in process)
{
counter.CategoryName = "Process";
counter.CounterName = "% Processor Time";
counter.InstanceName = "Idle";
counter.NextValue();
//here i do something to display the MemUsage for some processes
}
System.Threading.Thread.Sleep(1000);
float convert = 200 - counter.NextValue();
TextBox1.Text = convert.ToString();

Can anybody help me please?
Oct 1 '07 #1
2 2221
Plater
7,872 Expert 4TB
Can this be done with WMI?
How would you get performance of the 2 cpu's manually? Like as a human, what would you do to find out?

The values in taskmanger are heavily computed (like a lot of computations are done to produce those numbers I think)
Oct 1 '07 #2
d33a
4
Yes, you are right. This can be done with WMI. Thank you so much :). I think i solved it:
I only have one more question: there are 2 classes - Win32_Processor - the one that i used - and Win32_PerfFormattedData_PerfProc_Process.

I tried solving this with the second one, and the values were always 0 or 100. I found something on the web, but only for scripts. Is there a difference of performance between the 2 classes?

The code is:
ConnectionOptions connection2 = new ConnectionOptions();
ManagementScope ms1 = new ManagementScope("\\\\localhost", connection2);
ObjectQuery query1 = new ObjectQuery("Select LoadPercentage, DeviceID, Name from Win32_Processor");
ManagementObjectSearcher searcher2 = new ManagementObjectSearcher(ms1, query1);
ManagementObjectCollection returncollection2 = searcher2.Get();
ArrayList processor = new ArrayList();
foreach (ManagementObject returnc in returncollection2)
{
processor.Add(returnc["LoadPercentage"].ToString());
processor.Add(returnc["DeviceID"].ToString());
processor.Add(returnc["Name"].ToString());
}

This works ok, but I found a property in the second class - PercentUserTime - that might do the trick. I can't get this thing to work, shows only 0 or 100.
Any sugestions?
Oct 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Vinay C | last post by:
Hi, Can anyone clear me that, when should we use go for mutex, and in which situation should we opt for monitor, lock, semaphone and other objects, in a multithreaded application for synchronization...
1
by: Walter | last post by:
Dear all, i am planing to implement a Windows 2003 Cluster with MS SQl 2000 Enterprise Edition. I have 2 Nodes (4 * XEON MP Processors) with 8 GB RAM per Node. I have the need for 6 SQL...
15
by: Dirk Reske | last post by:
Hello, why doesn't this code work correctly? private int GetCpuUsage(Process proc) { DateTime time1,time2; TimeSpan timediff; double cpu1,cpu2,cpudiff;
6
by: Clark Sann | last post by:
Can someone help me understand what object should be used as the lock object? I've seen some programs that use Monitor.Enter(Me). Then, in those same programs, they sometimes use another object. ...
5
by: shumaker | last post by:
I just read an overview of C# 3.0, and it occured to me that some of these features could make it much easier to write programs that automatically make use of multi core processors. After reading...
2
by: Reny | last post by:
Hi, I want to develop an internet usage monitor program in vb.net and monitor the time the user spend on internet etc. Can any one give me a clue on how to code it? Reny
0
by: mrpincer21 | last post by:
Could anyone help me by telling me how to create an excel document that monitors usage of many others by using visual basic program? I currently produce excel reports for my company but need to...
5
by: soulofstar | last post by:
I want to monitor the CPU and RAM usage using Python, Now, I know how to monitor RAM usage by Python from ctypes import * from ctypes.wintypes import * class MEMORYSTATUS(Structure): ...
2
by: Victory | last post by:
Do i need to use a special class if i need to code on computer with multiple processors. I need to make sure that all of the CPU resources are used to process the code. Is there a way to do this?...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.