diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-01-03 13:50:55 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-01-03 13:50:55 -0500 |
commit | 1e7972cc5c16e06f258b0278d8c9adfb5aa75c68 (patch) | |
tree | b73bbe4083bba9e345474fd17082d8a179f93157 /tools/perf | |
parent | daec78a09de3df5fbfbbd167da0304d49d7fcfe5 (diff) |
perf util: Move do_read from session to util
Not really something to be exported from session.c. Rename it to
'readn' as others did in the past.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/header.c | 6 | ||||
-rw-r--r-- | tools/perf/util/session.c | 22 | ||||
-rw-r--r-- | tools/perf/util/session.h | 1 | ||||
-rw-r--r-- | tools/perf/util/util.c | 17 | ||||
-rw-r--r-- | tools/perf/util/util.h | 1 |
5 files changed, 23 insertions, 24 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index ecb5a8444f42..05dec98fc3ff 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -604,7 +604,7 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit) | |||
604 | static int perf_header__getbuffer64(struct perf_header *self, | 604 | static int perf_header__getbuffer64(struct perf_header *self, |
605 | int fd, void *buf, size_t size) | 605 | int fd, void *buf, size_t size) |
606 | { | 606 | { |
607 | if (do_read(fd, buf, size) <= 0) | 607 | if (readn(fd, buf, size) <= 0) |
608 | return -1; | 608 | return -1; |
609 | 609 | ||
610 | if (self->needs_swap) | 610 | if (self->needs_swap) |
@@ -660,7 +660,7 @@ int perf_file_header__read(struct perf_file_header *self, | |||
660 | { | 660 | { |
661 | lseek(fd, 0, SEEK_SET); | 661 | lseek(fd, 0, SEEK_SET); |
662 | 662 | ||
663 | if (do_read(fd, self, sizeof(*self)) <= 0 || | 663 | if (readn(fd, self, sizeof(*self)) <= 0 || |
664 | memcmp(&self->magic, __perf_magic, sizeof(self->magic))) | 664 | memcmp(&self->magic, __perf_magic, sizeof(self->magic))) |
665 | return -1; | 665 | return -1; |
666 | 666 | ||
@@ -821,7 +821,7 @@ static int perf_file_header__read_pipe(struct perf_pipe_file_header *self, | |||
821 | struct perf_header *ph, int fd, | 821 | struct perf_header *ph, int fd, |
822 | bool repipe) | 822 | bool repipe) |
823 | { | 823 | { |
824 | if (do_read(fd, self, sizeof(*self)) <= 0 || | 824 | if (readn(fd, self, sizeof(*self)) <= 0 || |
825 | memcmp(&self->magic, __perf_magic, sizeof(self->magic))) | 825 | memcmp(&self->magic, __perf_magic, sizeof(self->magic))) |
826 | return -1; | 826 | return -1; |
827 | 827 | ||
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 0f7e544544f5..b163dfd6cbc5 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -838,23 +838,6 @@ static struct thread *perf_session__register_idle_thread(struct perf_session *se | |||
838 | return thread; | 838 | return thread; |
839 | } | 839 | } |
840 | 840 | ||
841 | int do_read(int fd, void *buf, size_t size) | ||
842 | { | ||
843 | void *buf_start = buf; | ||
844 | |||
845 | while (size) { | ||
846 | int ret = read(fd, buf, size); | ||
847 | |||
848 | if (ret <= 0) | ||
849 | return ret; | ||
850 | |||
851 | size -= ret; | ||
852 | buf += ret; | ||
853 | } | ||
854 | |||
855 | return buf - buf_start; | ||
856 | } | ||
857 | |||
858 | #define session_done() (*(volatile int *)(&session_done)) | 841 | #define session_done() (*(volatile int *)(&session_done)) |
859 | volatile int session_done; | 842 | volatile int session_done; |
860 | 843 | ||
@@ -872,7 +855,7 @@ static int __perf_session__process_pipe_events(struct perf_session *self, | |||
872 | 855 | ||
873 | head = 0; | 856 | head = 0; |
874 | more: | 857 | more: |
875 | err = do_read(self->fd, &event, sizeof(struct perf_event_header)); | 858 | err = readn(self->fd, &event, sizeof(struct perf_event_header)); |
876 | if (err <= 0) { | 859 | if (err <= 0) { |
877 | if (err == 0) | 860 | if (err == 0) |
878 | goto done; | 861 | goto done; |
@@ -892,8 +875,7 @@ more: | |||
892 | p += sizeof(struct perf_event_header); | 875 | p += sizeof(struct perf_event_header); |
893 | 876 | ||
894 | if (size - sizeof(struct perf_event_header)) { | 877 | if (size - sizeof(struct perf_event_header)) { |
895 | err = do_read(self->fd, p, | 878 | err = readn(self->fd, p, size - sizeof(struct perf_event_header)); |
896 | size - sizeof(struct perf_event_header)); | ||
897 | if (err <= 0) { | 879 | if (err <= 0) { |
898 | if (err == 0) { | 880 | if (err == 0) { |
899 | pr_err("unexpected end of event stream\n"); | 881 | pr_err("unexpected end of event stream\n"); |
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index ffe4b98db8f0..decd83f274fd 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -109,7 +109,6 @@ void mem_bswap_64(void *src, int byte_size); | |||
109 | 109 | ||
110 | int perf_session__create_kernel_maps(struct perf_session *self); | 110 | int perf_session__create_kernel_maps(struct perf_session *self); |
111 | 111 | ||
112 | int do_read(int fd, void *buf, size_t size); | ||
113 | void perf_session__update_sample_type(struct perf_session *self); | 112 | void perf_session__update_sample_type(struct perf_session *self); |
114 | void perf_session__set_sample_id_all(struct perf_session *session, bool value); | 113 | void perf_session__set_sample_id_all(struct perf_session *session, bool value); |
115 | void perf_session__set_sample_type(struct perf_session *session, u64 type); | 114 | void perf_session__set_sample_type(struct perf_session *session, u64 type); |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 214265674ddd..5b3ea49aa63e 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -114,3 +114,20 @@ unsigned long convert_unit(unsigned long value, char *unit) | |||
114 | 114 | ||
115 | return value; | 115 | return value; |
116 | } | 116 | } |
117 | |||
118 | int readn(int fd, void *buf, size_t n) | ||
119 | { | ||
120 | void *buf_start = buf; | ||
121 | |||
122 | while (n) { | ||
123 | int ret = read(fd, buf, n); | ||
124 | |||
125 | if (ret <= 0) | ||
126 | return ret; | ||
127 | |||
128 | n -= ret; | ||
129 | buf += ret; | ||
130 | } | ||
131 | |||
132 | return buf - buf_start; | ||
133 | } | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 7562707ddd1c..e833f26f3bfc 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -265,6 +265,7 @@ void argv_free(char **argv); | |||
265 | bool strglobmatch(const char *str, const char *pat); | 265 | bool strglobmatch(const char *str, const char *pat); |
266 | bool strlazymatch(const char *str, const char *pat); | 266 | bool strlazymatch(const char *str, const char *pat); |
267 | unsigned long convert_unit(unsigned long value, char *unit); | 267 | unsigned long convert_unit(unsigned long value, char *unit); |
268 | int readn(int fd, void *buf, size_t size); | ||
268 | 269 | ||
269 | #define _STR(x) #x | 270 | #define _STR(x) #x |
270 | #define STR(x) _STR(x) | 271 | #define STR(x) _STR(x) |