Move the xyarray class from perf to libperf, because it's going to be used in both.
Unified · Split
| @@ -38,7 +38,6 @@ · 37 unmodified lines | ||
| 38 | 38 | #include <subcmd/parse-options.h> |
| 39 | 39 | #include "util/parse-events.h" |
| 40 | 40 | #include "util/cpumap.h" |
| 41 | −#include "util/xyarray.h" | |
| 42 | 41 | #include "util/sort.h" |
| 43 | 42 | #include "util/string2.h" |
| 44 | 43 | #include "util/term.h" |
| @@ -4,6 +4,7 @@ libperf-y += threadmap.o · 3 unmodified lines | ||
| 4 | 4 | libperf-y += evsel.o |
| 5 | 5 | libperf-y += evlist.o |
| 6 | 6 | libperf-y += zalloc.o |
| 7 | +libperf-y += xyarray.o | |
| 7 | 8 | |
| 8 | 9 | $(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE |
| 9 | 10 | $(call rule_mkdir) |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | −#ifndef _PERF_XYARRAY_H_ | |
| 3 | −#define _PERF_XYARRAY_H_ 1 | |
| 2 | +#ifndef __LIBPERF_INTERNAL_XYARRAY_H | |
| 3 | +#define __LIBPERF_INTERNAL_XYARRAY_H | |
| 4 | 4 | |
| 5 | 5 | #include <sys/types.h> |
| 6 | 6 | |
| @@ -32,4 +32,4 @@ static inline int xyarray__max_x(struct xyarray *xy) · 25 unmodified lines | ||
| 32 | 32 | return xy->max_x; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | −#endif /* _PERF_XYARRAY_H_ */ | |
| 35 | +#endif /* __LIBPERF_INTERNAL_XYARRAY_H */ | |
| @@ -0,0 +1,33 @@ | ||
| 1 | +// SPDX-License-Identifier: GPL-2.0 | |
| 2 | +#include <internal/xyarray.h> | |
| 3 | +#include <linux/zalloc.h> | |
| 4 | +#include <stdlib.h> | |
| 5 | +#include <string.h> | |
| 6 | + | |
| 7 | +struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size) | |
| 8 | +{ | |
| 9 | + size_t row_size = ylen * entry_size; | |
| 10 | + struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size); | |
| 11 | + | |
| 12 | + if (xy != NULL) { | |
| 13 | + xy->entry_size = entry_size; | |
| 14 | + xy->row_size = row_size; | |
| 15 | + xy->entries = xlen * ylen; | |
| 16 | + xy->max_x = xlen; | |
| 17 | + xy->max_y = ylen; | |
| 18 | + } | |
| 19 | + | |
| 20 | + return xy; | |
| 21 | +} | |
| 22 | + | |
| 23 | +void xyarray__reset(struct xyarray *xy) | |
| 24 | +{ | |
| 25 | + size_t n = xy->entries * xy->entry_size; | |
| 26 | + | |
| 27 | + memset(xy->contents, 0, n); | |
| 28 | +} | |
| 29 | + | |
| 30 | +void xyarray__delete(struct xyarray *xy) | |
| 31 | +{ | |
| 32 | + free(xy); | |
| 33 | +} | |
| @@ -69,7 +69,6 @@ perf-y += svghelper.o · 68 unmodified lines | ||
| 69 | 69 | perf-y += sort.o |
| 70 | 70 | perf-y += hist.o |
| 71 | 71 | perf-y += util.o |
| 72 | −perf-y += xyarray.o | |
| 73 | 72 | perf-y += cpumap.o |
| 74 | 73 | perf-y += cputopo.o |
| 75 | 74 | perf-y += cgroup.o |
| @@ -2,7 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | #ifndef __PERF_COUNTS_H |
| 3 | 3 | #define __PERF_COUNTS_H |
| 4 | 4 | |
| 5 | −#include "xyarray.h" | |
| 5 | +#include <internal/xyarray.h> | |
| 6 | 6 | |
| 7 | 7 | struct perf_counts_values { |
| 8 | 8 | union { |
| @@ -8,7 +8,7 @@ · 7 unmodified lines | ||
| 8 | 8 | #include <linux/perf_event.h> |
| 9 | 9 | #include <linux/types.h> |
| 10 | 10 | #include <internal/evsel.h> |
| 11 | −#include "xyarray.h" | |
| 11 | +#include <internal/xyarray.h> | |
| 12 | 12 | #include "symbol_conf.h" |
| 13 | 13 | #include "cpumap.h" |
| 14 | 14 | #include "counts.h" |
| @@ -20,7 +20,6 @@ util/namespaces.c · 19 unmodified lines | ||
| 20 | 20 | ../lib/vsprintf.c |
| 21 | 21 | util/thread_map.c |
| 22 | 22 | util/util.c |
| 23 | −util/xyarray.c | |
| 24 | 23 | util/cgroup.c |
| 25 | 24 | util/parse-branch-options.c |
| 26 | 25 | util/rblist.c |
| @@ -8,7 +8,6 @@ · 7 unmodified lines | ||
| 8 | 8 | #include <sys/time.h> |
| 9 | 9 | #include <sys/resource.h> |
| 10 | 10 | #include <sys/wait.h> |
| 11 | −#include "xyarray.h" | |
| 12 | 11 | #include "rblist.h" |
| 13 | 12 | #include "perf.h" |
| 14 | 13 | #include "event.h" |