History

libperf: Adopt xyarray class from perf

Move the xyarray class from perf to libperf, because it's going to be used in both.

Jiri Olsa committed 7 years ago

Commit 4b247fa1 parent 453fa039 files · +39 −9Browse files

Unified · Split

9 files
  1. tools/perf/builtin-top.c +0 −1
  2. tools/perf/lib/Build +1 −0
  3. tools/perf/lib/include/internal/xyarray.h +3 −3
  4. tools/perf/lib/xyarray.c +33 −0
  5. tools/perf/util/Build +0 −1
  6. tools/perf/util/counts.h +1 −1
  7. tools/perf/util/evsel.h +1 −1
  8. tools/perf/util/python-ext-sources +0 −1
  9. tools/perf/util/stat.h +0 −1
tools/perf/builtin-top.c+0−1
@@ -38,7 +38,6 @@ · 37 unmodified lines
3838 #include <subcmd/parse-options.h>
3939 #include "util/parse-events.h"
4040 #include "util/cpumap.h"
41−#include "util/xyarray.h"
4241 #include "util/sort.h"
4342 #include "util/string2.h"
4443 #include "util/term.h"
tools/perf/lib/Build+1−0
@@ -4,6 +4,7 @@ libperf-y += threadmap.o · 3 unmodified lines
44 libperf-y += evsel.o
55 libperf-y += evlist.o
66 libperf-y += zalloc.o
7+libperf-y += xyarray.o
78
89 $(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE
910 $(call rule_mkdir)
tools/perf/lib/include/internal/xyarray.hrenamed from tools/perf/util/xyarray.h+3−3
@@ -1,6 +1,6 @@
11 /* 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
44
55 #include <sys/types.h>
66
@@ -32,4 +32,4 @@ static inline int xyarray__max_x(struct xyarray *xy) · 25 unmodified lines
3232 return xy->max_x;
3333 }
3434
35−#endif /* _PERF_XYARRAY_H_ */
35+#endif /* __LIBPERF_INTERNAL_XYARRAY_H */
tools/perf/lib/xyarray.c+33−0
@@ -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+}
tools/perf/util/Build+0−1
@@ -69,7 +69,6 @@ perf-y += svghelper.o · 68 unmodified lines
6969 perf-y += sort.o
7070 perf-y += hist.o
7171 perf-y += util.o
72−perf-y += xyarray.o
7372 perf-y += cpumap.o
7473 perf-y += cputopo.o
7574 perf-y += cgroup.o
tools/perf/util/counts.h+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
22 #ifndef __PERF_COUNTS_H
33 #define __PERF_COUNTS_H
44
5−#include "xyarray.h"
5+#include <internal/xyarray.h>
66
77 struct perf_counts_values {
88 union {
tools/perf/util/evsel.h+1−1
@@ -8,7 +8,7 @@ · 7 unmodified lines
88 #include <linux/perf_event.h>
99 #include <linux/types.h>
1010 #include <internal/evsel.h>
11−#include "xyarray.h"
11+#include <internal/xyarray.h>
1212 #include "symbol_conf.h"
1313 #include "cpumap.h"
1414 #include "counts.h"
tools/perf/util/python-ext-sources+0−1
@@ -20,7 +20,6 @@ util/namespaces.c · 19 unmodified lines
2020 ../lib/vsprintf.c
2121 util/thread_map.c
2222 util/util.c
23−util/xyarray.c
2423 util/cgroup.c
2524 util/parse-branch-options.c
2625 util/rblist.c
tools/perf/util/stat.h+0−1
@@ -8,7 +8,6 @@ · 7 unmodified lines
88 #include <sys/time.h>
99 #include <sys/resource.h>
1010 #include <sys/wait.h>
11−#include "xyarray.h"
1211 #include "rblist.h"
1312 #include "perf.h"
1413 #include "event.h"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t