summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-11-24 12:05:16 -0200
committerIngo Molnar <mingo@elte.hu>2009-11-24 16:37:02 +0100
commit364794845cbc49e638b83d7ef739524291e1e961 (patch)
treee720975b26d307d6566afb9305c9f6e44290a7da /tools
parentb32d133aec5dc882cf783a293f393bfb3f4379e1 (diff)
downloadlinux-364794845cbc49e638b83d7ef739524291e1e961.tar.bz2
perf tools: Introduce zalloc() for the common calloc(1, N) case
This way we type less characters and it looks more like the kzalloc kernel counterpart. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1259071517-3242-3-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/bench/mem-memcpy.c4
-rw-r--r--tools/perf/builtin-help.c4
-rw-r--r--tools/perf/builtin-probe.c4
-rw-r--r--tools/perf/builtin-sched.c14
-rw-r--r--tools/perf/builtin-top.c2
-rw-r--r--tools/perf/util/header.c2
-rw-r--r--tools/perf/util/parse-events.c2
-rw-r--r--tools/perf/util/symbol.c11
-rw-r--r--tools/perf/util/thread.c2
-rw-r--r--tools/perf/util/util.h5
10 files changed, 25 insertions, 25 deletions
diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c
index 5165fd1d8d2c..89773178e894 100644
--- a/tools/perf/bench/mem-memcpy.c
+++ b/tools/perf/bench/mem-memcpy.c
@@ -127,11 +127,11 @@ int bench_mem_memcpy(int argc, const char **argv,
return 1;
}
- dst = calloc(length, sizeof(char));
+ dst = zalloc(length);
if (!dst)
die("memory allocation failed - maybe length is too large?\n");
- src = calloc(length, sizeof(char));
+ src = zalloc(length);
if (!src)
die("memory allocation failed - maybe length is too large?\n");
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 768f9c826312..9f810b17c25c 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -179,7 +179,7 @@ static void add_man_viewer(const char *name)
while (*p)
p = &((*p)->next);
- *p = calloc(1, (sizeof(**p) + len + 1));
+ *p = zalloc(sizeof(**p) + len + 1);
strncpy((*p)->name, name, len);
}
@@ -194,7 +194,7 @@ static void do_add_man_viewer_info(const char *name,
size_t len,
const char *value)
{
- struct man_viewer_info_list *new = calloc(1, sizeof(*new) + len + 1);
+ struct man_viewer_info_list *new = zalloc(sizeof(*new) + len + 1);
strncpy(new->name, name, len);
new->info = strdup(value);
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index d78a3d945492..a2f6daf01ecb 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -309,9 +309,9 @@ static int synthesize_probe_event(struct probe_point *pp)
{
char *buf;
int i, len, ret;
- pp->probes[0] = buf = (char *)calloc(MAX_CMDLEN, sizeof(char));
+ pp->probes[0] = buf = zalloc(MAX_CMDLEN);
if (!buf)
- die("Failed to allocate memory by calloc.");
+ die("Failed to allocate memory by zalloc.");
ret = snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset);
if (ret <= 0 || ret >= MAX_CMDLEN)
goto error;
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index dbf089b12def..19eb708a706b 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -225,7 +225,7 @@ static void calibrate_sleep_measurement_overhead(void)
static struct sched_atom *
get_new_event(struct task_desc *task, u64 timestamp)
{
- struct sched_atom *event = calloc(1, sizeof(*event));
+ struct sched_atom *event = zalloc(sizeof(*event));
unsigned long idx = task->nr_events;
size_t size;
@@ -293,7 +293,7 @@ add_sched_event_wakeup(struct task_desc *task, u64 timestamp,
return;
}
- wakee_event->wait_sem = calloc(1, sizeof(*wakee_event->wait_sem));
+ wakee_event->wait_sem = zalloc(sizeof(*wakee_event->wait_sem));
sem_init(wakee_event->wait_sem, 0, 0);
wakee_event->specific_wait = 1;
event->wait_sem = wakee_event->wait_sem;
@@ -323,7 +323,7 @@ static struct task_desc *register_pid(unsigned long pid, const char *comm)
if (task)
return task;
- task = calloc(1, sizeof(*task));
+ task = zalloc(sizeof(*task));
task->pid = pid;
task->nr = nr_tasks;
strcpy(task->comm, comm);
@@ -962,9 +962,7 @@ __thread_latency_insert(struct rb_root *root, struct work_atoms *data,
static void thread_atoms_insert(struct thread *thread)
{
- struct work_atoms *atoms;
-
- atoms = calloc(sizeof(*atoms), 1);
+ struct work_atoms *atoms = zalloc(sizeof(*atoms));
if (!atoms)
die("No memory");
@@ -996,9 +994,7 @@ add_sched_out_event(struct work_atoms *atoms,
char run_state,
u64 timestamp)
{
- struct work_atom *atom;
-
- atom = calloc(sizeof(*atom), 1);
+ struct work_atom *atom = zalloc(sizeof(*atom));
if (!atom)
die("Non memory");
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index a21247543fc1..4c8653a86aaf 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -181,7 +181,7 @@ static void parse_source(struct sym_entry *syme)
return;
if (syme->src == NULL) {
- syme->src = calloc(1, sizeof(*source));
+ syme->src = zalloc(sizeof(*source));
if (syme->src == NULL)
return;
pthread_mutex_init(&syme->src->lock, NULL);
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 271a1600e6f7..4b586569bb02 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -63,7 +63,7 @@ int perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
*/
struct perf_header *perf_header__new(void)
{
- struct perf_header *self = calloc(sizeof(*self), 1);
+ struct perf_header *self = zalloc(sizeof(*self));
if (self != NULL) {
self->size = 1;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 070027469270..9e5dbd66d34d 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -197,7 +197,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
if (id == config) {
closedir(evt_dir);
closedir(sys_dir);
- path = calloc(1, sizeof(path));
+ path = zalloc(sizeof(path));
path->system = malloc(MAX_EVENT_LENGTH);
if (!path->system) {
free(path);
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index c4ca974b36e3..8db85b4f553f 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -94,15 +94,14 @@ static void kernel_maps__fixup_end(void)
static struct symbol *symbol__new(u64 start, u64 len, const char *name)
{
size_t namelen = strlen(name) + 1;
- struct symbol *self = calloc(1, (symbol__priv_size +
- sizeof(*self) + namelen));
- if (!self)
+ struct symbol *self = zalloc(symbol__priv_size +
+ sizeof(*self) + namelen);
+ if (self == NULL)
return NULL;
- if (symbol__priv_size) {
- memset(self, 0, symbol__priv_size);
+ if (symbol__priv_size)
self = ((void *)self) + symbol__priv_size;
- }
+
self->start = start;
self->end = len ? start + len - 1 : start;
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 0f6d78c9863a..1796625f7784 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -11,7 +11,7 @@ static struct thread *last_match;
static struct thread *thread__new(pid_t pid)
{
- struct thread *self = calloc(1, sizeof(*self));
+ struct thread *self = zalloc(sizeof(*self));
if (self != NULL) {
self->pid = pid;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index e1c623e0c99e..30c5517f2f91 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -302,6 +302,11 @@ extern int xdup(int fd);
extern FILE *xfdopen(int fd, const char *mode);
extern int xmkstemp(char *template);
+static inline void *zalloc(size_t size)
+{
+ return calloc(1, size);
+}
+
static inline size_t xsize_t(off_t len)
{
return (size_t)len;