Chromium 中chrome.system.cpu扩展接口定义c++

一、chrome.system.cpu

使用 system.cpu API 查询 CPU 元数据。

权限

system.cpu

类型

CpuInfo

属性
  • archName

    字符串

    处理器的架构名称。

  • 功能

    字符串[]

    一组功能代码,用于表示处理器的部分功能。目前支持的代码包括“mmx”“sse”“sse2”“sse3”“ssse3”“sse4_1”“sse4_2”和“avx”。

  • modelName

    字符串

    处理器的型号名称。

  • numOfProcessors

    number

    逻辑处理器数量。

  • 处理器

    ProcessorInfo[]

    每个逻辑处理器的相关信息。

  • 温度

    数值 []

    Chrome 60 及更高版本

    来自 CPU 每个热区的 CPU 温度读数列表。温度以摄氏度为单位。

    目前仅适用于 ChromeOS。

CpuTime

属性
  • 空闲

    number

    此处理器的累计空闲时间。

  • 内核

    number

    此处理器上的内核程序使用的累计时间。

  • 总计

    number

    此处理器的总累计时间。此值等于用户 + 内核 + 空闲。

  • 用户

    number

    用户空间程序在此处理器上使用的累计时间。

ProcessorInfo

属性
  • 使用量

    CpuTime

    此逻辑处理器的累计使用信息。

方法

getInfo()

<ph type="x-smartling-placeholder"></ph> 承诺

chrome.system.cpu.getInfo(
  callback?: function,
)

查询系统的基本 CPU 信息。

参数
  • callback

    函数(可选)

    callback 参数如下所示:

    (info: CpuInfo) => void

chrome.system.cpu  |  API  |  Chrome for Developers

二、chrome.system.cpu 接口定义c++:

1、system_cpu.idl

extensions\common\api\system_cpu.idl

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Use the <code>system.cpu</code> API to query CPU metadata.
namespace system.cpu {

  // Counters for assessing CPU utilization.  Each field is monotonically
  // increasing while the processor is powered on.  Values are in milliseconds.
  dictionary CpuTime {
    // The cumulative time used by userspace programs on this processor.
    double user;

    // The cumulative time used by kernel programs on this processor.
    double kernel;

    // The cumulative time spent idle by this processor.
    double idle;

    // The total cumulative time for this processor.  This value is equal to
    // user + kernel + idle.
    double total;
  };

  dictionary ProcessorInfo {
    // Cumulative usage info for this logical processor.
    CpuTime usage;
  };

  dictionary CpuInfo {
    // The number of logical processors.
    long numOfProcessors;

    // The architecture name of the processors.
    DOMString archName;

    // The model name of the processors.
    DOMString modelName;

    // A set of feature codes indicating some of the processor's capabilities.
    // The currently supported codes are "mmx", "sse", "sse2", "sse3", "ssse3",
    // "sse4_1", "sse4_2", and "avx".
    DOMString[] features;

    // Information about each logical processor.
    ProcessorInfo[] processors;

    // List of CPU temperature readings from each thermal zone of the CPU.
    // Temperatures are in degrees Celsius.
    //
    // <b>Currently supported on Chrome OS only.</b>
    double[] temperatures;
  };

  callback CpuInfoCallback = void (CpuInfo info);

  interface Functions {
    // Queries basic CPU information of the system.
    [supportsPromises] static void getInfo(CpuInfoCallback callback);
  };
};

2、system_cpu.idl自动生成c++文件:

out\Debug\gen\extensions\common\api\system_cpu.h

out\Debug\gen\extensions\common\api\system_cpu.cc

3、chrome.system.cpu api定义c++:

extensions\browser\api\system_cpu\system_cpu_api.h

extensions\browser\api\system_cpu\system_cpu_api.cc

namespace extensions {

class SystemCpuGetInfoFunction : public ExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("system.cpu.getInfo", SYSTEM_CPU_GETINFO)

  SystemCpuGetInfoFunction() = default;
  SystemCpuGetInfoFunction(const SystemCpuGetInfoFunction&) = delete;
  SystemCpuGetInfoFunction& operator=(const SystemCpuGetInfoFunction&) = delete;

 private:
  ~SystemCpuGetInfoFunction() override = default;

  // ExtensionFunction:
  ResponseAction Run() override;

  void OnGetCpuInfoCompleted(bool success);
};

}  // namespace extensions

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值