1. <i id='aQVFn'><tr id='aQVFn'><dt id='aQVFn'><q id='aQVFn'><span id='aQVFn'><b id='aQVFn'><form id='aQVFn'><ins id='aQVFn'></ins><ul id='aQVFn'></ul><sub id='aQVFn'></sub></form><legend id='aQVFn'></legend><bdo id='aQVFn'><pre id='aQVFn'><center id='aQVFn'></center></pre></bdo></b><th id='aQVFn'></th></span></q></dt></tr></i><div id='aQVFn'><tfoot id='aQVFn'></tfoot><dl id='aQVFn'><fieldset id='aQVFn'></fieldset></dl></div>
          <bdo id='aQVFn'></bdo><ul id='aQVFn'></ul>

      2. <small id='aQVFn'></small><noframes id='aQVFn'>

        <tfoot id='aQVFn'></tfoot><legend id='aQVFn'><style id='aQVFn'><dir id='aQVFn'><q id='aQVFn'></q></dir></style></legend>
      3. 如何在 windows (win32) 上获取每个线程的 CPU 使用率

        时间:2023-05-24
        • <small id='rosEh'></small><noframes id='rosEh'>

            <tbody id='rosEh'></tbody>
              1. <legend id='rosEh'><style id='rosEh'><dir id='rosEh'><q id='rosEh'></q></dir></style></legend>

              2. <i id='rosEh'><tr id='rosEh'><dt id='rosEh'><q id='rosEh'><span id='rosEh'><b id='rosEh'><form id='rosEh'><ins id='rosEh'></ins><ul id='rosEh'></ul><sub id='rosEh'></sub></form><legend id='rosEh'></legend><bdo id='rosEh'><pre id='rosEh'><center id='rosEh'></center></pre></bdo></b><th id='rosEh'></th></span></q></dt></tr></i><div id='rosEh'><tfoot id='rosEh'></tfoot><dl id='rosEh'><fieldset id='rosEh'></fieldset></dl></div>
                <tfoot id='rosEh'></tfoot>

                  <bdo id='rosEh'></bdo><ul id='rosEh'></ul>

                • 本文介绍了如何在 windows (win32) 上获取每个线程的 CPU 使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  寻找 Win32 API 函数、C++ 或 Delphi 示例代码,这些代码告诉我线程(而不是进程的总数)的 CPU 使用率(百分比和/或总 CPU 时间).我有线程 ID.

                  Looking for Win32 API functions, C++ or Delphi sample code that tells me the CPU usage (percent and/or total CPU time) of a thread (not the total for a process). I have the thread ID.

                  我知道 Sysinternals Process Explorer 可以显示此信息,但我的程序中需要此信息.

                  I know that Sysinternals Process Explorer can display this information, but I need this information inside my program.

                  推荐答案

                  在 RRUZ 上面的回答的帮助下,我终于为 Borland Delphi 想出了这个代码:

                  With the help of RRUZ's answer above I finally came up with this code for Borland Delphi:

                  const
                    THREAD_TERMINATE                 = $0001;
                    THREAD_SUSPEND_RESUME            = $0002;
                    THREAD_GET_CONTEXT               = $0008;
                    THREAD_SET_CONTEXT               = $0010;
                    THREAD_SET_INFORMATION           = $0020;
                    THREAD_QUERY_INFORMATION         = $0040;
                    THREAD_SET_THREAD_TOKEN          = $0080;
                    THREAD_IMPERSONATE               = $0100;
                    THREAD_DIRECT_IMPERSONATION      = $0200;
                    THREAD_SET_LIMITED_INFORMATION   = $0400;
                    THREAD_QUERY_LIMITED_INFORMATION = $0800;
                    THREAD_ALL_ACCESS                = STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or $03FF;
                  
                  function OpenThread(dwDesiredAccess: DWord;
                                      bInheritHandle: Bool;
                                      dwThreadId: DWord): DWord; stdcall; external 'kernel32.dll';
                  
                  
                  procedure TForm1.Button1Click(Sender: TObject);
                  var iii:integer;
                      handle:thandle;
                      creationtime,exittime,kerneltime,usertime:filetime;
                  begin
                    Handle:=OpenThread(THREAD_SET_INFORMATION or THREAD_QUERY_INFORMATION, False, windows.GetCurrentThreadId);
                    if handle<>0 then
                    begin
                      getthreadtimes(Handle,creationtime,exittime,kerneltime,usertime);
                      label1.caption:='Total time for Thread #'+inttostr(windows.GetCurrentThreadId)+': '+inttostr( (int64(kerneltime)+int64(usertime)) div 1000 )+' msec';
                      CloseHandle(Handle);
                    end;
                  end;
                  

                  这篇关于如何在 windows (win32) 上获取每个线程的 CPU 使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:C++ 全局变量声明 下一篇:将 C/C++ dll 头文件转换为 Delphi 的最佳资源?

                  相关文章

                  最新文章

                    <i id='GCuur'><tr id='GCuur'><dt id='GCuur'><q id='GCuur'><span id='GCuur'><b id='GCuur'><form id='GCuur'><ins id='GCuur'></ins><ul id='GCuur'></ul><sub id='GCuur'></sub></form><legend id='GCuur'></legend><bdo id='GCuur'><pre id='GCuur'><center id='GCuur'></center></pre></bdo></b><th id='GCuur'></th></span></q></dt></tr></i><div id='GCuur'><tfoot id='GCuur'></tfoot><dl id='GCuur'><fieldset id='GCuur'></fieldset></dl></div>
                  1. <small id='GCuur'></small><noframes id='GCuur'>

                    1. <tfoot id='GCuur'></tfoot>
                      • <bdo id='GCuur'></bdo><ul id='GCuur'></ul>
                      <legend id='GCuur'><style id='GCuur'><dir id='GCuur'><q id='GCuur'></q></dir></style></legend>