libperf: Adopt xyarray class from perf
authorJiri Olsa <jolsa@kernel.org>
Sun, 21 Jul 2019 11:24:44 +0000 (13:24 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 29 Jul 2019 21:34:45 +0000 (18:34 -0300)
Move the xyarray class from perf to libperf, because it's going to be
used in both.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20190721112506.12306-58-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-top.c
tools/perf/lib/Build
tools/perf/lib/include/internal/xyarray.h [new file with mode: 0644]
tools/perf/lib/xyarray.c [new file with mode: 0644]
tools/perf/util/Build
tools/perf/util/counts.h
tools/perf/util/evsel.h
tools/perf/util/python-ext-sources
tools/perf/util/stat.h
tools/perf/util/xyarray.h [deleted file]

index c69ddc67c6723a379dfc5c232c8661772818785a..1a4615a5f6c9d088d26383e10e7983dfdebc24f2 100644 (file)
@@ -38,7 +38,6 @@
 #include <subcmd/parse-options.h>
 #include "util/parse-events.h"
 #include "util/cpumap.h"
-#include "util/xyarray.h"
 #include "util/sort.h"
 #include "util/string2.h"
 #include "util/term.h"
index faf64db13e377f1f8b7c65abc01b536b54c353e0..4f78ec0b4e100292e54d8b93ce651734eef1a974 100644 (file)
@@ -4,6 +4,7 @@ libperf-y += threadmap.o
 libperf-y += evsel.o
 libperf-y += evlist.o
 libperf-y += zalloc.o
+libperf-y += xyarray.o
 
 $(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE
        $(call rule_mkdir)
diff --git a/tools/perf/lib/include/internal/xyarray.h b/tools/perf/lib/include/internal/xyarray.h
new file mode 100644 (file)
index 0000000..3bf70e4
--- /dev/null
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_INTERNAL_XYARRAY_H
+#define __LIBPERF_INTERNAL_XYARRAY_H
+
+#include <sys/types.h>
+
+struct xyarray {
+       size_t row_size;
+       size_t entry_size;
+       size_t entries;
+       size_t max_x;
+       size_t max_y;
+       char contents[];
+};
+
+struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size);
+void xyarray__delete(struct xyarray *xy);
+void xyarray__reset(struct xyarray *xy);
+
+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_y;
+}
+
+static inline int xyarray__max_x(struct xyarray *xy)
+{
+       return xy->max_x;
+}
+
+#endif /* __LIBPERF_INTERNAL_XYARRAY_H */
diff --git a/tools/perf/lib/xyarray.c b/tools/perf/lib/xyarray.c
new file mode 100644 (file)
index 0000000..dcd901d
--- /dev/null
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <internal/xyarray.h>
+#include <linux/zalloc.h>
+#include <stdlib.h>
+#include <string.h>
+
+struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
+{
+       size_t row_size = ylen * entry_size;
+       struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size);
+
+       if (xy != NULL) {
+               xy->entry_size = entry_size;
+               xy->row_size   = row_size;
+               xy->entries    = xlen * ylen;
+               xy->max_x      = xlen;
+               xy->max_y      = ylen;
+       }
+
+       return xy;
+}
+
+void xyarray__reset(struct xyarray *xy)
+{
+       size_t n = xy->entries * xy->entry_size;
+
+       memset(xy->contents, 0, n);
+}
+
+void xyarray__delete(struct xyarray *xy)
+{
+       free(xy);
+}
index 08f670d216153f402550a2f36ab49c869aaccc3d..7abf05131889030cff512b79aef839dc4a2c949a 100644 (file)
@@ -69,7 +69,6 @@ perf-y += svghelper.o
 perf-y += sort.o
 perf-y += hist.o
 perf-y += util.o
-perf-y += xyarray.o
 perf-y += cpumap.o
 perf-y += cputopo.o
 perf-y += cgroup.o
index 0f0cb2d8f70d3a86f91c0cf3243adb4b4775152d..bbfac9ecf6428f8137ec23df811e54b0163991b4 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef __PERF_COUNTS_H
 #define __PERF_COUNTS_H
 
-#include "xyarray.h"
+#include <internal/xyarray.h>
 
 struct perf_counts_values {
        union {
index 57b5523b480c63ea891e809066666f4959863942..1f9f66fe43f40d035354ef2a93312bc8b09827b8 100644 (file)
@@ -8,7 +8,7 @@
 #include <linux/perf_event.h>
 #include <linux/types.h>
 #include <internal/evsel.h>
-#include "xyarray.h"
+#include <internal/xyarray.h>
 #include "symbol_conf.h"
 #include "cpumap.h"
 #include "counts.h"
index 2237bac9fadbbb3058617a72a4bde70c4699117d..235bd98033903aa13698243e04764072f8e268ff 100644 (file)
@@ -20,7 +20,6 @@ util/namespaces.c
 ../lib/vsprintf.c
 util/thread_map.c
 util/util.c
-util/xyarray.c
 util/cgroup.c
 util/parse-branch-options.c
 util/rblist.c
index 95b4de7a9d51c8621993e4c2e5a1d52c263738a7..bcb376e1b3a7f9db54c4a27e3dd45102eac2317e 100644 (file)
@@ -8,7 +8,6 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/wait.h>
-#include "xyarray.h"
 #include "rblist.h"
 #include "perf.h"
 #include "event.h"
diff --git a/tools/perf/util/xyarray.h b/tools/perf/util/xyarray.h
deleted file mode 100644 (file)
index 7ffe562..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _PERF_XYARRAY_H_
-#define _PERF_XYARRAY_H_ 1
-
-#include <sys/types.h>
-
-struct xyarray {
-       size_t row_size;
-       size_t entry_size;
-       size_t entries;
-       size_t max_x;
-       size_t max_y;
-       char contents[];
-};
-
-struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size);
-void xyarray__delete(struct xyarray *xy);
-void xyarray__reset(struct xyarray *xy);
-
-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_y;
-}
-
-static inline int xyarray__max_x(struct xyarray *xy)
-{
-       return xy->max_x;
-}
-
-#endif /* _PERF_XYARRAY_H_ */