@@ -1150,6 +1150,119 @@ main (int argc, char *argv[])
1150
1150
loutput .legend = 0 ;
1151
1151
}
1152
1152
1153
+ /***********************
1154
+ * Configure the output
1155
+ */
1156
+
1157
+ /* if the output format wasn't enforced, look at the filename */
1158
+ if (filename && output_format == LSTOPO_OUTPUT_DEFAULT ) {
1159
+ if (!strcmp (filename , "-" )
1160
+ || !strcmp (filename , "/dev/stdout" )) {
1161
+ output_format = LSTOPO_OUTPUT_CONSOLE ;
1162
+ } else {
1163
+ char * dot = strrchr (filename , '.' );
1164
+ if (dot )
1165
+ output_format = parse_output_format (dot + 1 , callname );
1166
+ else {
1167
+ fprintf (stderr , "Cannot infer output type for file `%s' without any extension, using default output.\n" , filename );
1168
+ filename = NULL ;
1169
+ }
1170
+ }
1171
+ }
1172
+ if (output_format == LSTOPO_OUTPUT_ERROR )
1173
+ goto out_usagefailure ;
1174
+
1175
+ /* if the output format wasn't enforced, think a bit about what the user probably want */
1176
+ if (output_format == LSTOPO_OUTPUT_DEFAULT ) {
1177
+ if (loutput .show_cpuset
1178
+ || loutput .show_only != HWLOC_OBJ_TYPE_NONE
1179
+ || loutput .show_distances_only
1180
+ || loutput .verbose_mode != LSTOPO_VERBOSE_MODE_DEFAULT )
1181
+ output_format = LSTOPO_OUTPUT_CONSOLE ;
1182
+ }
1183
+
1184
+ switch (output_format ) {
1185
+ case LSTOPO_OUTPUT_DEFAULT :
1186
+ #ifdef LSTOPO_HAVE_GRAPHICS
1187
+ #if (defined LSTOPO_HAVE_X11 )
1188
+ if (getenv ("DISPLAY" )) {
1189
+ output_func = output_x11 ;
1190
+ } else
1191
+ #endif /* LSTOPO_HAVE_X11 */
1192
+ #ifdef HWLOC_WIN_SYS
1193
+ {
1194
+ output_func = output_windows ;
1195
+ }
1196
+ #endif
1197
+ #endif /* !LSTOPO_HAVE_GRAPHICS */
1198
+ #if !defined HWLOC_WIN_SYS || !defined LSTOPO_HAVE_GRAPHICS
1199
+ {
1200
+ output_func = output_console ;
1201
+ }
1202
+ #endif
1203
+ break ;
1204
+
1205
+ case LSTOPO_OUTPUT_CONSOLE :
1206
+ output_func = output_console ;
1207
+ break ;
1208
+ case LSTOPO_OUTPUT_SYNTHETIC :
1209
+ output_func = output_synthetic ;
1210
+ break ;
1211
+ case LSTOPO_OUTPUT_ASCII :
1212
+ output_func = output_ascii ;
1213
+ break ;
1214
+ case LSTOPO_OUTPUT_TIKZ :
1215
+ output_func = output_tikz ;
1216
+ break ;
1217
+ case LSTOPO_OUTPUT_FIG :
1218
+ output_func = output_fig ;
1219
+ break ;
1220
+ #ifdef LSTOPO_HAVE_GRAPHICS
1221
+ # ifdef CAIRO_HAS_PNG_FUNCTIONS
1222
+ case LSTOPO_OUTPUT_PNG :
1223
+ output_func = output_png ;
1224
+ break ;
1225
+ # endif /* CAIRO_HAS_PNG_FUNCTIONS */
1226
+ # ifdef CAIRO_HAS_PDF_SURFACE
1227
+ case LSTOPO_OUTPUT_PDF :
1228
+ output_func = output_pdf ;
1229
+ break ;
1230
+ # endif /* CAIRO_HAS_PDF_SURFACE */
1231
+ # ifdef CAIRO_HAS_PS_SURFACE
1232
+ case LSTOPO_OUTPUT_PS :
1233
+ output_func = output_ps ;
1234
+ break ;
1235
+ # endif /* CAIRO_HAS_PS_SURFACE */
1236
+ # ifdef CAIRO_HAS_SVG_SURFACE
1237
+ case LSTOPO_OUTPUT_SVG :
1238
+ case LSTOPO_OUTPUT_CAIROSVG :
1239
+ output_func = output_cairosvg ;
1240
+ break ;
1241
+ # endif /* CAIRO_HAS_SVG_SURFACE */
1242
+ #endif /* LSTOPO_HAVE_GRAPHICS */
1243
+ #if !(defined LSTOPO_HAVE_GRAPHICS ) || !(defined CAIRO_HAS_SVG_SURFACE )
1244
+ case LSTOPO_OUTPUT_SVG :
1245
+ #endif
1246
+ case LSTOPO_OUTPUT_NATIVESVG :
1247
+ output_func = output_nativesvg ;
1248
+ break ;
1249
+ case LSTOPO_OUTPUT_XML :
1250
+ output_func = output_xml ;
1251
+ break ;
1252
+ #ifndef HWLOC_WIN_SYS
1253
+ case LSTOPO_OUTPUT_SHMEM :
1254
+ output_func = output_shmem ;
1255
+ break ;
1256
+ #endif
1257
+ default :
1258
+ fprintf (stderr , "file format not supported\n" );
1259
+ goto out_usagefailure ;
1260
+ }
1261
+
1262
+ /*************************
1263
+ * Configure the topology
1264
+ */
1265
+
1153
1266
err = hwloc_topology_set_flags (topology , flags );
1154
1267
if (err < 0 ) {
1155
1268
fprintf (stderr , "Failed to set flags %lx (%s).\n" , flags , strerror (errno ));
@@ -1194,33 +1307,6 @@ main (int argc, char *argv[])
1194
1307
}
1195
1308
}
1196
1309
1197
- /* if the output format wasn't enforced, look at the filename */
1198
- if (filename && output_format == LSTOPO_OUTPUT_DEFAULT ) {
1199
- if (!strcmp (filename , "-" )
1200
- || !strcmp (filename , "/dev/stdout" )) {
1201
- output_format = LSTOPO_OUTPUT_CONSOLE ;
1202
- } else {
1203
- char * dot = strrchr (filename , '.' );
1204
- if (dot )
1205
- output_format = parse_output_format (dot + 1 , callname );
1206
- else {
1207
- fprintf (stderr , "Cannot infer output type for file `%s' without any extension, using default output.\n" , filename );
1208
- filename = NULL ;
1209
- }
1210
- }
1211
- }
1212
- if (output_format == LSTOPO_OUTPUT_ERROR )
1213
- goto out_usagefailure ;
1214
-
1215
- /* if the output format wasn't enforced, think a bit about what the user probably want */
1216
- if (output_format == LSTOPO_OUTPUT_DEFAULT ) {
1217
- if (loutput .show_cpuset
1218
- || loutput .show_only != HWLOC_OBJ_TYPE_NONE
1219
- || loutput .show_distances_only
1220
- || loutput .verbose_mode != LSTOPO_VERBOSE_MODE_DEFAULT )
1221
- output_format = LSTOPO_OUTPUT_CONSOLE ;
1222
- }
1223
-
1224
1310
if (input_format == HWLOC_UTILS_INPUT_XML
1225
1311
&& output_format == LSTOPO_OUTPUT_XML ) {
1226
1312
/* must be after parsing output format and before loading the topology */
@@ -1229,6 +1315,10 @@ main (int argc, char *argv[])
1229
1315
hwloc_topology_set_userdata_export_callback (topology , hwloc_utils_userdata_export_cb );
1230
1316
}
1231
1317
1318
+ /*********************
1319
+ * Build the topology
1320
+ */
1321
+
1232
1322
#ifdef HAVE_CLOCK_GETTIME
1233
1323
if (measure_load_time )
1234
1324
clock_gettime (CLOCK_MONOTONIC , & ts1 );
@@ -1256,6 +1346,18 @@ main (int argc, char *argv[])
1256
1346
}
1257
1347
}
1258
1348
1349
+ #ifdef HAVE_CLOCK_GETTIME
1350
+ if (measure_load_time ) {
1351
+ clock_gettime (CLOCK_MONOTONIC , & ts2 );
1352
+ ms = (ts2 .tv_nsec - ts1 .tv_nsec )/1000000 + (ts2 .tv_sec - ts1 .tv_sec )* 1000UL ;
1353
+ printf ("hwloc_topology_load() took %lu ms\n" , ms );
1354
+ }
1355
+ #endif
1356
+
1357
+ /********************************
1358
+ * Tweak the topology and output
1359
+ */
1360
+
1259
1361
if (allow_flags ) {
1260
1362
if (allow_flags == HWLOC_ALLOW_FLAG_CUSTOM ) {
1261
1363
err = hwloc_topology_allow (topology , allow_cpuset , allow_nodeset , HWLOC_ALLOW_FLAG_CUSTOM );
@@ -1282,14 +1384,6 @@ main (int argc, char *argv[])
1282
1384
/* get our binding even if --pid not given, it may be used by --restrict */
1283
1385
hwloc_get_membind (topology , loutput .membind_set , & policy , HWLOC_MEMBIND_BYNODESET );
1284
1386
1285
- #ifdef HAVE_CLOCK_GETTIME
1286
- if (measure_load_time ) {
1287
- clock_gettime (CLOCK_MONOTONIC , & ts2 );
1288
- ms = (ts2 .tv_nsec - ts1 .tv_nsec )/1000000 + (ts2 .tv_sec - ts1 .tv_sec )* 1000UL ;
1289
- printf ("hwloc_topology_load() took %lu ms\n" , ms );
1290
- }
1291
- #endif
1292
-
1293
1387
loutput .need_pci_domain = lstopo_check_pci_domains (topology );
1294
1388
1295
1389
if (top )
@@ -1311,84 +1405,6 @@ main (int argc, char *argv[])
1311
1405
free (restrictstring );
1312
1406
}
1313
1407
1314
- switch (output_format ) {
1315
- case LSTOPO_OUTPUT_DEFAULT :
1316
- #ifdef LSTOPO_HAVE_GRAPHICS
1317
- #if (defined LSTOPO_HAVE_X11 )
1318
- if (getenv ("DISPLAY" )) {
1319
- output_func = output_x11 ;
1320
- } else
1321
- #endif /* LSTOPO_HAVE_X11 */
1322
- #ifdef HWLOC_WIN_SYS
1323
- {
1324
- output_func = output_windows ;
1325
- }
1326
- #endif
1327
- #endif /* !LSTOPO_HAVE_GRAPHICS */
1328
- #if !defined HWLOC_WIN_SYS || !defined LSTOPO_HAVE_GRAPHICS
1329
- {
1330
- output_func = output_console ;
1331
- }
1332
- #endif
1333
- break ;
1334
-
1335
- case LSTOPO_OUTPUT_CONSOLE :
1336
- output_func = output_console ;
1337
- break ;
1338
- case LSTOPO_OUTPUT_SYNTHETIC :
1339
- output_func = output_synthetic ;
1340
- break ;
1341
- case LSTOPO_OUTPUT_ASCII :
1342
- output_func = output_ascii ;
1343
- break ;
1344
- case LSTOPO_OUTPUT_TIKZ :
1345
- output_func = output_tikz ;
1346
- break ;
1347
- case LSTOPO_OUTPUT_FIG :
1348
- output_func = output_fig ;
1349
- break ;
1350
- #ifdef LSTOPO_HAVE_GRAPHICS
1351
- # ifdef CAIRO_HAS_PNG_FUNCTIONS
1352
- case LSTOPO_OUTPUT_PNG :
1353
- output_func = output_png ;
1354
- break ;
1355
- # endif /* CAIRO_HAS_PNG_FUNCTIONS */
1356
- # ifdef CAIRO_HAS_PDF_SURFACE
1357
- case LSTOPO_OUTPUT_PDF :
1358
- output_func = output_pdf ;
1359
- break ;
1360
- # endif /* CAIRO_HAS_PDF_SURFACE */
1361
- # ifdef CAIRO_HAS_PS_SURFACE
1362
- case LSTOPO_OUTPUT_PS :
1363
- output_func = output_ps ;
1364
- break ;
1365
- # endif /* CAIRO_HAS_PS_SURFACE */
1366
- # ifdef CAIRO_HAS_SVG_SURFACE
1367
- case LSTOPO_OUTPUT_SVG :
1368
- case LSTOPO_OUTPUT_CAIROSVG :
1369
- output_func = output_cairosvg ;
1370
- break ;
1371
- # endif /* CAIRO_HAS_SVG_SURFACE */
1372
- #endif /* LSTOPO_HAVE_GRAPHICS */
1373
- #if !(defined LSTOPO_HAVE_GRAPHICS ) || !(defined CAIRO_HAS_SVG_SURFACE )
1374
- case LSTOPO_OUTPUT_SVG :
1375
- #endif
1376
- case LSTOPO_OUTPUT_NATIVESVG :
1377
- output_func = output_nativesvg ;
1378
- break ;
1379
- case LSTOPO_OUTPUT_XML :
1380
- output_func = output_xml ;
1381
- break ;
1382
- #ifndef HWLOC_WIN_SYS
1383
- case LSTOPO_OUTPUT_SHMEM :
1384
- output_func = output_shmem ;
1385
- break ;
1386
- #endif
1387
- default :
1388
- fprintf (stderr , "file format not supported\n" );
1389
- goto out_usagefailure ;
1390
- }
1391
-
1392
1408
loutput .topology = topology ;
1393
1409
loutput .depth = hwloc_topology_get_depth (topology );
1394
1410
loutput .file = NULL ;
@@ -1400,6 +1416,9 @@ main (int argc, char *argv[])
1400
1416
lstopo_add_collapse_attributes (topology );
1401
1417
}
1402
1418
1419
+ /******************
1420
+ * Output for real
1421
+ */
1403
1422
err = output_func (& loutput , filename );
1404
1423
1405
1424
if (output_format != LSTOPO_OUTPUT_XML ) {
0 commit comments