Solved

CPU usage

Posted on 2003-11-14
19
589 Views
Last Modified: 2010-04-05
Hi,

Taskmanager displays the usage percentage of the CPUs. How can I get the same info from my code?

Regards, GD
0
Comment
Question by:goodday
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 5
  • +1
19 Comments
 
LVL 8

Expert Comment

by:gmayo
ID: 9751399
Have a look at the component on this page at the top: http://www.torry.net/systeminfo.htm

Geoff M.
0
 

Accepted Solution

by:
13_th earned 200 total points
ID: 9754685
0
 

Expert Comment

by:Shinez
ID: 9758280
This will sort your problem :)

type
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);

  public
    s1,s2:int64;

implementation

{$R *.dfm}
type
  TProcessorTimeInfo = record
    IdleTime: int64;
    KernelTime: int64;
    UserTime: int64;
    DpcTime: int64;
    InterruptTime:int64;
    InterruptCount:cardinal;
  end;

function NtQuerySystemInformation(si_class: cardinal; si: pointer; si_length: cardinal; ret_length:cardinal):cardinal; stdcall; external 'ntdll.dll';

procedure TForm1.Timer1Timer(Sender: TObject);
var
  buf:array[0..299999] of char;
  //pi: ^TProcessInfo;
  ti: ^TProcessorTimeInfo;
  i:integer;
begin
timer1.Interval:=1000;
  NtQuerySystemInformation(8, @buf, 300000, 0);

  ti:=@buf;
  s2:=ti^.KernelTime+ti^.UserTime{+ti^.DpcTime+ti^.InterruptTime}-ti^.IdleTime;
 
  i:=round((s2-s1)/100000);
  s1:=s2;
  StatusBar1.Panels[0].Text:='CPU: '+inttostr(i)+'%';
end;

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:13_th
ID: 9758319
TO Shinez

not STEAL!

0
 

Expert Comment

by:Shinez
ID: 9758326
*** off topic comment removed by Netminder, EE Admin ***
0
 

Expert Comment

by:13_th
ID: 9758354
TO Shinez


brought by you code from my example.
this example is not in knowledge.
he is written by me
0
 

Expert Comment

by:Shinez
ID: 9758368
*** off topic comment removed by Netminder, EE Admin ***
0
 

Expert Comment

by:13_th
ID: 9758405
TO Shinez

using someone else work indicate this.

copyrights did not canceal
0
 

Expert Comment

by:Shinez
ID: 9758430
*** off topic comment removed by Netminder, EE Admin ***
0
 

Expert Comment

by:13_th
ID: 9758482
To talk to cretins, to not respect myself . Conversation is finished.
0
 

Expert Comment

by:Shinez
ID: 9758484
kool :)
0
 

Author Comment

by:goodday
ID: 9758518
13_th

I appreciate your trying to help.

I think any work done by a programmer that creates value is worth for money. It is a very unselfish and generous act to share some results of your own creativity with other people.
 
No one should judge you, or tell a singe bad thing about you for NOT sharing the result of your own work, but you really have to understand, that once you share it, you donate it to everybody else. It becomes public property. If you do not limit how it can be used and copied then everyone is allowed to use it for any purpose, and use it, as his own code. Even share it with other people.

ALL RESPECTS will always belong to you for being able to create, and for sharing your code. But most people will probably never say thank you to you, because they will never know the original creator.

I think you also have to understand, that at Experts-Exchange the person who first provides the information is prized by points, not the original source. This place is about information sharing. The one who does it faster and better takes the prize.

I personally highly appreciate everyone who is willing and able to help, and I try to give some points to everybody who provides any useful information.

In this particular case, your help was very useful to me, the points go to you.

Many thanks, GD.
0
 

Author Comment

by:goodday
ID: 9758525
Shinez

Thanks for trying to help.

Please give some time to 13_th to understand how things work here .... :)

Best Regards, GD
0
 

Expert Comment

by:Shinez
ID: 9758535
thats kool :) we all here 2 help each other.
0
 

Expert Comment

by:13_th
ID: 9758553
to goodday

not against use of my code basically. I think not correct use of my work in this case Shinez
0
 

Author Comment

by:goodday
ID: 9758560
Shinez

One more thing: I think it is fair and nice that  you try to help me to undestand 13_th's code better. Though the source he/she provided, was enough for me. It was a complete answer to my question, thats why I gave the points to him/her.

Good Luck, GD  
0
 

Author Comment

by:goodday
ID: 9758620
13_th

As I understand Shinez did not mean to provide your code as if it was his/her own. He/She must have taken a look at the source and copied to EE the part of it, which actually holds the answer. Just to highlight the important parts. It was no question, that the real work was done by you. Shinez only tried to save some time to me by doing this. Which is also very nice from him/her. :)

I think you both simply misunderstood each others point of view.

I appreciate both of you for being here on a Sunday afternoon.

Best Regards, GD.
0
 

Expert Comment

by:Shinez
ID: 9758673
*** off topic comment removed by Netminder, EE Admin ***
0
 

Author Comment

by:goodday
ID: 9759826
Shinez

" .. blue sky and everything.. " - :)
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question