[PATCH 2/5] perf tools: Add xyarray__realloc function in xyarray.c to expend xyarray.
From: chenggang
Date: Thu Dec 20 2012 - 04:14:08 EST
xyarray__realloc() could be used if we wish extend the evsel->fd,
evsel->sample_id or any other xyarray on-the-fly.
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Arjan van de Ven <arjan@xxxxxxxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxx>
Cc: Yanmin Zhang <yanmin.zhang@xxxxxxxxx>
Cc: Wu Fengguang <fengguang.wu@xxxxxxxxx>
Cc: Mike Galbraith <efault@xxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Chenggang Qin <chenggang.qcg@xxxxxxxxxx>
---
tools/perf/util/xyarray.c | 26 ++++++++++++++++++++++++++
tools/perf/util/xyarray.h | 2 ++
2 files changed, 28 insertions(+)
diff --git a/tools/perf/util/xyarray.c b/tools/perf/util/xyarray.c
index 22afbf6..4e76377 100644
--- a/tools/perf/util/xyarray.c
+++ b/tools/perf/util/xyarray.c
@@ -18,3 +18,29 @@ void xyarray__delete(struct xyarray *xy)
{
free(xy);
}
+
+int xyarray__realloc(struct xyarray **xy_old, int xlen_old, int xlen_new,
+ int ylen_new)
+{
+ size_t row_size_new = ylen_new * (*xy_old)->entry_size;
+ struct xyarray *xy_new = zalloc(sizeof(*xy_new) + xlen_new
+ * row_size_new);
+ int x;
+
+ if (xy_new != NULL) {
+ for (x = 0; x < xlen_old; x++)
+ memcpy(&xy_new->contents[x * row_size_new],
+ &((*xy_old)->contents[x * (*xy_old)->row_size]),
+ (*xy_old)->row_size);
+
+ xy_new->row_size = row_size_new;
+ xy_new->entry_size = (*xy_old)->entry_size;
+
+ xyarray__delete(*xy_old);
+
+ *xy_old = xy_new;
+
+ return 0;
+ }
+
+ return -1;
+}
+
diff --git a/tools/perf/util/xyarray.h b/tools/perf/util/xyarray.h
index c488a07..ad41649 100644
--- a/tools/perf/util/xyarray.h
+++ b/tools/perf/util/xyarray.h
@@ -11,6 +11,8 @@ struct xyarray {
struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size);
void xyarray__delete(struct xyarray *xy);
+int xyarray__realloc(struct xyarray **xy_old, int xlen_old, int xlen_new,
+ int ylen_new);
static inline void *xyarray__entry(struct xyarray *xy, int x, int y)
{
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/