From a0893edf184aa760236e30e08f0e40154bb405c6 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sun, 19 Jun 2022 14:53:12 -0700 Subject: feat(tools/numap): add a tool to report NUMA topology of a host The tool maps the various PCI devices to the NUMA node they are attached to and print the result to STDOUT in JSON. Only ethernet, NVMe and GPU devices are accounted for at the moment. Change-Id: If32c805e61211f0ef4838a82eabc70d7fc1985fe Reviewed-on: https://cl.fcuny.net/c/world/+/453 Tested-by: CI Reviewed-by: Franck Cuny --- tools/numap/internal/sysfs/parse.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tools/numap/internal/sysfs/parse.go (limited to 'tools/numap/internal/sysfs/parse.go') diff --git a/tools/numap/internal/sysfs/parse.go b/tools/numap/internal/sysfs/parse.go new file mode 100644 index 0000000..d518653 --- /dev/null +++ b/tools/numap/internal/sysfs/parse.go @@ -0,0 +1,21 @@ +package sysfs + +import ( + "io/ioutil" + "strconv" + "strings" +) + +// ContentUint64 parses the content of a file in sysfs, and convert +// from hex to uint64. +func ContentUint64(path string) (uint64, error) { + content, err := ioutil.ReadFile(path) + if err != nil { + return 0, err + } + result, err := strconv.ParseUint(strings.TrimSpace(string(content)), 0, 64) + if err != nil { + return 0, err + } + return result, nil +} -- cgit v1.2.3