jaypipes / ghw

Go HardWare discovery/inspection library
Apache License 2.0
1.61k stars 174 forks source link

Support ASCII block diagram for cache/topology information #13

Open jaypipes opened 6 years ago

jaypipes commented 6 years ago

After the fix for Issue #11, it became apparent that the String() output for ghw.MemoryCache was less than ideal for visualizing the interconnection between various caches on the CPU socket:

jaypipes@uberbox:~/src/github.com/jaypipes/ghw/ghwc$ go run example.go 
topology SMP (1 nodes)
node #0 (1 cores)
processor core #0 (12 threads), logical processors [0 1 10 11 2 3 4 5 6 7 8 9]
L2 cache (256 KB) shared with logical processors: 10,4
L1i cache (32 KB) shared with logical processors: 2,8
L2 cache (256 KB) shared with logical processors: 2,8
L1d cache (32 KB) shared with logical processors: 3,9
L2 cache (256 KB) shared with logical processors: 3,9
L1i cache (32 KB) shared with logical processors: 1,7
L1i cache (32 KB) shared with logical processors: 10,4
L1d cache (32 KB) shared with logical processors: 10,4
L1i cache (32 KB) shared with logical processors: 3,9
L1i cache (32 KB) shared with logical processors: 0,6
L2 cache (256 KB) shared with logical processors: 0,6
L1d cache (32 KB) shared with logical processors: 2,8
L1d cache (32 KB) shared with logical processors: 0,6
L3 cache (12288 KB) shared with logical processors: 0,1,10,11,2,3,4,5,6,7,8,9
L1d cache (32 KB) shared with logical processors: 11,5
L1i cache (32 KB) shared with logical processors: 11,5
L2 cache (256 KB) shared with logical processors: 11,5
L1d cache (32 KB) shared with logical processors: 1,7
L2 cache (256 KB) shared with logical processors: 1,7

Let's support something a bit more visually useful. Something like this would work:

// +===============================================================================+                                                                                          
// |                                   node 0                                      |                                                                                          
// | +----------+ +----------+ +----------+ +----------+ +----------+ +----------+ |                                                                                          
// | |  core 0  | |  core 6  | |  core 2  | |  core 8  | |  core 5  | |  core 11 | |                                                                                          
// | +----------+ +----------+ +----------+ +----------+ +----------+ +----------| |                                                                                          
// | +-----------------------+ +-----------------------+ +-----------------------+ |                                                                                          
// | |   cache 1(I) - 32K    | |   cache 1(I) - 32K    | |   cache 1(I) - 32K    | |                                                                                          
// | +-----------------------+ +-----------------------+ +-----------------------+ |                                                                                          
// | |   cache 1(D) - 32K    | |   cache 1(D) - 32K    | |   cache 1(D) - 32K    | |                                                                                          
// | +-----------------------+ +-----------------------+ +-----------------------+ |                                                                                          
// | |    cache 2 - 32K      | |    cache 2 - 32K      | |    cache 2 - 32K      | |                                                                                          
// | +-----------------------+ +-----------------------+ +-----------------------+ |                                                                                          
// | +---------------------------------------------------------------------------+ |                                                                                          
// | |                               cache 3 - 12288K                            | |                                                                                          
// | +---------------------------------------------------------------------------+ |                                                                                          
// +===============================================================================+   
ffromani commented 3 years ago

I wonder if a simpler output like the one in the tree utility (https://linux.die.net/man/1/tree) can be a good intermediate step - or even a valid alternative