View Javadoc
1   /*
2    * Copyright 2020-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.driver.unix.aix;
6   
7   import java.util.HashMap;
8   import java.util.List;
9   import java.util.Map;
10  
11  import oshi.annotation.concurrent.ThreadSafe;
12  import oshi.util.ExecutingCommand;
13  import oshi.util.ParseUtil;
14  import oshi.util.tuples.Pair;
15  
16  /**
17   * Utility to query lssrad
18   */
19  @ThreadSafe
20  public final class Lssrad {
21  
22      private Lssrad() {
23      }
24  
25      /**
26       * Query {@code lssrad} to get numa node and physical package info
27       *
28       * @return A map of processor number to a pair containing the ref (NUMA equivalent) and srad (package)
29       */
30      public static Map<Integer, Pair<Integer, Integer>> queryNodesPackages() {
31          /*-
32          # lssrad -av
33          REF1        SRAD        MEM        CPU
34          0
35                         0       32749.12    0-63
36                         1        9462.00    64-67 72-75
37                                             80-83 88-91
38          1
39                         2        2471.19    92-95
40          2
41                         3        1992.00
42                         4         249.00
43           */
44          int node = 0;
45          int slot = 0;
46          Map<Integer, Pair<Integer, Integer>> nodeMap = new HashMap<>();
47          List<String> lssrad = ExecutingCommand.runNative("lssrad -av");
48          // remove header
49          if (!lssrad.isEmpty()) {
50              lssrad.remove(0);
51          }
52          for (String s : lssrad) {
53              String t = s.trim();
54              if (!t.isEmpty()) {
55                  if (Character.isDigit(s.charAt(0))) {
56                      node = ParseUtil.parseIntOrDefault(t, 0);
57                  } else {
58                      if (t.contains(".")) {
59                          String[] split = ParseUtil.whitespaces.split(t, 3);
60                          slot = ParseUtil.parseIntOrDefault(split[0], 0);
61                          t = split.length > 2 ? split[2] : "";
62                      }
63                      for (Integer proc : ParseUtil.parseHyphenatedIntList(t)) {
64                          nodeMap.put(proc, new Pair<>(node, slot));
65                      }
66                  }
67              }
68          }
69          return nodeMap;
70      }
71  }