All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tools: using O_LARGEFILE to open perf data file
@ 2010-02-03  3:53 Xiao Guangrong
  2010-02-03  8:45 ` [tip:perf/core] perf tools: Use " tip-bot for Xiao Guangrong
  2010-02-03 11:06 ` [PATCH] perf tools: using O_LARGEFILE to open perf data file - fix Xiao Guangrong
  0 siblings, 2 replies; 10+ messages in thread
From: Xiao Guangrong @ 2010-02-03  3:53 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Frederic Weisbecker, Steven Rostedt, Paul Mackerras,
	Peter Zijlstra, LKML

Open perf data file with O_LARGEFILE flag since its size is easy
larger that 2G.

For example:

# rm -rf perf.data
# ./perf kmem record sleep 300

[ perf record: Woken up 0 times to write data ]
[ perf record: Captured and wrote 3142.147 MB perf.data (~137282513 samples) ]

# ll -h perf.data 
-rw------- 1 root root 3.1G .....

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 tools/perf/builtin-record.c        |    5 ++++-
 tools/perf/util/header.c           |   22 +++++++++++++---------
 tools/perf/util/session.c          |    5 ++++-
 tools/perf/util/trace-event-read.c |    4 ++--
 4 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index eea5691..949167e 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -5,6 +5,9 @@
  * (or a CPU, or a PID) into the perf.data output file - for
  * later analysis via perf report.
  */
+#define _LARGEFILE64_SOURCE
+#define _FILE_OFFSET_BITS 64
+
 #include "builtin.h"
 
 #include "perf.h"
@@ -451,7 +454,7 @@ static int __cmd_record(int argc, const char **argv)
 		append_file = 0;
 	}
 
-	flags = O_CREAT|O_RDWR;
+	flags = O_CREAT|O_RDWR|O_LARGEFILE;
 	if (append_file)
 		file_new = 0;
 	else
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 2bb2bdb..ed3efd7 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1,3 +1,6 @@
+#define _LARGEFILE64_SOURCE
+#define _FILE_OFFSET_BITS 64
+
 #include <sys/types.h>
 #include <byteswap.h>
 #include <unistd.h>
@@ -382,7 +385,7 @@ static int perf_header__adds_write(struct perf_header *self, int fd)
 	sec_size = sizeof(*feat_sec) * nr_sections;
 
 	sec_start = self->data_offset + self->data_size;
-	lseek(fd, sec_start + sec_size, SEEK_SET);
+	lseek64(fd, sec_start + sec_size, SEEK_SET);
 
 	if (perf_header__has_feat(self, HEADER_TRACE_INFO)) {
 		struct perf_file_section *trace_sec;
@@ -390,9 +393,9 @@ static int perf_header__adds_write(struct perf_header *self, int fd)
 		trace_sec = &feat_sec[idx++];
 
 		/* Write trace info */
-		trace_sec->offset = lseek(fd, 0, SEEK_CUR);
+		trace_sec->offset = lseek64(fd, 0, SEEK_CUR);
 		read_tracing_data(fd, attrs, nr_counters);
-		trace_sec->size = lseek(fd, 0, SEEK_CUR) - trace_sec->offset;
+		trace_sec->size = lseek64(fd, 0, SEEK_CUR) - trace_sec->offset;
 	}
 
 
@@ -402,17 +405,18 @@ static int perf_header__adds_write(struct perf_header *self, int fd)
 		buildid_sec = &feat_sec[idx++];
 
 		/* Write build-ids */
-		buildid_sec->offset = lseek(fd, 0, SEEK_CUR);
+		buildid_sec->offset = lseek64(fd, 0, SEEK_CUR);
 		err = dsos__write_buildid_table(fd);
 		if (err < 0) {
 			pr_debug("failed to write buildid table\n");
 			goto out_free;
 		}
-		buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset;
+		buildid_sec->size = lseek64(fd, 0, SEEK_CUR) -
+					    buildid_sec->offset;
 		dsos__cache_build_ids();
 	}
 
-	lseek(fd, sec_start, SEEK_SET);
+	lseek64(fd, sec_start, SEEK_SET);
 	err = do_write(fd, feat_sec, sec_size);
 	if (err < 0)
 		pr_debug("failed to write feature section\n");
@@ -506,7 +510,7 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit)
 		pr_debug("failed to write perf header\n");
 		return err;
 	}
-	lseek(fd, self->data_offset + self->data_size, SEEK_SET);
+	lseek64(fd, self->data_offset + self->data_size, SEEK_SET);
 
 	self->frozen = 1;
 	return 0;
@@ -560,7 +564,7 @@ int perf_header__process_sections(struct perf_header *self, int fd,
 
 	sec_size = sizeof(*feat_sec) * nr_sections;
 
-	lseek(fd, self->data_offset + self->data_size, SEEK_SET);
+	lseek64(fd, self->data_offset + self->data_size, SEEK_SET);
 
 	if (perf_header__getbuffer64(self, fd, feat_sec, sec_size))
 		goto out_free;
@@ -634,7 +638,7 @@ static int perf_file_section__process(struct perf_file_section *self,
 				      struct perf_header *ph,
 				      int feat, int fd)
 {
-	if (lseek(fd, self->offset, SEEK_SET) < 0) {
+	if (lseek64(fd, self->offset, SEEK_SET) < 0) {
 		pr_debug("Failed to lseek to %Ld offset for feature %d, "
 			 "continuing...\n", self->offset, feat);
 		return 0;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 8e7c189..cf91d09 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1,3 +1,6 @@
+#define _LARGEFILE64_SOURCE
+#define _FILE_OFFSET_BITS 64
+
 #include <linux/kernel.h>
 
 #include <byteswap.h>
@@ -12,7 +15,7 @@ static int perf_session__open(struct perf_session *self, bool force)
 {
 	struct stat input_stat;
 
-	self->fd = open(self->filename, O_RDONLY);
+	self->fd = open(self->filename, O_RDONLY|O_LARGEFILE);
 	if (self->fd < 0) {
 		pr_err("failed to open file: %s", self->filename);
 		if (!strcmp(self->filename, "perf.data"))
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index 1744422..ca3c26d 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -83,7 +83,7 @@ static char *read_string(void)
 	char *str = NULL;
 	int size = 0;
 	int i;
-	int r;
+	s64 r;
 
 	for (;;) {
 		r = read(input_fd, buf, BUFSIZ);
@@ -117,7 +117,7 @@ static char *read_string(void)
 	i++;
 
 	/* move the file descriptor to the end of the string */
-	r = lseek(input_fd, -(r - i), SEEK_CUR);
+	r = lseek64(input_fd, -(r - i), SEEK_CUR);
 	if (r < 0)
 		die("lseek");
 
-- 
1.6.1.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-02-04  9:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-03  3:53 [PATCH] perf tools: using O_LARGEFILE to open perf data file Xiao Guangrong
2010-02-03  8:45 ` [tip:perf/core] perf tools: Use " tip-bot for Xiao Guangrong
2010-02-03  9:23   ` H. Peter Anvin
2010-02-03 11:00     ` Xiao Guangrong
2010-02-03 11:06 ` [PATCH] perf tools: using O_LARGEFILE to open perf data file - fix Xiao Guangrong
2010-02-03 13:19   ` Ingo Molnar
2010-02-04  2:31     ` Xiao Guangrong
2010-02-03 17:30   ` H. Peter Anvin
2010-02-04  8:46     ` [PATCH v2] " Xiao Guangrong
2010-02-04  9:57       ` [tip:perf/core] perf tools: Clean up O_LARGEFILE et al usage tip-bot for Xiao Guangrong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.