Le 21/06/2013 18:22, Brice Goglin a écrit : > Le 21/06/2013 17:59, Jiri Hladky a écrit : >> Hi Brice, >> >> this would be useful feature for me and I believe also for others! >> Currently > The attached patch puts Misc object in Orange. See how I modified > lstopo.c, you'll see what you have to do. I can easily add the same > check to other types.
Jiri, Does this still matter for you? If you want things to be added in v1.8, please let me know :) The attached patch lets you force the lstopo color of any object in the topology (see the header of the patch). It could be extended to changing the color of an entire level from the lstopo command-line. Brice
commit 26caff4ea5f9f50f5442646625ab2797305db22a Author: Brice Goglin <bgog...@inria.fr> List-Post: hwloc-devel@lists.open-mpi.org Date: Tue Jun 25 15:28:27 2013 +0200 lstopo: add a lstopoColor info attribute to change colors This attribute must be "xx:yy:zz" sets the object RGB color. If it ends with another ",xx:yy:zz", it sets the additional object color (currently only NUMA node memory box color). Numbers are truncated to [0-255] Suggested by Jirka Hladky. diff --git a/utils/lstopo-draw.c b/utils/lstopo-draw.c index cc582c5..6f27549 100644 --- a/utils/lstopo-draw.c +++ b/utils/lstopo-draw.c @@ -416,6 +416,151 @@ lstopo_obj_snprintf(char *text, size_t textlen, hwloc_obj_t obj, int logical) return snprintf(text, textlen, "%s%s", typestr, indexstr); } +static struct draw_methods getmax_draw_methods; + +static void +lstopo_set_object_color(struct draw_methods *methods, hwloc_topology_t topology, + hwloc_obj_t obj, int arg, /* PU status (0=normal, 1=running, 2=forbidden, 3=offline) + * Machine status (0=normal, 1=displayed as a root/System) */ + int *r, int *g, int *b, /* main object colors */ + int *r2, int *g2, int *b2 /* optional object colors, e.g. NUMA node memory box */) +{ + int forcer, forceg, forceb; + const char *color, *comma; + + /* no need to deal with colors when computing max sizes */ + if (methods == &getmax_draw_methods) + return; + + switch (obj->type) { + + case HWLOC_OBJ_MACHINE: + if (arg == 0) { + *r = MACHINE_R_COLOR; + *g = MACHINE_G_COLOR; + *b = MACHINE_B_COLOR; + break; + } + assert(arg == 1); /* Machine printed as a System (when root) */ + /* fallthrough */ + case HWLOC_OBJ_SYSTEM: + *r = SYSTEM_R_COLOR; + *g = SYSTEM_G_COLOR; + *b = SYSTEM_B_COLOR; + break; + + case HWLOC_OBJ_GROUP: + *r = MISC_R_COLOR; + *g = MISC_G_COLOR; + *b = MISC_B_COLOR; + break; + + case HWLOC_OBJ_MISC: + *r = MISC_R_COLOR; + *g = MISC_G_COLOR; + *b = MISC_B_COLOR; + break; + + case HWLOC_OBJ_NODE: + *r = NODE_R_COLOR; + *g = NODE_G_COLOR; + *b = NODE_B_COLOR; + assert(r2); + assert(g2); + assert(b2); + *r2 = MEMORY_R_COLOR; + *g2 = MEMORY_G_COLOR; + *b2 = MEMORY_B_COLOR; + break; + + case HWLOC_OBJ_SOCKET: + *r = SOCKET_R_COLOR; + *g = SOCKET_G_COLOR; + *b = SOCKET_B_COLOR; + break; + + case HWLOC_OBJ_CORE: + *r = CORE_R_COLOR; + *g = CORE_G_COLOR; + *b = CORE_B_COLOR; + break; + + case HWLOC_OBJ_CACHE: + *r = CACHE_R_COLOR; + *g = CACHE_G_COLOR; + *b = CACHE_B_COLOR; + break; + + case HWLOC_OBJ_PU: + switch (arg) { + case 0: + *r = THREAD_R_COLOR; + *g = THREAD_G_COLOR; + *b = THREAD_B_COLOR; + break; + case 1: + *r = RUNNING_R_COLOR; + *g = RUNNING_G_COLOR; + *b = RUNNING_B_COLOR; + break; + case 2: + *r = FORBIDDEN_R_COLOR; + *g = FORBIDDEN_G_COLOR; + *b = FORBIDDEN_B_COLOR; + break; + case 3: + *r = OFFLINE_R_COLOR; + *g = OFFLINE_G_COLOR; + *b = OFFLINE_B_COLOR; + break; + default: + assert(0); + } + break; + + case HWLOC_OBJ_BRIDGE: + *r = BRIDGE_R_COLOR; + *g = BRIDGE_G_COLOR; + *b = BRIDGE_B_COLOR; + break; + + case HWLOC_OBJ_PCI_DEVICE: + *r = PCI_DEVICE_R_COLOR; + *g = PCI_DEVICE_G_COLOR; + *b = PCI_DEVICE_B_COLOR; + break; + + case HWLOC_OBJ_OS_DEVICE: + *r = OS_DEVICE_R_COLOR; + *g = OS_DEVICE_G_COLOR; + *b = OS_DEVICE_B_COLOR; + break; + + default: + assert(0); + } + + /* "xx:yy:zz" force the main object color. + * Optional suffix ",xx:yy:zz" forces the additional object color (e.g. NUMA node memory box). + * Number are truncated to [0-255]. + */ + color = hwloc_obj_get_info_by_name(obj, "lstopoColor"); + if (color) { + if (sscanf(color, "%x:%x:%x", &forcer, &forceg, &forceb) == 3) { + *r = forcer & 255; + *g = forceg & 255; + *b = forceb & 255; + } + comma = strchr(color, ','); + if (comma) + if (sscanf(comma+1, "%x:%x:%x", &forcer, &forceg, &forceb) == 3) { + *r2 = forcer & 255; + *g2 = forceg & 255; + *b2 = forceb & 255; + } + } +} + static void pci_device_draw(hwloc_topology_t topology __hwloc_attribute_unused, struct draw_methods *methods, int logical, hwloc_obj_t level, void *output, unsigned depth, unsigned x, unsigned *retwidth, unsigned y, unsigned *retheight) { @@ -424,6 +569,7 @@ pci_device_draw(hwloc_topology_t topology __hwloc_attribute_unused, struct draw_ unsigned myheight = textheight; unsigned mywidth = 0; unsigned totwidth, totheight; + int rcolor = 0, gcolor = 0, bcolor = 0; char text[64]; int n; @@ -436,7 +582,8 @@ pci_device_draw(hwloc_topology_t topology __hwloc_attribute_unused, struct draw_ RECURSE_RECT(level, &null_draw_methods, gridsize, gridsize); - methods->box(output, PCI_DEVICE_R_COLOR, PCI_DEVICE_G_COLOR, PCI_DEVICE_B_COLOR, depth, x, *retwidth, y, *retheight); + lstopo_set_object_color(methods, topology, level, 0, &rcolor, &gcolor, &bcolor, NULL, NULL, NULL); + methods->box(output, rcolor, gcolor, bcolor, depth, x, *retwidth, y, *retheight); if (fontsize) methods->text(output, 0, 0, 0, fontsize, depth-1, x + gridsize, y + gridsize, text); @@ -452,6 +599,7 @@ os_device_draw(hwloc_topology_t topology __hwloc_attribute_unused, struct draw_m unsigned textwidth = 0; unsigned totheight = gridsize; unsigned totwidth = gridsize; + int rcolor = 0, gcolor = 0, bcolor = 0; int n; if (fontsize) { @@ -464,7 +612,8 @@ os_device_draw(hwloc_topology_t topology __hwloc_attribute_unused, struct draw_m *retwidth = totwidth; *retheight = totheight; - methods->box(output, OS_DEVICE_R_COLOR, OS_DEVICE_G_COLOR, OS_DEVICE_B_COLOR, depth, x, *retwidth, y, *retheight); + lstopo_set_object_color(methods, topology, level, 0, &rcolor, &gcolor, &bcolor, NULL, NULL, NULL); + methods->box(output, rcolor, gcolor, bcolor, depth, x, *retwidth, y, *retheight); if (fontsize) methods->text(output, 0, 0, 0, fontsize, depth-1, x + gridsize, y + gridsize, level->name); @@ -479,13 +628,15 @@ bridge_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical unsigned speedwidth = fontsize ? fontsize + gridsize : 0; unsigned mywidth = 2*gridsize + gridsize + speedwidth; unsigned totwidth, totheight; + int rcolor = 0, gcolor = 0, bcolor = 0; DYNA_CHECK(); RECURSE_VERT(level, &null_draw_methods, gridsize, 0); /* Square and left link */ - methods->box(output, BRIDGE_R_COLOR, BRIDGE_G_COLOR, BRIDGE_B_COLOR, depth, x, gridsize, y + PCI_HEIGHT/2 - gridsize/2, gridsize); + lstopo_set_object_color(methods, topology, level, 0, &rcolor, &gcolor, &bcolor, NULL, NULL, NULL); + methods->box(output, rcolor, gcolor, bcolor, depth, x, gridsize, y + PCI_HEIGHT/2 - gridsize/2, gridsize); methods->line(output, 0, 0, 0, depth, x + gridsize, y + PCI_HEIGHT/2, x + 2*gridsize, y + PCI_HEIGHT/2); if (level->arity > 0) { @@ -538,19 +689,22 @@ pu_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical, hw unsigned myheight = (fontsize ? (fontsize + gridsize) : 0), totheight; unsigned textwidth = fontsize ? 6*fontsize : gridsize; unsigned mywidth = 0, totwidth; + int rcolor = 0, gcolor = 0, bcolor = 0, colorarg; DYNA_CHECK(); RECURSE_RECT(level, &null_draw_methods, 0, gridsize); if (lstopo_pu_offline(level)) - methods->box(output, OFFLINE_R_COLOR, OFFLINE_G_COLOR, OFFLINE_B_COLOR, depth, x, *retwidth, y, *retheight); + colorarg = 3; else if (lstopo_pu_forbidden(level)) - methods->box(output, FORBIDDEN_R_COLOR, FORBIDDEN_G_COLOR, FORBIDDEN_B_COLOR, depth, x, *retwidth, y, *retheight); + colorarg = 2; else if (lstopo_pu_running(topology, level)) - methods->box(output, RUNNING_R_COLOR, RUNNING_G_COLOR, RUNNING_B_COLOR, depth, x, *retwidth, y, *retheight); + colorarg = 1; else - methods->box(output, THREAD_R_COLOR, THREAD_G_COLOR, THREAD_B_COLOR, depth, x, *retwidth, y, *retheight); + colorarg = 0; + lstopo_set_object_color(methods, topology, level, colorarg, &rcolor, &gcolor, &bcolor, NULL, NULL, NULL); + methods->box(output, rcolor, gcolor, bcolor, depth, x, *retwidth, y, *retheight); if (fontsize) { char text[64]; @@ -574,12 +728,14 @@ cache_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical, unsigned textwidth = fontsize ? ((logical ? level->logical_index : level->os_index) == (unsigned) -1 ? 8*fontsize : 10*fontsize) : 0; /* Do not separate objects when in L1 (SMT) */ unsigned separator = level->attr->cache.depth > 1 ? gridsize : 0; + int rcolor = 0, gcolor = 0, bcolor = 0; DYNA_CHECK(); RECURSE_RECT(level, &null_draw_methods, separator, 0); - methods->box(output, CACHE_R_COLOR, CACHE_G_COLOR, CACHE_B_COLOR, depth, x, totwidth, y, myheight - gridsize); + lstopo_set_object_color(methods, topology, level, 0, &rcolor, &gcolor, &bcolor, NULL, NULL, NULL); + methods->box(output, rcolor, gcolor, bcolor, depth, x, totwidth, y, myheight - gridsize); if (fontsize) { char text[64]; @@ -599,12 +755,14 @@ core_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical, unsigned myheight = (fontsize ? (fontsize + gridsize) : 0), totheight; unsigned mywidth = 0, totwidth; unsigned textwidth = fontsize ? 8*fontsize : gridsize; + int rcolor = 0, gcolor = 0, bcolor = 0; DYNA_CHECK(); RECURSE_RECT(level, &null_draw_methods, 0, gridsize); - methods->box(output, CORE_R_COLOR, CORE_G_COLOR, CORE_B_COLOR, depth, x, totwidth, y, totheight); + lstopo_set_object_color(methods, topology, level, 0, &rcolor, &gcolor, &bcolor, NULL, NULL, NULL); + methods->box(output, rcolor, gcolor, bcolor, depth, x, totwidth, y, totheight); if (fontsize) { char text[64]; @@ -623,12 +781,14 @@ socket_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical unsigned myheight = (fontsize ? (fontsize + gridsize) : 0), totheight; unsigned mywidth = 0, totwidth; unsigned textwidth = 6*fontsize; + int rcolor = 0, gcolor = 0, bcolor = 0; DYNA_CHECK(); RECURSE_RECT(level, &null_draw_methods, gridsize, gridsize); - methods->box(output, SOCKET_R_COLOR, SOCKET_G_COLOR, SOCKET_B_COLOR, depth, x, totwidth, y, totheight); + lstopo_set_object_color(methods, topology, level, 0, &rcolor, &gcolor, &bcolor, NULL, NULL, NULL); + methods->box(output, rcolor, gcolor, bcolor, depth, x, totwidth, y, totheight); if (fontsize) { char text[64]; @@ -654,6 +814,8 @@ node_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical, unsigned totwidth; /* Width of the heading text, thus minimal width */ unsigned textwidth = 16*fontsize; + int rcolor = 0, gcolor = 0, bcolor = 0; /* node box */ + int rcolor2 = 0, gcolor2 = 0, bcolor2 = 0; /* mem box */ /* Check whether dynamic programming can save us time */ DYNA_CHECK(); @@ -661,10 +823,11 @@ node_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical, /* Compute the size needed by sublevels */ RECURSE_RECT(level, &null_draw_methods, gridsize, gridsize); + lstopo_set_object_color(methods, topology, level, 0 /* node */, &rcolor, &gcolor, &bcolor, &rcolor2, &gcolor2, &bcolor2); /* Draw the epoxy box */ - methods->box(output, NODE_R_COLOR, NODE_G_COLOR, NODE_B_COLOR, depth, x, totwidth, y, totheight); + methods->box(output, rcolor, gcolor, bcolor, depth, x, totwidth, y, totheight); /* Draw the memory box */ - methods->box(output, MEMORY_R_COLOR, MEMORY_G_COLOR, MEMORY_B_COLOR, depth-1, x + gridsize, totwidth - 2 * gridsize, y + gridsize, myheight - gridsize); + methods->box(output, rcolor2, gcolor2, bcolor2, depth-1, x + gridsize, totwidth - 2 * gridsize, y + gridsize, myheight - gridsize); if (fontsize) { char text[64]; @@ -686,12 +849,14 @@ machine_draw(hwloc_topology_t topology, struct draw_methods *methods, int logica unsigned myheight = (fontsize ? (fontsize + gridsize) : 0), totheight; unsigned mywidth = 0, totwidth; unsigned textwidth = 8*fontsize; + int rcolor = 0, gcolor = 0, bcolor = 0; DYNA_CHECK(); RECURSE_RECT(level, &null_draw_methods, gridsize, gridsize); - methods->box(output, MACHINE_R_COLOR, MACHINE_G_COLOR, MACHINE_B_COLOR, depth, x, totwidth, y, totheight); + lstopo_set_object_color(methods, topology, level, 0 /* machine */, &rcolor, &gcolor, &bcolor, NULL, NULL, NULL); + methods->box(output, rcolor, gcolor, bcolor, depth, x, totwidth, y, totheight); if (fontsize) { char text[64]; @@ -752,6 +917,7 @@ system_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical unsigned mywidth = 0, totwidth; unsigned textwidth = 10*fontsize; int vert = prefer_vert(topology, logical, level, output, depth, x, y, gridsize); + int rcolor = 0, gcolor = 0, bcolor = 0; DYNA_CHECK(); @@ -760,7 +926,8 @@ system_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical else RECURSE_RECT(level, &null_draw_methods, gridsize, gridsize); - methods->box(output, SYSTEM_R_COLOR, SYSTEM_G_COLOR, SYSTEM_B_COLOR, depth, x, totwidth, y, totheight); + lstopo_set_object_color(methods, topology, level, 1 /* system */, &rcolor, &gcolor, &bcolor, NULL, NULL, NULL); + methods->box(output, rcolor, gcolor, bcolor, depth, x, totwidth, y, totheight); if (fontsize) { char text[64]; @@ -783,6 +950,7 @@ group_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical, unsigned mywidth = 0, totwidth; unsigned textwidth = level->name ? strlen(level->name) * fontsize : 6*fontsize; int vert = prefer_vert(topology, logical, level, output, depth, x, y, gridsize); + int rcolor = 0, gcolor = 0, bcolor = 0; DYNA_CHECK(); @@ -798,7 +966,8 @@ group_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical, else RECURSE_RECT(level, &null_draw_methods, gridsize, gridsize); - methods->box(output, MISC_R_COLOR, MISC_G_COLOR, MISC_B_COLOR, depth, x, totwidth, y, totheight); + lstopo_set_object_color(methods, topology, level, 0, &rcolor, &gcolor, &bcolor, NULL, NULL, NULL); + methods->box(output, rcolor, gcolor, bcolor, depth, x, totwidth, y, totheight); if (fontsize) { if (level->name) { @@ -826,6 +995,7 @@ misc_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical, unsigned mywidth = 0, totwidth; unsigned textwidth = level->name ? strlen(level->name) * fontsize : 6*fontsize; int vert = prefer_vert(topology, logical, level, output, depth, x, y, gridsize); + int rcolor = 0, gcolor = 0, bcolor = 0; DYNA_CHECK(); @@ -834,7 +1004,8 @@ misc_draw(hwloc_topology_t topology, struct draw_methods *methods, int logical, else RECURSE_HORIZ(level, &null_draw_methods, gridsize, 0); - methods->box(output, MISC_R_COLOR, MISC_G_COLOR, MISC_B_COLOR, depth, x, totwidth, y, boxheight); + lstopo_set_object_color(methods, topology, level, 0, &rcolor, &gcolor, &bcolor, NULL, NULL, NULL); + methods->box(output, rcolor, gcolor, bcolor, depth, x, totwidth, y, boxheight); if (fontsize) { if (level->name) {