aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2009-12-18 12:59:43 -0500
committerSteven Rostedt <rostedt@goodmis.org>2009-12-18 12:59:43 -0500
commitd889066760e48795b4c778e4589ec089e41f009d (patch)
tree3c58e8f5dc055f214002cb8e9bfd100036012893
parent91dc34ce6bb3cc86d1e522c61bffaee6bc6bf23d (diff)
trace-cmd: Fixed tracecmd_refresh_record()
Fixed tracecmd_refresh_record to update the CPU iterator properly. Also added the refresh to the tracecmd_peek_data() if it was going to return the cached record. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-input.c64
1 files changed, 58 insertions, 6 deletions
diff --git a/trace-input.c b/trace-input.c
index 826fed9..5c8dfae 100644
--- a/trace-input.c
+++ b/trace-input.c
@@ -495,6 +495,11 @@ static unsigned int ts4host(struct tracecmd_input *handle,
495 return type_len_ts >> 5; 495 return type_len_ts >> 5;
496} 496}
497 497
498static unsigned int read_type_len_ts(struct tracecmd_input *handle, void *ptr)
499{
500 return data2host4(handle->pevent, ptr);
501}
502
498static int calc_index(struct tracecmd_input *handle, 503static int calc_index(struct tracecmd_input *handle,
499 void *ptr, int cpu) 504 void *ptr, int cpu)
500{ 505{
@@ -574,9 +579,21 @@ static int get_read_page(struct tracecmd_input *handle, int cpu,
574 return 0; 579 return 0;
575} 580}
576 581
582/*
583 * get_page maps a page for a given cpu.
584 *
585 * Returns 1 if the page was already mapped,
586 * 0 if it mapped successfully
587 * -1 on error
588 */
577static int get_page(struct tracecmd_input *handle, int cpu, 589static int get_page(struct tracecmd_input *handle, int cpu,
578 off64_t offset) 590 off64_t offset)
579{ 591{
592 /* Don't map if the page is already where we want */
593 if (handle->cpu_data[cpu].offset == offset &&
594 handle->cpu_data[cpu].page)
595 return 1;
596
580 if (offset & (handle->page_size - 1)) { 597 if (offset & (handle->page_size - 1)) {
581 errno = -EINVAL; 598 errno = -EINVAL;
582 die("bad page offset %llx", offset); 599 die("bad page offset %llx", offset);
@@ -656,7 +673,7 @@ read_old_format(struct tracecmd_input *handle, void **ptr, int cpu)
656 673
657 index = calc_index(handle, *ptr, cpu); 674 index = calc_index(handle, *ptr, cpu);
658 675
659 type_len_ts = data2host4(pevent, *ptr); 676 type_len_ts = read_type_len_ts(handle, *ptr);
660 *ptr += 4; 677 *ptr += 4;
661 678
662 type = type4host(handle, type_len_ts); 679 type = type4host(handle, type_len_ts);
@@ -769,7 +786,7 @@ find_and_read_event(struct tracecmd_input *handle, unsigned long long offset,
769 /* Move this cpu index to point to this offest */ 786 /* Move this cpu index to point to this offest */
770 page_offset = offset & ~(handle->page_size - 1); 787 page_offset = offset & ~(handle->page_size - 1);
771 788
772 if (get_page(handle, cpu, page_offset)) 789 if (get_page(handle, cpu, page_offset) < 0)
773 return NULL; 790 return NULL;
774 791
775 if (pcpu) 792 if (pcpu)
@@ -822,14 +839,46 @@ tracecmd_read_at(struct tracecmd_input *handle, unsigned long long offset,
822 * A record data points to a mmap section of memory. 839 * A record data points to a mmap section of memory.
823 * by reading new records the mmap section may be unmapped. 840 * by reading new records the mmap section may be unmapped.
824 * This will refresh the record's data mapping. 841 * This will refresh the record's data mapping.
842 *
843 * Returns 1 if page is still mapped (does not modify CPU iterator)
844 * 0 on successful mapping (was not mapped before,
845 * This will update CPU iterator to point to
846 * the next record)
847 * -1 on error.
825 */ 848 */
826int tracecmd_refresh_record(struct tracecmd_input *handle, 849int tracecmd_refresh_record(struct tracecmd_input *handle,
827 struct record *record) 850 struct record *record)
828{ 851{
829 unsigned long long page_offset; 852 unsigned long long page_offset;
853 int cpu = record->cpu;
854 struct cpu_data *cpu_data = &handle->cpu_data[cpu];
855 unsigned int type_len_ts;
856 unsigned int len;
857 int index;
858 int ret;
830 859
831 page_offset = record->offset & ~(handle->page_size - 1); 860 page_offset = record->offset & ~(handle->page_size - 1);
832 get_page(handle, record->cpu, page_offset); 861 index = record->offset & (handle->page_size - 1);
862
863 ret = get_page(handle, record->cpu, page_offset) < 0;
864 if (ret < 0)
865 return -1;
866
867 /* If the page is still mapped, there's nothing to do */
868 if (ret)
869 return 1;
870
871 record->data = cpu_data->page + index;
872
873 type_len_ts = read_type_len_ts(handle, record->data);
874 len = len4host(handle, type_len_ts);
875
876 /* The data starts either 4 or 8 bytes from offset */
877 record->data += len ? 4 : 8;
878
879 /* The get_page resets the index, set the index after this record */
880 cpu_data->index = index + record->record_size;
881 cpu_data->timestamp = record->ts;
833 882
834 return 0; 883 return 0;
835} 884}
@@ -938,7 +987,7 @@ tracecmd_set_cpu_to_timestamp(struct tracecmd_input *handle, int cpu,
938 } 987 }
939 988
940 while (start < end) { 989 while (start < end) {
941 if (get_page(handle, cpu, next)) 990 if (get_page(handle, cpu, next) < 0)
942 return -1; 991 return -1;
943 992
944 if (cpu_data->timestamp == ts) 993 if (cpu_data->timestamp == ts)
@@ -982,7 +1031,7 @@ translate_data(struct tracecmd_input *handle,
982 unsigned int type_len_ts; 1031 unsigned int type_len_ts;
983 unsigned int type_len; 1032 unsigned int type_len;
984 1033
985 type_len_ts = data2host4(pevent, *ptr); 1034 type_len_ts = read_type_len_ts(handle, *ptr);
986 *ptr += 4; 1035 *ptr += 4;
987 1036
988 type_len = type_len4host(handle, type_len_ts); 1037 type_len = type_len4host(handle, type_len_ts);
@@ -1092,8 +1141,11 @@ tracecmd_peek_data(struct tracecmd_input *handle, int cpu)
1092 /* Hack to work around function graph read ahead */ 1141 /* Hack to work around function graph read ahead */
1093 tracecmd_curr_thread_handle = handle; 1142 tracecmd_curr_thread_handle = handle;
1094 1143
1095 if (handle->cpu_data[cpu].next) 1144 if (handle->cpu_data[cpu].next) {
1145 /* Make sure it's still mapped */
1146 tracecmd_refresh_record(handle, handle->cpu_data[cpu].next);
1096 return handle->cpu_data[cpu].next; 1147 return handle->cpu_data[cpu].next;
1148 }
1097 1149
1098 if (!page) 1150 if (!page)
1099 return NULL; 1151 return NULL;