Skip to content

Commit

Permalink
perf xyarray: Save max_x, max_y
Browse files Browse the repository at this point in the history
Save the original array dimensions in xyarrays, so that users can
retrieve them later. Add some inline functions to access these fields.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170811232634.30465-1-andi@firstfloor.org
[ As noticed by Jiri, fix up namespacing: xy__method() -> xyarray__method() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Andi Kleen authored and Arnaldo Carvalho de Melo committed Aug 22, 2017
1 parent ba63f76 commit d74be47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tools/perf/util/xyarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
xy->entry_size = entry_size;
xy->row_size = row_size;
xy->entries = xlen * ylen;
xy->max_x = xlen;
xy->max_y = ylen;
}

return xy;
Expand Down
12 changes: 12 additions & 0 deletions tools/perf/util/xyarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ struct xyarray {
size_t row_size;
size_t entry_size;
size_t entries;
size_t max_x;
size_t max_y;
char contents[];
};

Expand All @@ -19,4 +21,14 @@ static inline void *xyarray__entry(struct xyarray *xy, int x, int y)
return &xy->contents[x * xy->row_size + y * xy->entry_size];
}

static inline int xyarray__max_y(struct xyarray *xy)
{
return xy->max_x;
}

static inline int xyarray__max_x(struct xyarray *xy)
{
return xy->max_y;
}

#endif /* _PERF_XYARRAY_H_ */

0 comments on commit d74be47

Please sign in to comment.