You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 11下CPU线程及进程时间统计异常的已知解决办法有哪些?

Windows 11 CPU时间统计异常问题求助

目前有大量Windows 11下CPU使用率统计异常的反馈,该问题同样影响CPU进程及线程时间统计。升级至Windows 11后,测得的CPU time远小于wall clock time,我使用的是12代英特尔酷睿处理器。

我的CPU时间统计代码实现

#include <chrono>
#include <iostream>
#include "windows.h"
#include "processthreadsapi.h"

// Returns CPU process time in milliseconds
static long long get_cpu_time()
{
    union FiletimeUnion
    {
        FILETIME  as_filetime;
        long long as_llong;
    };

    // Get process user and kernel times
    FILETIME create_time, exit_time;
    FiletimeUnion user_time, kernel_time;
    GetProcessTimes(GetCurrentProcess(), &create_time, &exit_time, &kernel_time.as_filetime, &user_time.as_filetime);

    // Return sum of user and kernel times in milliseconds
    return (user_time.as_llong + kernel_time.as_llong) / 10000;
}

int main()
{
    // Measure start times
    const auto cpu_time_start = get_cpu_time();
    const auto wall_time_start = std::chrono::steady_clock::now();

    // Run application with a single thread
    // ...

    // Measure end times
    const auto cpu_time_end = get_cpu_time();
    const auto wall_time_end = std::chrono::steady_clock::now();

    // Get elapsed times in milliseconds
    const auto cpu_time_in_ms = static_cast<double>(cpu_time_end - cpu_time_start);
    const auto wall_time_in_ms = std::chrono::duration_cast<std::chrono::milliseconds>(wall_time_end - wall_time_start).count();

    std::cout << "CPU time:      " << cpu_time_in_ms << " ms" << std::endl;
    std::cout << "Wall time:     " << wall_time_in_ms << " ms" << std::endl;

    return 0;
}

测试结果

CPU time:      1468 ms
Wall time:     6900 ms

这个结果明显不符合预期。

已尝试的方案

我尝试过部分监控软件采用的基于CPU空闲使用率的 workaround:通过进程空闲使用率的倒数计算进程使用率,再结合wall clock time计算CPU time。该方案在CPU未满载时效果良好,但在高负载场景下失效。

求助问题

Windows 11下CPU时间统计异常是否有已知的解决办法?

内容的提问来源于stack exchange,提问作者TroubleWithTribbles

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 15:03:24