static void output_console_obj (hwloc_topology_t topology, hwloc_obj_t l, FILE *output, int logical, int verbose_mode) { char type[32], *attr, phys[32] = ""; unsigned idx = logical ? l->logical_index : l->os_index; const char *indexprefix = logical ? " L#" : " P#"; if (lstopo_show_cpuset < 2) { int len; if (l->type == HWLOC_OBJ_MISC && l->name) fprintf(output, "%s", l->name); else { hwloc_obj_type_snprintf (type, sizeof(type), l, verbose_mode-1); fprintf(output, "%s", type); } if (l->depth != 0 && idx != (unsigned)-1 && l->type != HWLOC_OBJ_PCI_DEVICE && (l->type != HWLOC_OBJ_BRIDGE || l->attr->bridge.upstream_type == HWLOC_OBJ_BRIDGE_HOST)) fprintf(output, "%s%u", indexprefix, idx); if (logical && l->os_index != (unsigned) -1 && (verbose_mode >= 2 || l->type == HWLOC_OBJ_PU || l->type == HWLOC_OBJ_NODE)) snprintf(phys, sizeof(phys), "P#%u", l->os_index); len = hwloc_obj_attr_snprintf (NULL, 0, l, " ", verbose_mode-1); attr = malloc(len+1); *attr = '\0'; hwloc_obj_attr_snprintf (attr, len+1, l, " ", verbose_mode-1); if (*phys || *attr) { const char *separator = *phys != '\0' && *attr!= '\0' ? " " : ""; fprintf(output, " (%s%s%s)", phys, separator, attr); } free(attr); if ((l->type == HWLOC_OBJ_OS_DEVICE || verbose_mode >= 2) && l->name && l->type != HWLOC_OBJ_MISC) fprintf(output, " \"%s\"", l->name); } if (!l->cpuset) return; if (lstopo_show_cpuset == 1) fprintf(output, " cpuset="); if (lstopo_show_cpuset) { char *cpusetstr; if (lstopo_show_taskset) hwloc_bitmap_taskset_asprintf(&cpusetstr, l->cpuset); else hwloc_bitmap_asprintf(&cpusetstr, l->cpuset); fprintf(output, "%s", cpusetstr); free(cpusetstr); } /* annotate if the PU is forbidden/offline/running */ if (l->type == HWLOC_OBJ_PU && verbose_mode >= 2) { if (lstopo_pu_offline(l)) printf(" (offline)"); else if (lstopo_pu_forbidden(l)) printf(" (forbidden)"); else if (lstopo_pu_running(topology, l)) printf(" (running)"); } }
static void pu_draw(struct lstopo_output *loutput, struct draw_methods *methods, hwloc_obj_t level, unsigned depth, unsigned x, unsigned *retwidth, unsigned y, unsigned *retheight) { hwloc_topology_t topology = loutput->topology; int logical = loutput->logical; unsigned gridsize = loutput->gridsize; unsigned fontsize = loutput->fontsize; unsigned myheight = (fontsize ? (fontsize + gridsize) : 0), totheight; unsigned textwidth = gridsize; unsigned mywidth = 0, totwidth; unsigned textxoffset = 0; char text[64]; int n; struct style style; int colorarg; DYNA_CHECK(); if (fontsize) { n = lstopo_obj_snprintf(text, sizeof(text), level, logical); textwidth = get_textwidth(loutput, methods, text, n, fontsize, gridsize); /* if smaller than other PU, artificially extend/shift it * to make PU boxes nicer when vertically stacked. */ if (textwidth < loutput->min_pu_textwidth) { textxoffset = (loutput->min_pu_textwidth - textwidth) / 2; textwidth = loutput->min_pu_textwidth; } } RECURSE_RECT(level, &null_draw_methods, 0, gridsize); if (lstopo_pu_forbidden(level)) colorarg = 2; else if (lstopo_pu_running(loutput, level)) colorarg = 1; else colorarg = 0; lstopo_set_object_color(methods, topology, level, colorarg, &style); methods->box(loutput, style.bg.r, style.bg.g, style.bg.b, depth, x, *retwidth, y, *retheight); if (fontsize) { methods->text(loutput, style.t.r, style.t.g, style.t.b, fontsize, depth-1, x + gridsize + textxoffset, y + gridsize, text); } RECURSE_RECT(level, methods, 0, gridsize); DYNA_SAVE(); }
static void output_console_obj (hwloc_topology_t topology, hwloc_obj_t l, FILE *output, int logical, int verbose_mode, int collapsed) { unsigned idx = logical ? l->logical_index : l->os_index; const char *value; char pidxstr[16] = "P#[collapsed]"; char lidxstr[16] = "L#[collapsed]"; if (!collapsed || l->type != HWLOC_OBJ_PCI_DEVICE) { snprintf(pidxstr, sizeof(pidxstr), "P#%u", l->os_index); snprintf(lidxstr, sizeof(lidxstr), "L#%u", l->logical_index); } if (lstopo_show_cpuset < 2) { char type[64], *attr, phys[32] = ""; int len; value = hwloc_obj_get_info_by_name(l, "Type"); hwloc_obj_type_snprintf (type, sizeof(type), l, verbose_mode-1); if (value) fprintf(output, "%s(%s)", type, value); else fprintf(output, "%s", type); if (l->depth != 0 && idx != (unsigned)-1 && l->type != HWLOC_OBJ_MISC && l->type != HWLOC_OBJ_PCI_DEVICE && (l->type != HWLOC_OBJ_BRIDGE || l->attr->bridge.upstream_type == HWLOC_OBJ_BRIDGE_HOST)) fprintf(output, " %s", logical ? lidxstr : pidxstr); if (l->name && (l->type == HWLOC_OBJ_MISC || l->type == HWLOC_OBJ_GROUP)) fprintf(output, " %s", l->name); if (logical && l->os_index != (unsigned) -1 && (verbose_mode >= 2 || l->type == HWLOC_OBJ_PU || l->type == HWLOC_OBJ_NUMANODE)) snprintf(phys, sizeof(phys), "%s", pidxstr); /* display attributes */ len = hwloc_obj_attr_snprintf (NULL, 0, l, " ", verbose_mode-1); attr = malloc(len+1); *attr = '\0'; hwloc_obj_attr_snprintf (attr, len+1, l, " ", verbose_mode-1); if (*phys || *attr) { const char *separator = *phys != '\0' && *attr!= '\0' ? " " : ""; fprintf(output, " (%s%s%s)", phys, separator, attr); } free(attr); /* display the root total_memory if not verbose (already shown) * and different from the local_memory (already shown) */ if (verbose_mode == 1 && !l->parent && l->memory.total_memory > l->memory.local_memory) fprintf(output, " (%lu%s total)", (unsigned long) hwloc_memory_size_printf_value(l->memory.total_memory, 0), hwloc_memory_size_printf_unit(l->memory.total_memory, 0)); /* append the name */ if (l->name && (l->type == HWLOC_OBJ_OS_DEVICE || verbose_mode >= 2) && l->type != HWLOC_OBJ_MISC && l->type != HWLOC_OBJ_GROUP) fprintf(output, " \"%s\"", l->name); } if (!l->cpuset) return; if (lstopo_show_cpuset == 1) fprintf(output, " cpuset="); if (lstopo_show_cpuset) { char *cpusetstr; if (lstopo_show_taskset) hwloc_bitmap_taskset_asprintf(&cpusetstr, l->cpuset); else hwloc_bitmap_asprintf(&cpusetstr, l->cpuset); fprintf(output, "%s", cpusetstr); free(cpusetstr); } /* annotate if the PU is forbidden/running */ if (l->type == HWLOC_OBJ_PU && verbose_mode >= 2) { if (lstopo_pu_forbidden(l)) fprintf(output, " (forbidden)"); else if (lstopo_pu_running(topology, l)) fprintf(output, " (running)"); } }
static void lstopo_set_object_color(struct lstopo_output *loutput, hwloc_obj_t obj, struct lstopo_style *s) { struct lstopo_obj_userdata *lud = obj->userdata; memset(s, 0, sizeof(*s)); switch (obj->type) { case HWLOC_OBJ_MACHINE: s->bg = MACHINE_COLOR; break; case HWLOC_OBJ_GROUP: { hwloc_obj_t parent; s->bg = MISC_COLOR; parent = obj->parent; while (parent) { if (parent->type == HWLOC_OBJ_PACKAGE) { s->bg = GROUP_IN_PACKAGE_COLOR; break; } parent = parent->parent; } break; } case HWLOC_OBJ_MISC: s->bg = MISC_COLOR; break; case HWLOC_OBJ_NUMANODE: if (lstopo_numa_forbidden(loutput, obj)) { s->bg = FORBIDDEN_COLOR; } else if (lstopo_numa_binding(loutput, obj)) { s->bg = BINDING_COLOR; } else { s->bg = MEMORY_COLOR; } break; case HWLOC_OBJ_PACKAGE: s->bg = PACKAGE_COLOR; break; case HWLOC_OBJ_CORE: s->bg = CORE_COLOR; break; case HWLOC_OBJ_L1CACHE: case HWLOC_OBJ_L2CACHE: case HWLOC_OBJ_L3CACHE: case HWLOC_OBJ_L4CACHE: case HWLOC_OBJ_L5CACHE: case HWLOC_OBJ_L1ICACHE: case HWLOC_OBJ_L2ICACHE: case HWLOC_OBJ_L3ICACHE: s->bg = CACHE_COLOR; break; case HWLOC_OBJ_PU: if (lstopo_pu_forbidden(loutput, obj)) { s->bg = FORBIDDEN_COLOR; } else if (lstopo_pu_binding(loutput, obj)) { s->bg = BINDING_COLOR; } else { s->bg = THREAD_COLOR; } break; case HWLOC_OBJ_BRIDGE: s->bg = BRIDGE_COLOR; break; case HWLOC_OBJ_PCI_DEVICE: s->bg = PCI_DEVICE_COLOR; break; case HWLOC_OBJ_OS_DEVICE: s->bg = OS_DEVICE_COLOR; break; default: assert(0); } if (lud->style_set & LSTOPO_STYLE_BG) memcpy(&s->bg, &lud->style.bg, sizeof(struct lstopo_color)); if (lud->style_set & LSTOPO_STYLE_T) memcpy(&s->t, &lud->style.t, sizeof(struct lstopo_color)); if (lud->style_set & LSTOPO_STYLE_T2) memcpy(&s->t2, &lud->style.t2, sizeof(struct lstopo_color)); }