Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting graphic card information in objective C

I need to get Graphics card information in my application. The information I need is the same as displayed by *system_profiler SPDisplays* command under the section Graphics/Displays:. I have already considered using sysctl(), but I am unable to find proper hardware selector for graphics card in sysctl.h

Any suggestions highly appericiated.

like image 838
rsharma Avatar asked Aug 06 '13 10:08

rsharma


People also ask

How to see what graphics card you have on Linux?

On a GNOME desktop, open the “Settings” dialog, and then click “Details” in the sidebar. In the “About” panel, look for a “Graphics” entry. This tells you what kind of graphics card is in the computer, or, more specifically, the graphics card that's currently in use. Your machine might have more than one GPU.

How to get GPU info in Ubuntu?

The command glxinfo will give you all available OpenGL information for the graphics processor, including its vendor name, if the drivers are correctly installed. To get clock speed information, there is no standard tool.

What's inside GPU?

The GPU. Like a motherboard, a graphics card is a printed circuit board that houses a processor and VRAM. It also has an input/output system (BIOS) chip that stores the card's settings and performs diagnostics on the memory, input and output at startup.


1 Answers

After fiddling with IOKit I have managed to fetch the required information. The code can be seen here (original source)and below:

- (void)displayGraphicsInfo
{
    // Get dictionary of all the PCI Devicces
    CFMutableDictionaryRef matchDict = IOServiceMatching("IOPCIDevice");

    // Create an iterator
    io_iterator_t iterator;

    if (IOServiceGetMatchingServices(kIOMasterPortDefault,matchDict,
                                     &iterator) == kIOReturnSuccess)
    {
        // Iterator for devices found
        io_registry_entry_t regEntry;

        while ((regEntry = IOIteratorNext(iterator))) {
            // Put this services object into a dictionary object.
            CFMutableDictionaryRef serviceDictionary;
            if (IORegistryEntryCreateCFProperties(regEntry,
                                                  &serviceDictionary,
                                                  kCFAllocatorDefault,
                                                  kNilOptions) != kIOReturnSuccess)
            {
                // Service dictionary creation failed.
                IOObjectRelease(regEntry);
                continue;
            }
            const void *GPUModel = CFDictionaryGetValue(serviceDictionary, @"model");

            if (GPUModel != nil) {
                if (CFGetTypeID(GPUModel) == CFDataGetTypeID()) {
                    // Create a string from the CFDataRef.
                    NSString *modelName = [[NSString alloc] initWithData:
                                           (NSData *)GPUModel encoding:NSASCIIStringEncoding];

                    NSLog(@"GPU Model: %@", modelName);
                    [modelName release];
                }
            }
            // Release the dictionary
            CFRelease(serviceDictionary);
            // Release the serviceObject
            IOObjectRelease(regEntry);
        }
        // Release the iterator
        IOObjectRelease(iterator);
    }
}
like image 81
rsharma Avatar answered Nov 01 '22 17:11

rsharma