diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-12-14 20:31:17 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-14 20:31:17 -0500 |
commit | 868c803feabfec0acbb588e5052bae8caf6cbec1 (patch) | |
tree | 2d854b7935602c3923ee7bae2f29c826e2f7876d | |
parent | 5c45bd2c0f7bbc7fd97e7e7e8825012b7ab069ac (diff) |
Add tracecmd_read_cpu_first() and last()
Add a interface to get the first and last item per CPU.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-cmd.h | 4 | ||||
-rw-r--r-- | trace-input.c | 41 | ||||
-rw-r--r-- | trace-read.c | 47 |
3 files changed, 92 insertions, 0 deletions
diff --git a/trace-cmd.h b/trace-cmd.h index 9fbd475..e67cdef 100644 --- a/trace-cmd.h +++ b/trace-cmd.h | |||
@@ -75,6 +75,10 @@ tracecmd_read_at(struct tracecmd_input *handle, unsigned long long offset, | |||
75 | struct record * | 75 | struct record * |
76 | tracecmd_translate_data(struct tracecmd_input *handle, | 76 | tracecmd_translate_data(struct tracecmd_input *handle, |
77 | void *ptr, int size); | 77 | void *ptr, int size); |
78 | struct record * | ||
79 | tracecmd_read_cpu_first(struct tracecmd_input *handle, int cpu); | ||
80 | struct record * | ||
81 | tracecmd_read_cpu_last(struct tracecmd_input *handle, int cpu); | ||
78 | 82 | ||
79 | int tracecmd_set_cpu_to_timestamp(struct tracecmd_input *handle, | 83 | int tracecmd_set_cpu_to_timestamp(struct tracecmd_input *handle, |
80 | int cpu, unsigned long long ts); | 84 | int cpu, unsigned long long ts); |
diff --git a/trace-input.c b/trace-input.c index 7051709..3747680 100644 --- a/trace-input.c +++ b/trace-input.c | |||
@@ -585,6 +585,14 @@ static int get_page(struct tracecmd_input *handle, int cpu, | |||
585 | return -1; | 585 | return -1; |
586 | } | 586 | } |
587 | 587 | ||
588 | if (offset < handle->cpu_data[cpu].file_offset || | ||
589 | offset > handle->cpu_data[cpu].file_offset + | ||
590 | handle->cpu_data[cpu].file_size) { | ||
591 | errno = -EINVAL; | ||
592 | die("bad page offset %llx", offset); | ||
593 | return -1; | ||
594 | } | ||
595 | |||
588 | handle->cpu_data[cpu].offset = offset; | 596 | handle->cpu_data[cpu].offset = offset; |
589 | handle->cpu_data[cpu].size = (handle->cpu_data[cpu].file_offset + | 597 | handle->cpu_data[cpu].size = (handle->cpu_data[cpu].file_offset + |
590 | handle->cpu_data[cpu].file_size) - | 598 | handle->cpu_data[cpu].file_size) - |
@@ -796,6 +804,39 @@ tracecmd_read_at(struct tracecmd_input *handle, unsigned long long offset, | |||
796 | return find_and_read_event(handle, offset, pcpu); | 804 | return find_and_read_event(handle, offset, pcpu); |
797 | } | 805 | } |
798 | 806 | ||
807 | struct record * | ||
808 | tracecmd_read_cpu_first(struct tracecmd_input *handle, int cpu) | ||
809 | { | ||
810 | get_page(handle, cpu, handle->cpu_data[cpu].file_offset); | ||
811 | |||
812 | return tracecmd_read_data(handle, cpu); | ||
813 | } | ||
814 | |||
815 | struct record * | ||
816 | tracecmd_read_cpu_last(struct tracecmd_input *handle, int cpu) | ||
817 | { | ||
818 | struct record *record; | ||
819 | off64_t offset; | ||
820 | |||
821 | offset = handle->cpu_data[cpu].file_offset + | ||
822 | handle->cpu_data[cpu].file_size; | ||
823 | |||
824 | if (offset & (handle->page_size - 1)) | ||
825 | offset &= ~(handle->page_size - 1); | ||
826 | else | ||
827 | offset -= handle->page_size; | ||
828 | |||
829 | get_page(handle, cpu, offset); | ||
830 | |||
831 | do { | ||
832 | record = tracecmd_read_data(handle, cpu); | ||
833 | if (record) | ||
834 | offset = record->offset; | ||
835 | } while (record); | ||
836 | |||
837 | return tracecmd_read_at(handle, offset, NULL); | ||
838 | } | ||
839 | |||
799 | int | 840 | int |
800 | tracecmd_set_cpu_to_timestamp(struct tracecmd_input *handle, int cpu, | 841 | tracecmd_set_cpu_to_timestamp(struct tracecmd_input *handle, int cpu, |
801 | unsigned long long ts) | 842 | unsigned long long ts) |
diff --git a/trace-read.c b/trace-read.c index 48c9510..492aab1 100644 --- a/trace-read.c +++ b/trace-read.c | |||
@@ -133,6 +133,53 @@ static void test_save(struct record *record, int cpu) | |||
133 | } | 133 | } |
134 | #endif /* TEST_AT_TIMESTAMP */ | 134 | #endif /* TEST_AT_TIMESTAMP */ |
135 | 135 | ||
136 | #define TEST_FIRST_LAST 1 | ||
137 | #if TEST_FIRST_LAST | ||
138 | #define DO_TEST | ||
139 | static void show_test(struct tracecmd_input *handle) | ||
140 | { | ||
141 | struct pevent *pevent; | ||
142 | struct record *record; | ||
143 | struct trace_seq s; | ||
144 | int cpu = 0; | ||
145 | |||
146 | pevent = tracecmd_get_pevent(handle); | ||
147 | |||
148 | record = tracecmd_read_cpu_first(handle, cpu); | ||
149 | if (!record) { | ||
150 | printf("No first record?\n"); | ||
151 | return; | ||
152 | } | ||
153 | |||
154 | printf("\nHERE'S THE FIRST RECORD with offset %p\n", | ||
155 | (void *)record->offset); | ||
156 | trace_seq_init(&s); | ||
157 | pevent_print_event(pevent, &s, cpu, record->data, record->size, record->ts); | ||
158 | trace_seq_do_printf(&s); | ||
159 | printf("\n"); | ||
160 | |||
161 | free(record); | ||
162 | |||
163 | record = tracecmd_read_cpu_last(handle, cpu); | ||
164 | if (!record) { | ||
165 | printf("No last record?\n"); | ||
166 | return; | ||
167 | } | ||
168 | |||
169 | printf("\nHERE'S THE LAST RECORD with offset %p\n", | ||
170 | (void *)record->offset); | ||
171 | trace_seq_init(&s); | ||
172 | pevent_print_event(pevent, &s, cpu, record->data, record->size, record->ts); | ||
173 | trace_seq_do_printf(&s); | ||
174 | printf("\n"); | ||
175 | |||
176 | free(record); | ||
177 | } | ||
178 | static void test_save(struct record *record, int cpu) | ||
179 | { | ||
180 | } | ||
181 | #endif /* TEST_FIRST_LAST */ | ||
182 | |||
136 | #ifndef DO_TEST | 183 | #ifndef DO_TEST |
137 | static void show_test(struct tracecmd_input *handle) | 184 | static void show_test(struct tracecmd_input *handle) |
138 | { | 185 | { |