void output_draw(struct lstopo_output *loutput) { hwloc_topology_t topology = loutput->topology; struct draw_methods *methods = loutput->methods; int logical = loutput->logical; int legend = loutput->legend; unsigned gridsize = loutput->gridsize; unsigned fontsize = loutput->fontsize; unsigned depth = 100; unsigned totwidth, totheight, offset, i; time_t t; char text[128]; char hostname[128] = ""; unsigned long hostname_size = sizeof(hostname); output_compute_pu_min_textwidth(loutput); system_draw(loutput, methods, hwloc_get_root_obj(topology), depth, 0, &totwidth, 0, &totheight); if (totwidth < 20*fontsize) totwidth = 20*fontsize; if (legend) { /* Display the hostname, but only if we're showing *this* system */ if (hwloc_topology_is_thissystem(topology)) { #if defined(HWLOC_WIN_SYS) && !defined(__CYGWIN__) GetComputerName(hostname, &hostname_size); #else gethostname(hostname, hostname_size); #endif } if (*hostname) { snprintf(text, sizeof(text), "Host: %s", hostname); methods->box(loutput, 0xff, 0xff, 0xff, depth, 0, totwidth, totheight, gridsize + (gridsize + fontsize)*(3+loutput->legend_append_nr)); methods->text(loutput, 0, 0, 0, fontsize, depth, gridsize, totheight + gridsize, text); offset = gridsize + fontsize; } else { methods->box(loutput, 0xff, 0xff, 0xff, depth, 0, totwidth, totheight, gridsize + (gridsize + fontsize)*(2+loutput->legend_append_nr)); offset = 0; } /* Display whether we're showing physical or logical IDs */ snprintf(text, sizeof(text), "Indexes: %s", logical ? "logical" : "physical"); methods->text(loutput, 0, 0, 0, fontsize, depth, gridsize, totheight + gridsize + offset, text); /* Display timestamp */ t = time(NULL); #ifdef HAVE_STRFTIME { struct tm *tmp; tmp = localtime(&t); strftime(text, sizeof(text), "Date: %c", tmp); } #else /* HAVE_STRFTIME */ { char *date; int n; date = ctime(&t); n = strlen(date); if (n && date[n-1] == '\n') { date[n-1] = 0; } snprintf(text, sizeof(text), "Date: %s", date); } #endif /* HAVE_STRFTIME */ methods->text(loutput, 0, 0, 0, fontsize, depth, gridsize, totheight + gridsize + offset + fontsize + gridsize, text); offset = totheight + gridsize + offset + (fontsize + gridsize) * 2; for(i=0; i<loutput->legend_append_nr; i++) { methods->text(loutput, 0, 0, 0, fontsize, depth, gridsize, offset, loutput->legend_append[i]); offset += fontsize + gridsize; } } }
void output_draw(struct lstopo_output *loutput) { hwloc_topology_t topology = loutput->topology; struct draw_methods *methods = loutput->methods; int legend = loutput->legend; unsigned gridsize = loutput->gridsize; unsigned fontsize = loutput->fontsize; hwloc_obj_t root = hwloc_get_root_obj(topology); struct lstopo_obj_userdata *rlud = root->userdata; unsigned depth = 100; unsigned totwidth, totheight, offset, i; time_t t; char text[3][128]; unsigned ntext = 0; char hostname[128] = ""; const char *forcedhostname = NULL; unsigned long hostname_size = sizeof(hostname); unsigned maxtextwidth = 0, textwidth; if (legend && fontsize) { forcedhostname = hwloc_obj_get_info_by_name(hwloc_get_root_obj(topology), "HostName"); if (!forcedhostname && hwloc_topology_is_thissystem(topology)) { #if defined(HWLOC_WIN_SYS) && !defined(__CYGWIN__) GetComputerName(hostname, &hostname_size); #else gethostname(hostname, hostname_size); #endif } if (forcedhostname || *hostname) { if (forcedhostname) snprintf(text[ntext], sizeof(text[ntext]), "Host: %s", forcedhostname); else snprintf(text[ntext], sizeof(text[ntext]), "Host: %s", hostname); textwidth = get_textwidth(loutput, text[ntext], (unsigned) strlen(text[ntext]), fontsize); if (textwidth > maxtextwidth) maxtextwidth = textwidth; ntext++; } /* Display whether we're showing physical or logical IDs */ snprintf(text[ntext], sizeof(text[ntext]), "Indexes: %s", loutput->logical ? "logical" : "physical"); textwidth = get_textwidth(loutput, text[ntext], (unsigned) strlen(text[ntext]), fontsize); if (textwidth > maxtextwidth) maxtextwidth = textwidth; ntext++; /* Display timestamp */ t = time(NULL); #ifdef HAVE_STRFTIME { struct tm *tmp; tmp = localtime(&t); strftime(text[ntext], sizeof(text[ntext]), "Date: %c", tmp); } #else /* HAVE_STRFTIME */ { char *date; int n; date = ctime(&t); n = strlen(date); if (n && date[n-1] == '\n') { date[n-1] = 0; } snprintf(text[ntext], sizeof(text[ntext]), "Date: %s", date); } #endif /* HAVE_STRFTIME */ textwidth = get_textwidth(loutput, text[ntext], (unsigned) strlen(text[ntext]), fontsize); if (textwidth > maxtextwidth) maxtextwidth = textwidth; ntext++; } if (loutput->drawing == LSTOPO_DRAWING_PREPARE) { /* compute root size, our size, and save it */ output_compute_pu_min_textwidth(loutput); get_type_fun(root->type)(loutput, root, depth, 0, 0); /* loutput width is max(root, legend) */ totwidth = rlud->width; if (maxtextwidth + 2*gridsize > totwidth) totwidth = maxtextwidth + 2*gridsize; loutput->width = totwidth; /* loutput height is sum(root, legend) */ totheight = rlud->height; if (legend && fontsize) totheight += gridsize + (ntext+loutput->legend_append_nr) * (gridsize+fontsize); loutput->height = totheight; } else { /* LSTOPO_DRAWING_DRAW */ /* restore our size that was computed during prepare */ totwidth = rlud->width; totheight = rlud->height; /* Draw root for real */ get_type_fun(root->type)(loutput, root, depth, 0, 0); /* Draw legend */ if (legend && fontsize) { offset = rlud->height + gridsize; methods->box(loutput, &WHITE_COLOR, depth, 0, loutput->width, totheight, gridsize + (ntext+loutput->legend_append_nr) * (gridsize+fontsize)); for(i=0; i<ntext; i++, offset += gridsize + fontsize) methods->text(loutput, &BLACK_COLOR, fontsize, depth, gridsize, offset, text[i]); for(i=0; i<loutput->legend_append_nr; i++, offset += gridsize + fontsize) methods->text(loutput, &BLACK_COLOR, fontsize, depth, gridsize, offset, loutput->legend_append[i]); } } }
void output_draw(struct lstopo_output *output) { output_compute_pu_min_textwidth(output); fig(output->topology, output->methods, output->logical, output->legend, hwloc_get_root_obj(output->topology), output, 100, 0, 0); }