diff options
Diffstat (limited to 'trace-input.c')
| -rw-r--r-- | trace-input.c | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/trace-input.c b/trace-input.c index 299d7dc..38dd53d 100644 --- a/trace-input.c +++ b/trace-input.c | |||
| @@ -45,6 +45,8 @@ struct tracecmd_handle { | |||
| 45 | 45 | ||
| 46 | __thread struct tracecmd_handle *tracecmd_curr_thread_handle; | 46 | __thread struct tracecmd_handle *tracecmd_curr_thread_handle; |
| 47 | 47 | ||
| 48 | static int init_cpu(struct tracecmd_handle *handle, int cpu); | ||
| 49 | |||
| 48 | static int do_read(struct tracecmd_handle *handle, void *data, int size) | 50 | static int do_read(struct tracecmd_handle *handle, void *data, int size) |
| 49 | { | 51 | { |
| 50 | int tot = 0; | 52 | int tot = 0; |
| @@ -476,7 +478,7 @@ static int get_next_page(struct tracecmd_handle *handle, int cpu) | |||
| 476 | update_cpu_data_index(handle, cpu); | 478 | update_cpu_data_index(handle, cpu); |
| 477 | 479 | ||
| 478 | /* other parts of the code may expect the pointer to not move */ | 480 | /* other parts of the code may expect the pointer to not move */ |
| 479 | save_seek = lseek64(input_fd, 0, SEEK_CUR); | 481 | save_seek = lseek64(handle->fd, 0, SEEK_CUR); |
| 480 | 482 | ||
| 481 | ret = lseek64(handle->fd, handle->cpu_data[cpu].offset, SEEK_SET); | 483 | ret = lseek64(handle->fd, handle->cpu_data[cpu].offset, SEEK_SET); |
| 482 | if (ret < 0) | 484 | if (ret < 0) |
| @@ -486,7 +488,7 @@ static int get_next_page(struct tracecmd_handle *handle, int cpu) | |||
| 486 | return -1; | 488 | return -1; |
| 487 | 489 | ||
| 488 | /* reset the file pointer back */ | 490 | /* reset the file pointer back */ |
| 489 | lseek64(input_fd, save_seek, SEEK_SET); | 491 | lseek64(handle->fd, save_seek, SEEK_SET); |
| 490 | 492 | ||
| 491 | return 0; | 493 | return 0; |
| 492 | } | 494 | } |
| @@ -500,7 +502,7 @@ static int get_next_page(struct tracecmd_handle *handle, int cpu) | |||
| 500 | update_cpu_data_index(handle, cpu); | 502 | update_cpu_data_index(handle, cpu); |
| 501 | 503 | ||
| 502 | handle->cpu_data[cpu].page = mmap(NULL, handle->page_size, PROT_READ, MAP_PRIVATE, | 504 | handle->cpu_data[cpu].page = mmap(NULL, handle->page_size, PROT_READ, MAP_PRIVATE, |
| 503 | input_fd, handle->cpu_data[cpu].offset); | 505 | handle->fd, handle->cpu_data[cpu].offset); |
| 504 | if (handle->cpu_data[cpu].page == MAP_FAILED) | 506 | if (handle->cpu_data[cpu].page == MAP_FAILED) |
| 505 | return -1; | 507 | return -1; |
| 506 | 508 | ||
| @@ -605,6 +607,8 @@ read_event(struct tracecmd_handle *handle, unsigned long long offset, | |||
| 605 | handle->cpu_data[cpu].index = 0; | 607 | handle->cpu_data[cpu].index = 0; |
| 606 | 608 | ||
| 607 | do { | 609 | do { |
| 610 | /* Make sure peek returns new data */ | ||
| 611 | handle->cpu_data[cpu].next = NULL; | ||
| 608 | record = tracecmd_read_data(handle, cpu); | 612 | record = tracecmd_read_data(handle, cpu); |
| 609 | } while (record && (record->offset + record->record_size) <= offset); | 613 | } while (record && (record->offset + record->record_size) <= offset); |
| 610 | 614 | ||
| @@ -633,18 +637,38 @@ find_and_read_event(struct tracecmd_handle *handle, unsigned long long offset, | |||
| 633 | /* Move this cpu index to point to this offest */ | 637 | /* Move this cpu index to point to this offest */ |
| 634 | page_offset = offset & ~(handle->page_size - 1); | 638 | page_offset = offset & ~(handle->page_size - 1); |
| 635 | 639 | ||
| 636 | /* | 640 | if (handle->cpu_data[cpu].page) { |
| 637 | * Set the cpu_data to point to the page in front. | 641 | /* |
| 638 | */ | 642 | * If a page already exists, then we need to reset |
| 639 | page_offset -= handle->page_size; | 643 | * it to point to the page with the data we want. |
| 644 | * We update the pointers to point to the previous | ||
| 645 | * page, and call get_next_page which will mmap | ||
| 646 | * the next page after the pointer of the previous | ||
| 647 | * page we want. Which ends up mapping the page we want. | ||
| 648 | */ | ||
| 640 | 649 | ||
| 641 | handle->cpu_data[cpu].offset = page_offset; | 650 | page_offset -= handle->page_size; |
| 642 | handle->cpu_data[cpu].size = (handle->cpu_data[cpu].file_offset + | ||
| 643 | handle->cpu_data[cpu].file_size) - | ||
| 644 | page_offset; | ||
| 645 | 651 | ||
| 646 | if (get_next_page(handle, cpu)) | 652 | handle->cpu_data[cpu].offset = page_offset; |
| 647 | return NULL; | 653 | handle->cpu_data[cpu].size = (handle->cpu_data[cpu].file_offset + |
| 654 | handle->cpu_data[cpu].file_size) - | ||
| 655 | page_offset; | ||
| 656 | |||
| 657 | if (get_next_page(handle, cpu)) | ||
| 658 | return NULL; | ||
| 659 | } else { | ||
| 660 | /* | ||
| 661 | * We need to map a new page. Just set it up the cpu_data | ||
| 662 | * to the position we want. | ||
| 663 | */ | ||
| 664 | handle->cpu_data[cpu].offset = page_offset; | ||
| 665 | handle->cpu_data[cpu].size = (handle->cpu_data[cpu].file_offset + | ||
| 666 | handle->cpu_data[cpu].file_size) - | ||
| 667 | page_offset; | ||
| 668 | |||
| 669 | if (init_cpu(handle, cpu)) | ||
| 670 | return NULL; | ||
| 671 | } | ||
| 648 | 672 | ||
| 649 | if (pcpu) | 673 | if (pcpu) |
| 650 | *pcpu = cpu; | 674 | *pcpu = cpu; |
| @@ -824,17 +848,17 @@ static int init_read(struct tracecmd_handle *handle, int cpu) | |||
| 824 | return -1; | 848 | return -1; |
| 825 | 849 | ||
| 826 | /* other parts of the code may expect the pointer to not move */ | 850 | /* other parts of the code may expect the pointer to not move */ |
| 827 | save_seek = lseek64(input_fd, 0, SEEK_CUR); | 851 | save_seek = lseek64(handle->fd, 0, SEEK_CUR); |
| 828 | 852 | ||
| 829 | ret = lseek64(input_fd, (off64_t)handle->cpu_data[cpu].offset, SEEK_SET); | 853 | ret = lseek64(handle->fd, (off64_t)handle->cpu_data[cpu].offset, SEEK_SET); |
| 830 | if (ret < 0) | 854 | if (ret < 0) |
| 831 | return -1; | 855 | return -1; |
| 832 | ret = read(input_fd, handle->cpu_data[cpu].page, handle->page_size); | 856 | ret = read(handle->fd, handle->cpu_data[cpu].page, handle->page_size); |
| 833 | if (ret < 0) | 857 | if (ret < 0) |
| 834 | return -1; | 858 | return -1; |
| 835 | 859 | ||
| 836 | /* reset the file pointer back */ | 860 | /* reset the file pointer back */ |
| 837 | lseek64(input_fd, save_seek, SEEK_SET); | 861 | lseek64(handle->fd, save_seek, SEEK_SET); |
| 838 | 862 | ||
| 839 | return 0; | 863 | return 0; |
| 840 | } | 864 | } |
| @@ -850,9 +874,10 @@ static int init_cpu(struct tracecmd_handle *handle, int cpu) | |||
| 850 | return init_read(handle, cpu); | 874 | return init_read(handle, cpu); |
| 851 | 875 | ||
| 852 | handle->cpu_data[cpu].page = mmap(NULL, handle->page_size, PROT_READ, | 876 | handle->cpu_data[cpu].page = mmap(NULL, handle->page_size, PROT_READ, |
| 853 | MAP_PRIVATE, input_fd, handle->cpu_data[cpu].offset); | 877 | MAP_PRIVATE, handle->fd, handle->cpu_data[cpu].offset); |
| 854 | if (handle->cpu_data[cpu].page == MAP_FAILED) { | 878 | if (handle->cpu_data[cpu].page == MAP_FAILED) { |
| 855 | /* fall back to just reading pages */ | 879 | /* fall back to just reading pages */ |
| 880 | perror("mmap"); | ||
| 856 | fprintf(stderr, "Can not mmap file, will read instead\n"); | 881 | fprintf(stderr, "Can not mmap file, will read instead\n"); |
| 857 | handle->read_page = 1; | 882 | handle->read_page = 1; |
| 858 | 883 | ||
