Code Monkey home page Code Monkey logo

icpuid's Introduction


What is iCPUID?

iCPUID is a lightweight cross-platform implementation that allows us to obtain the CPUID information.

Works on Windows, Mac and Linux

Install via NuGet

NuGet Version

Install via PowerShell

Now if you want you can use iCPUID from PowerShell. It has the iPowerShellCpuid module available that contains a collection of Cmdlets that allow us to obtain the CPUID information. If you want to know more, please review the available documentation from here.

  • From PowerShellGallery
PowerShellGallery Version
  • From PowerShell console

PM> Install-Module -Name iPowerShellCpuid

Usage

Call CPUID.Instance.Leafs for getting all CPUID implemented leafs.

Examples

  1. Detection of the availability of the CPUID instruction.

    CPUID cpuid = CPUID.Instance;
    Console.WriteLine($@" Is Available > {cpuid.IsAvailable}");
    
  2. Gets and prints all CPUID implemented leafs.

    CPUID cpuid = CPUID.Instance;
    ReadOnlyCollection<Leaf> leafs = cpuid.ImplementedLeafs;
    foreach (Leaf leaf in leafs)
    {
        Console.WriteLine($@" {(int)leaf:X8}-{leaf}");
    }
    
  3. Gets and prints all CPUID implemented leafs > sub-leafs.

    CPUID cpuid = CPUID.Instance;
    ReadOnlyCollection<Leaf> leafs = cpuid.ImplementedLeafs;
    foreach (var (leaf, subLeafs) in leafs)
    {
        Console.WriteLine($@" > {leaf} (EAX={(int)leaf:X8})");
    
        foreach (var subLeaf in subLeafs)
        {
            Console.WriteLine($@"   > {subLeaf.SubLeaf} (ECX={(int)subLeaf.SubLeaf:X8})");
        }
    }
    
  4. Gets and prints all CPUID implemented leafs > sub-leafs (shows description).

    CPUID cpuid = CPUID.Instance;
    ReadOnlyCollection<Leaf> leafs = cpuid.ImplementedLeafs;
    foreach (var (leaf, subLeafs) in leafs)
    {
        Console.WriteLine($@" > {leaf} (EAX={(int)leaf:X8})");
    
        foreach (var subLeaf in subLeafs)
        {
            Console.WriteLine($@"   > {subLeaf.SubLeaf} (ECX={(int)subLeaf.SubLeaf:X8})");
            IEnumerable<IPropertyKey> properties = subLeaf.ImplementedProperties;
            foreach (var property in properties)
            {
                string friendlyName = GetFriendlyName(property);
                PropertyUnit unit = property.PropertyUnit;
                string description = property.GetPropertyDescription();
    
                Console.WriteLine($@"     > {friendlyName} {(unit == PropertyUnit.None ? string.Empty : $"({unit})")}: {description}");
            }
        }
    }
    
  5. Gets and prints all CPUID implemented leafs > sub-leafs (values).

    CPUID cpuid = CPUID.Instance;
    ReadOnlyCollection<Leaf> leafs = cpuid.ImplementedLeafs;
    foreach (var (leaf, subLeafs) in leafs)
    {
        Console.WriteLine($@" > {leaf} (EAX={(int)leaf:X8})");
    
        foreach (var subLeaf in subLeafs)
        {
            Console.WriteLine($@"   > {subLeaf.SubLeaf} (ECX={(int)subLeaf.SubLeaf:X8})");
            IEnumerable<IPropertyKey> properties = subLeaf.ImplementedProperties;
            foreach (var property in properties)
            {
                QueryPropertyResult queryResult = subLeaf.GetProperty(property);
                PropertyItem propertyItem = queryResult.Value;
                object value = propertyItem.Value;
                string friendlyName = GetFriendlyName(property);
                PropertyUnit valueUnit = property.PropertyUnit;
                string unit = valueUnit == PropertyUnit.None ? string.Empty : valueUnit.ToString();
    
                if (value == null)
                {
                    Console.WriteLine($@"     > {friendlyName}: NULL");
                    continue;
                }
    
                if (value is bool)
                {
                    Console.WriteLine($@"     > {friendlyName}: {value} [{((bool)value ? 1 : 0)}]");
                }
                else if (value is string)
                {
                    Console.WriteLine($@"     > {friendlyName}: {value} {unit}");
                }
                else if (value is byte)
                {
                    Console.WriteLine($@"     > {friendlyName}: {value} {unit} [{value:X2}h]");
                }
                else if (value is int)
                {
                    Console.WriteLine($@"     > {friendlyName}: {value} {unit} [{value:X4}h]");
                }
                else if (value is uint)
                {
                    Console.WriteLine($@"     > {friendlyName}: {value} {unit} [{value:X4}h]");
                }
                else if (value is ulong)
                {
                    Console.WriteLine($@"     > {friendlyName}: {value} {unit} [{value:X8}h]");
                }
                else if (value.GetType() == typeof(ReadOnlyCollection<string>))
                {
                    Console.WriteLine($@"     > {friendlyName}");
                    var collection = (ReadOnlyCollection<string>)value;
                    foreach (var entry in collection)
                    {
                        Console.WriteLine($@"       > {entry} {unit}");
                    }
                }
                else
                {
                    Console.WriteLine($@"     > {friendlyName}: {value} {unit}");
                }
            }
        }
    }
    
  6. Gets a single property directly.

    CPUID cpuid = CPUID.Instance;
    QueryPropertyResult manufacturerQueryResult = cpuid.Leafs.GetProperty(LeafProperty.BasicInformation.Manufacturer);
    if (manufacturerQueryResult.Success)
    {
        Console.WriteLine($@" > Manufacturer: {manufacturerQueryResult.Value.Value}");
    }
    
    QueryPropertyResult avx2 = cpuid.Leafs.GetProperty(LeafProperty.ExtendedFeatures.AVX2);
    if (avx2.Success)
    {
        Console.WriteLine($@" > AVX2: {avx2.Value.Value}");
    }
    
  7. Gets a property in multiple elements directly.

    CPUID cpuid = CPUID.Instance;
    QuerySubLeafPropertyCollectionResult cacheSizesQueryResult = leafs.GetProperties(LeafProperty.DeterministicCacheParameters.CacheSize);
    if (cacheSizesQueryResult.Success)
    {
        CpuidSubLeafDictionary cacheSizes = cacheSizesQueryResult.Value;
        bool hasCacheSizesEntries = cacheSizes.Any();
        if (!hasCacheSizesEntries)
        {
            Console.WriteLine($@" > Sorry, The 'LeafProperty.DeterministicCacheParameters.CacheSize' property has not implementes on this system");
        }
        else
        {
            foreach (var (subLeaf, propertyItem) in cacheSizes)
            {
                Console.WriteLine($@" > Cache Size:  ({subLeaf}) > {propertyItem.Value}");
            }
        }
    }
    

Documentation

  • For full code documentation, please see next link documentation.

How can I send feedback!!!

If you have found iCPUID useful at work or in a personal project, I would love to hear about it. If you have decided not to use iCPUID, please send me and email stating why this is so. I will use this feedback to improve iCPUID in future releases.

My email address is

email.png

icpuid's People

Contributors

iajtin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

icpuid's Issues

Strange Design

This library is very well packaged, but not applicable to my scenario. I want to use the cpuid to determine if the program is running in the virtual machine, but the library doesn't read the 31 bits of leaf 0x1, a very strange design.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.