Coder Social home page Coder Social logo

gopci's Introduction

gopci

A minimal and fast library to parse pci device info from sysfs.

Go Report Card License Information

Description

This library provides methods to get PCI information on a linux system. It has been created as a minimalistic and more performant alternative to the pci parsing capabilities of jaypipes/ghw.

If you need non-pci or non-linux hardware information, ghw offers an all-in-one solution. If you simply care about linux pci information, this library offers a significant performance benefit over ghw (see comparison).

Usage

Install

go get github.com/hertg/gopci

Scan

devices, _ := pci.Scan()
for _, device := range devices {
	// ...
}

The Device struct contains information like Vendor, Device, Class, Subvendor, Subdevice, etc. More detailed information is made available in the Config field which contains the raw parsed PCI config header.

If more information from sysfs shall be processed, the SysfsPath() method can be used to get a direct link to the PCI devices sysfs path which can be used for further custom information gathering.

Filter

The Scan() method allows optional Filter arguments to only include matching devices in the resulting list of devices.

classFilter := func(d *pci.Device) bool { return d.Class.Class == 0x03 }
devices, _ := pci.Scan(classFilter)

Comparison

Device configuration is parsed directly as bytes (from config) instead of reading strings and parsing from there. This prevents unnecessary string allocationis and significantly improves performance.

It has been found that this library parses at more than 10x the speed while using 50x less memory compared to jaypipes/ghw.

goos: linux
goarch: amd64
pkg: github.com/hertg/gopci/pkg/pci
cpu: AMD Ryzen 9 5950X 16-Core Processor
BenchmarkGoPci
BenchmarkGoPci-32            518           2554827 ns/op          297709 B/op       5178 allocs/op
BenchmarkGhw
BenchmarkGhw-32               34          33286659 ns/op        15745188 B/op     201189 allocs/op
PASS
ok      github.com/hertg/gopci/pkg/pci  2.802s

gopci's People

Contributors

hertg avatar

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.