navigator.hardwareConcurrency
的属性,可以用来获取CPU的逻辑处理器核心数。
1、navigator.hardwareConcurrency
接口定义:
third_party\blink\renderer\core\frame\navigator_concurrent_hardware.idl
// https://html.spec.whatwg.org/C/#navigator.hardwareconcurrency
interface mixin NavigatorConcurrentHardware {
[HighEntropy=Direct, MeasureAs=NavigatorHardwareConcurrency] readonly attribute unsigned long long hardwareConcurrency;
};
2、navigator.hardwareConcurrency
接口实现:
third_party\blink\renderer\core\frame\navigator_concurrent_hardware.cc
third_party\blink\renderer\core\frame\navigator_concurrent_hardware.h
#include "base/system/sys_info.h"
namespace blink {
unsigned NavigatorConcurrentHardware::hardwareConcurrency() const {
return static_cast<unsigned>(base::SysInfo::NumberOfProcessors());
}
} // namespace blink
3、在NavigatorConcurrentHardware::hardwareConcurrency()函数里面直接修改核心数为120编译看下效果:
unsigned NavigatorConcurrentHardware::hardwareConcurrency() const {
return 120;
//return static_cast<unsigned>(base::SysInfo::NumberOfProcessors());
}
4、调用堆栈:
5、效果:
6、总结:
至此cpu逻辑处理器核心指纹修改完毕。