This information is useful to system administrators who need to monitor system health. This example shows how to enumerate the processor cores and hardware threads in a managed server.

The VMware implementation does not include instances of CIM_ProcessorCapabilities, but cores and hardware threads are modeled with individual instances of CIM_ProcessorCore and CIM_HardwareThread.

This example shows how to locate information about the CPU cores and threads by starting from the Interop namespace and traversing associations from the managed server Scoping Instance. A managed server has one or more processors, each of which has one or more cores with one or more threads. Locating CPU Cores and Hardware Threads shows the relationships of the CIM objects involved. For simplicity, the diagram shows only a single processor with one core and one hardware thread.

Figure 1. Locating CPU Cores and Hardware Threads
Diagram shows path from scoping instance to CIM_HardwareThread.

This pseudocode depends on the pseudocode in Make a Connection to the CIMOM and Identifying the Base Server Scoping Instance.

To report CPU cores and threads

Procedure

  1. Connect to the server URL.

    Specify the Interop namespace, supplied as a parameter, for the connection.

    use wbemlib
    use sys
    use connection renamed cnx
    connection = Null
    
    params = cnx.get_params()
    if params is Null 
       sys.exit(-1)
    interop_params = params
    interop_params['namespace'] = 'root/interop'
    connection = cnx.connect_to_host( interop_params )
    if connection is Null 
       print 'Failed to connect to: ' + params['host'] + ' as user: ' + params['user']
       sys.exit(-1)
  2. Locate the Base Server Scoping Instance of CIM_ComputerSystem.
    use scoping_instance renamed si
    
    scoping_instance_name = si.get_scoping_instance_name( connection )
    if scoping_instance_name is Null
       print 'Failed to find server Scoping Instance.'
       sys.exit(-1)
  3. Traverse the CIM_SystemDevice association to reach the CIM_Processor instances on the managed server.
    proc_instance_names = connection.AssociatorNames( scoping_instance_name, \
                                                      AssocClass = 'CIM_SystemDevice', \
                                                      ResultClass = ’CIM_Processor’ )
    if len( proc_instance_names ) is 0 
       print 'Error:  No processors associated with server Scoping Instance.'
       sys.exit(-1)
  4. For each CIM_Processor instance, print the ElementName, Family, and CurrentClockSpeed properties.
    for proc_instance_name in proc_instance_names
       instance = connection.GetInstance( proc_instance_name )
       print ‘ %s (Family: %s) (%sMHz)’ %
             ( instance[‘ElementName’], instance[‘Family’], instance[‘CurrentClockSpeed’] )
  5. For each CIM_Processor instance, traverse the CIM_ConcreteComponent association to reach the CIM_ProcessorCore instances on the managed server.
    core_instance_names = connection.AssociatorNames( proc_instance_name, \
                                                      AssocClass = 'CIM_ConcreteComponent', \
                                                      ResultClass = ’CIM_ProcessorCore’ )
    if len( core_instance_names ) is 0 
       print 'No processor cores associated with this CPU.’
       sys.exit(-1)
  6. For each CIM_ProcessorCore instance, print the ElementName and CoreEnabledState properties.
    for core_instance_name in core_instance_names
       instance = connection.GetInstance( core_instance_name )
       print ’      %s (%s)’ % \
             ( instance[‘ElementName’], \
               (instance[‘CoreEnabledState’]==’Enabled’)?’Enabled’:’Disabled’ )
  7. For each CIM_ProcessorCore instance, traverse the CIM_ConcreteComponent association to reach the CIM_HardwareThread instances on the managed server.
    thread_instance_names = connection.AssociatorNames( core_instance_name, \
                                                    AssocClass = 'CIM_ConcreteComponent', \
                                                    ResultClass = ’CIM_HardwareThread’ )
    if len( thread_instance_names ) is 0 
       print 'No hardware threads associated with this CPU core.’
       sys.exit(-1)
  8. For each CIM_HardwareThread instance, print the ElementName property.
    for thread_instance_name in thread_instance_names
       instance = connection.GetInstance( thread_instance_name )
       print ‘           %s’ % instance[‘ElementName’]

    A sample of the output looks like the following:

    CPU1 (Family: 179) (2667MHz)
         CPU1 Core 1 (Enabled)
              CPU1 Core 1 Thread 1
         CPU1 Core 2 (Enabled)
              CPU1 Core 2 Thread 1
    CPU2 (Family: 179) (2667MHz)
         CPU2 Core 1 (Enabled)
              CPU1 Core 1 Thread 1
         CPU2 Core 2 (Enabled)
              CPU1 Core 2 Thread 1