Skip to content

Commit

Permalink
utils/annotate: new distances may get a name now
Browse files Browse the repository at this point in the history
Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Apr 13, 2021
1 parent acbf63a commit 216cad8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
6 changes: 4 additions & 2 deletions utils/hwloc/hwloc-annotate.1in
@@ -1,5 +1,5 @@
.\" -*- nroff -*-
.\" Copyright © 2013-2020 Inria. All rights reserved.
.\" Copyright © 2013-2021 Inria. All rights reserved.
.\" See COPYING in top-level directory.
.TH HWLOC-ANNOTATE "1" "%HWLOC_DATE%" "%PACKAGE_VERSION%" "%PACKAGE_NAME%"
.SH NAME
Expand Down Expand Up @@ -129,12 +129,14 @@ The optional \fIflags\fR (0 unless specified) corresponds to the flags
given to the function \fBhwloc_distances_set()\fR.
\fIlocation\fR is ignored in this mode.

The first line of the pointed file must be a integer representing
The real first line of the pointed file must be a integer representing
a distances \fBkind\fR as defined in \fBhwloc/distances.h\fR.
The second line is the number of objects involved in the distances.
The next lines contain one object each.
The next lines contain one distance value each,
or a single line may be given with a integer combination of format \fBx*y\fR or \fBx*y*z\fR.
An optional line before all others may start with \fBname=\fR
to specify the name of the distances structure if any.
.TP
.B none
No new annotation is added. This is useful when clearing existing attributes.
Expand Down
20 changes: 17 additions & 3 deletions utils/hwloc/hwloc-annotate.c
Expand Up @@ -188,6 +188,7 @@ get_unique_obj(hwloc_topology_t topology, int topodepth, char *str,
static void
add_distances(hwloc_topology_t topology, int topodepth)
{
char *name = NULL;
unsigned long kind = 0;
unsigned nbobjs = 0;
hwloc_obj_t *objs = NULL;
Expand All @@ -205,10 +206,22 @@ add_distances(hwloc_topology_t topology, int topodepth)
}

if (!fgets(line, sizeof(line), file)) {
fprintf(stderr, "Failed to read kind line\n");
fprintf(stderr, "Failed to read header line\n");
goto out;
}
kind = strtoul(line, NULL, 0);
if (!strncmp(line, "name=", 5)) {
char *end = strchr(line, '\n');
if (end) {
*end = '\0';
name = strdup(line+5);
}
if (!fgets(line, sizeof(line), file)) {
fprintf(stderr, "Failed to read kind line\n");
goto out;
}
}

kind = strtoul(line, NULL, 0);

if (!fgets(line, sizeof(line), file)) {
fprintf(stderr, "Failed to read nbobjs line\n");
Expand Down Expand Up @@ -285,7 +298,7 @@ add_distances(hwloc_topology_t topology, int topodepth)
}

err = -1;
handle = hwloc_distances_add_create(topology, NULL, kind, 0);
handle = hwloc_distances_add_create(topology, name, kind, 0);
if (handle) {
err = hwloc_distances_add_values(topology, handle, nbobjs, objs, values, 0);
if (!err) {
Expand All @@ -298,6 +311,7 @@ add_distances(hwloc_topology_t topology, int topodepth)
}

out:
free(name);
free(objs);
free(values);
fclose(file);
Expand Down
2 changes: 1 addition & 1 deletion utils/hwloc/test-hwloc-annotate.output
Expand Up @@ -153,7 +153,7 @@
<info name="Foo" value="Bar"/>
</object>
</object>
<distances2 type="PU" nbobjs="3" kind="5" indexing="os">
<distances2 type="PU" nbobjs="3" kind="5" name="mynewdistances" indexing="os">
<indexes length="6">1 0 2 </indexes>
<u64values length="27">10 80 80 80 10 80 80 80 10 </u64values>
</distances2>
Expand Down
3 changes: 2 additions & 1 deletion utils/hwloc/test-hwloc-annotate.sh.in
Expand Up @@ -2,7 +2,7 @@
#-*-sh-*-

#
# Copyright © 2009-2020 Inria. All rights reserved.
# Copyright © 2009-2021 Inria. All rights reserved.
# Copyright © 2014 Cisco Systems, Inc. All rights reserved.
# See COPYING in top-level directory.
#
Expand Down Expand Up @@ -67,6 +67,7 @@ $annotate $file $file -- dummy -- cpukind 0xa -1 0 foo bar
$annotate $file $file -- dummy -- cpukind 0x3 4 0 foo2 bar2
$annotate $file $file -- dummy -- cpukind 0xc 7 0 foo2 bar3
cat > $distances << EOF
name=mynewdistances
5
3
pu:2
Expand Down

0 comments on commit 216cad8

Please sign in to comment.