如何在 SQL Server 中获取 CPU 速度?

Mar*_*lli 6 sql-server powershell sql-server-2016 cpu

当我从Glenn Berry运行以下查询时

-- Hardware information from SQL Server 2016  (Query 18) (Hardware Info)
SELECT cpu_count AS [Logical CPU Count], scheduler_count, hyperthread_ratio AS [Hyperthread Ratio],
cpu_count/hyperthread_ratio AS [Physical CPU Count], 
physical_memory_kb/1024 AS [Physical Memory (MB)], committed_kb/1024 AS [Committed Memory (MB)],
committed_target_kb/1024 AS [Committed Target Memory (MB)],
max_workers_count AS [Max Workers Count], affinity_type_desc AS [Affinity Type], 
sqlserver_start_time AS [SQL Server Start Time], virtual_machine_type_desc AS [Virtual Machine Type], 
softnuma_configuration_desc AS [Soft NUMA Configuration],
sql_memory_model_desc -- New in SQL Server 2016 SP1
FROM sys.dm_os_sys_info WITH (NOLOCK) OPTION (RECOMPILE);
------
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

但是,当我使用powershell 时,我会获得更多详细信息在此处输入图片说明

一直舍不得学powershell,不过打算快点接受。。。

同时,问题是:

在 sql server 中有什么方法可以找出处理器的速度(在这种情况下为 2.60 Ghz)?

Eri*_*ing 12

您可以使用xp_cmdshell,或者您可以使用xp_regread. 由于xp_regread“更安全”(我的意思是,您不必更改任何配置选项即可使用它),您可以执行以下操作:

DECLARE @cpu_speed_mhz int,
        @cpu_speed_ghz decimal(18,2);

EXEC master.sys.xp_regread @rootkey = 'HKEY_LOCAL_MACHINE',
                            @key = 'HARDWARE\DESCRIPTION\System\CentralProcessor\0',
                            @value_name = '~MHz',
                            @value = @cpu_speed_mhz OUTPUT;

SELECT @cpu_speed_ghz = CAST(CAST(@cpu_speed_mhz AS DECIMAL) / 1000 AS DECIMAL(18,2));
Run Code Online (Sandbox Code Playgroud)

我在几台不同的计算机上对此进行了测试,它似乎满足了我的需求。它也可能对你有用。

请记住,这xp_regread是没有记录的,并且可能会像微软一样贬低任何东西。

希望这可以帮助!