From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>,
David Ahern <dsahern@gmail.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Mike Galbraith <efault@gmx.de>, Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <peterz@infradead.org>,
Stephane Eranian <eranian@google.com>
Subject: [PATCH 01/25] perf tools: Eliminate duplicate code and use PATH_MAX consistently
Date: Mon, 28 Nov 2011 21:14:02 -0200 [thread overview]
Message-ID: <1322522066-21879-2-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1322522066-21879-1-git-send-email-acme@infradead.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
No need for multiple definitions for STR() and die(), also use SuSv2's
PATH_MAX instead of adding MAX_PATH.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-qpujjkw7u0bf0tr4wt55cr9y@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-probe.c | 1 -
tools/perf/util/cgroup.c | 15 +++++++--------
tools/perf/util/debugfs.c | 12 ++++++------
tools/perf/util/debugfs.h | 29 +++++++++--------------------
tools/perf/util/probe-finder.h | 1 -
tools/perf/util/trace-event-info.c | 28 ++--------------------------
6 files changed, 24 insertions(+), 62 deletions(-)
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 710ae3d..59d43ab 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -46,7 +46,6 @@
#define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*"
#define DEFAULT_FUNC_FILTER "!_*"
-#define MAX_PATH_LEN 256
/* Session management structure */
static struct {
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 96bee5c..dbe2f16 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -3,7 +3,6 @@
#include "parse-options.h"
#include "evsel.h"
#include "cgroup.h"
-#include "debugfs.h" /* MAX_PATH, STR() */
#include "evlist.h"
int nr_cgroups;
@@ -12,7 +11,7 @@ static int
cgroupfs_find_mountpoint(char *buf, size_t maxlen)
{
FILE *fp;
- char mountpoint[MAX_PATH+1], tokens[MAX_PATH+1], type[MAX_PATH+1];
+ char mountpoint[PATH_MAX + 1], tokens[PATH_MAX + 1], type[PATH_MAX + 1];
char *token, *saved_ptr = NULL;
int found = 0;
@@ -25,8 +24,8 @@ cgroupfs_find_mountpoint(char *buf, size_t maxlen)
* and inspect every cgroupfs mount point to find one that has
* perf_event subsystem
*/
- while (fscanf(fp, "%*s %"STR(MAX_PATH)"s %"STR(MAX_PATH)"s %"
- STR(MAX_PATH)"s %*d %*d\n",
+ while (fscanf(fp, "%*s %"STR(PATH_MAX)"s %"STR(PATH_MAX)"s %"
+ STR(PATH_MAX)"s %*d %*d\n",
mountpoint, type, tokens) == 3) {
if (!strcmp(type, "cgroup")) {
@@ -57,15 +56,15 @@ cgroupfs_find_mountpoint(char *buf, size_t maxlen)
static int open_cgroup(char *name)
{
- char path[MAX_PATH+1];
- char mnt[MAX_PATH+1];
+ char path[PATH_MAX + 1];
+ char mnt[PATH_MAX + 1];
int fd;
- if (cgroupfs_find_mountpoint(mnt, MAX_PATH+1))
+ if (cgroupfs_find_mountpoint(mnt, PATH_MAX + 1))
return -1;
- snprintf(path, MAX_PATH, "%s/%s", mnt, name);
+ snprintf(path, PATH_MAX, "%s/%s", mnt, name);
fd = open(path, O_RDONLY);
if (fd == -1)
diff --git a/tools/perf/util/debugfs.c b/tools/perf/util/debugfs.c
index a88fefc..680be34 100644
--- a/tools/perf/util/debugfs.c
+++ b/tools/perf/util/debugfs.c
@@ -2,8 +2,10 @@
#include "debugfs.h"
#include "cache.h"
+#include <sys/mount.h>
+
static int debugfs_premounted;
-static char debugfs_mountpoint[MAX_PATH+1];
+static char debugfs_mountpoint[PATH_MAX + 1];
static const char *debugfs_known_mountpoints[] = {
"/sys/kernel/debug/",
@@ -64,9 +66,7 @@ const char *debugfs_find_mountpoint(void)
if (fp == NULL)
die("Can't open /proc/mounts for read");
- while (fscanf(fp, "%*s %"
- STR(MAX_PATH)
- "s %99s %*s %*d %*d\n",
+ while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
debugfs_mountpoint, type) == 2) {
if (strcmp(type, "debugfs") == 0)
break;
@@ -158,7 +158,7 @@ int debugfs_umount(void)
int debugfs_write(const char *entry, const char *value)
{
- char path[MAX_PATH+1];
+ char path[PATH_MAX + 1];
int ret, count;
int fd;
@@ -203,7 +203,7 @@ int debugfs_write(const char *entry, const char *value)
*/
int debugfs_read(const char *entry, char *buffer, size_t size)
{
- char path[MAX_PATH+1];
+ char path[PATH_MAX + 1];
int ret;
int fd;
diff --git a/tools/perf/util/debugfs.h b/tools/perf/util/debugfs.h
index 83a0287..8cd3fa0 100644
--- a/tools/perf/util/debugfs.h
+++ b/tools/perf/util/debugfs.h
@@ -1,25 +1,14 @@
#ifndef __DEBUGFS_H__
#define __DEBUGFS_H__
-#include <sys/mount.h>
-
-#ifndef MAX_PATH
-# define MAX_PATH 256
-#endif
-
-#ifndef STR
-# define _STR(x) #x
-# define STR(x) _STR(x)
-#endif
-
-extern const char *debugfs_find_mountpoint(void);
-extern int debugfs_valid_mountpoint(const char *debugfs);
-extern int debugfs_valid_entry(const char *path);
-extern char *debugfs_mount(const char *mountpoint);
-extern int debugfs_umount(void);
-extern int debugfs_write(const char *entry, const char *value);
-extern int debugfs_read(const char *entry, char *buffer, size_t size);
-extern void debugfs_force_cleanup(void);
-extern int debugfs_make_path(const char *element, char *buffer, int size);
+const char *debugfs_find_mountpoint(void);
+int debugfs_valid_mountpoint(const char *debugfs);
+int debugfs_valid_entry(const char *path);
+char *debugfs_mount(const char *mountpoint);
+int debugfs_umount(void);
+int debugfs_write(const char *entry, const char *value);
+int debugfs_read(const char *entry, char *buffer, size_t size);
+void debugfs_force_cleanup(void);
+int debugfs_make_path(const char *element, char *buffer, int size);
#endif /* __DEBUGFS_H__ */
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index 1132c8f..17e94d0 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -5,7 +5,6 @@
#include "util.h"
#include "probe-event.h"
-#define MAX_PATH_LEN 256
#define MAX_PROBE_BUFFER 1024
#define MAX_PROBES 128
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index d2655f0..ac6830d 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -18,7 +18,8 @@
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
-#define _GNU_SOURCE
+#include <ctype.h>
+#include "util.h"
#include <dirent.h>
#include <mntent.h>
#include <stdio.h>
@@ -31,7 +32,6 @@
#include <pthread.h>
#include <fcntl.h>
#include <unistd.h>
-#include <ctype.h>
#include <errno.h>
#include <stdbool.h>
#include <linux/list.h>
@@ -44,10 +44,6 @@
#define VERSION "0.5"
-#define _STR(x) #x
-#define STR(x) _STR(x)
-#define MAX_PATH 256
-
#define TRACE_CTRL "tracing_on"
#define TRACE "trace"
#define AVAILABLE "available_tracers"
@@ -73,26 +69,6 @@ struct events {
};
-
-static void die(const char *fmt, ...)
-{
- va_list ap;
- int ret = errno;
-
- if (errno)
- perror("perf");
- else
- ret = -1;
-
- va_start(ap, fmt);
- fprintf(stderr, " ");
- vfprintf(stderr, fmt, ap);
- va_end(ap);
-
- fprintf(stderr, "\n");
- exit(ret);
-}
-
void *malloc_or_die(unsigned int size)
{
void *data;
--
1.7.8.rc0.35.gee6df
next prev parent reply other threads:[~2011-11-28 23:19 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-28 23:14 [GIT PULL 00/25] perf/core fixes and improvements Arnaldo Carvalho de Melo
2011-11-28 23:14 ` Arnaldo Carvalho de Melo [this message]
2011-11-28 23:14 ` [PATCH 02/25] perf tools: Simplify debugfs mountpoint handling code Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 03/25] perf evlist: Introduce perf_evlist__add_attrs Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 04/25] perf evlist: Introduce add_tracepoints method Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 05/25] perf evsel: Introduce config attr method Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 06/25] perf evlist: Introduce {prepare,start}_workload refactored from 'perf record' Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 07/25] perf evlist: Handle default value for 'pages' on mmap method Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 08/25] perf record: Move mmap_pages to perf_record_opts Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 09/25] perf session: Move threads to struct machine Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 10/25] perf record: Move 'group' to perf_event_ops Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 11/25] perf ui progress: Fix divide by zero Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 12/25] perf symbols: Add nr_events to symbol_conf Arnaldo Carvalho de Melo
2011-11-29 4:44 ` David Ahern
2011-11-29 11:52 ` Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 13/25] perf evlist: Introduce id_hdr_size method out of perf_session Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 14/25] perf event: perf_event_ops->attr() manipulates only an evlist Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 15/25] perf session: Remove superfluous callchain_cursor member Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 16/25] perf tools: Use evsel->attr.sample_type instead of session->sample_type Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 17/25] perf report: Group options in a struct Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 18/25] perf annotate: " Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 19/25] perf tools: Pass tool context in the the perf_event_ops functions Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 20/25] perf tools: Resolve machine earlier and pass it to perf_event_ops Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 21/25] perf tools: Rename perf_event_ops to perf_tool Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 22/25] perf top: Stop using globals for tool state Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 23/25] perf tools: make -C consistent across commands (for cpu list arg) Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 24/25] perf script: Add comm filtering option Arnaldo Carvalho de Melo
2011-11-28 23:14 ` [PATCH 25/25] perf tools: Save some loops using perf_evlist__id2evsel Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1322522066-21879-2-git-send-email-acme@infradead.org \
--to=acme@infradead.org \
--cc=acme@redhat.com \
--cc=dsahern@gmail.com \
--cc=efault@gmx.de \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®