skip to Main Content

I’m trying to get a human-readable representation of thread siblings.

I have following output: output.

undercloud) [stack@undercloud ~]$ os baremetal introspection data save compute0 |jq '.numa_topology.cpus[] | select(.numa_node == 0) | .thread_siblings'
[
  11,
  51
]
[
  9,
  49
]
[
  58,
  18
],

....
...
..
.

(undercloud) [stack@undercloud ~]$

Common View: Common view.

(undercloud) [stack@undercloud ~]$ os baremetal introspection data save compute0 | jq '.numa_topology.cpus'
[
  {
    "thread_siblings": [
      11,
      51
    ],
    "cpu": 11,
    "numa_node": 0
  },
  {
    "thread_siblings": [
      9,
      49
    ],
    "cpu": 9,
    "numa_node": 0
  },
  {
    "thread_siblings": [
      58,
      18
    ],
    "cpu": 18,
    "numa_node": 0
  },
....
...
..
.
(undercloud) [stack@undercloud ~]$

I want to get next output:

0, 1, 2, 3, 4, ... etc
40 41 42 43 44 ... etc

Is it possible to get such a list using jq? Perhaps with subsequent awk/sed processing.

P.S.: JSON moved to pastebin because the stackoverflow engine thinks my post has little detail and a lot of code, but I think I gave a pretty specific question and it doesn’t fall into the XY problem.

3

Answers


  1. Here’s an approach that sorts each .thread_siblings array, and then the array of all sibling arrays, transposes it to get all first numbers in one array, and all last ones in another, and joins both with a glue string:

    jq -r '
      [.numa_topology.cpus[] | select(.numa_node == 0).thread_siblings | sort]
      | sort | transpose[] | join(", ")
    '
    
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
    40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59
    

    Demo

    Login or Signup to reply.
  2. You’re looking for something like this:

    .numa_topology.cpus | map(
      select(.numa_node == 0) .thread_siblings | sort
    ) | sort | transpose[] | @csv
    
    Login or Signup to reply.
  3. If I understand correctly, here’s another way to do it using --raw-output.

    .numa_topology.cpus
    | map(select(.numa_node == 0).thread_siblings)
    | sort_by(min)
    | map(sort)
    | transpose | .[] | @csv
    

    Example output:

    0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
    40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59
    

    Try it on jqplay.org.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search