diff options
-rw-r--r-- | trace-input.c | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/trace-input.c b/trace-input.c index 99d24e4..239c9d3 100644 --- a/trace-input.c +++ b/trace-input.c | |||
@@ -451,19 +451,19 @@ update_cpu_data_index(struct tracecmd_handle *handle, int cpu) | |||
451 | handle->cpu_data[cpu].index = 0; | 451 | handle->cpu_data[cpu].index = 0; |
452 | } | 452 | } |
453 | 453 | ||
454 | static void get_next_page(struct tracecmd_handle *handle, int cpu) | 454 | static int get_next_page(struct tracecmd_handle *handle, int cpu) |
455 | { | 455 | { |
456 | off64_t save_seek; | 456 | off64_t save_seek; |
457 | off64_t ret; | 457 | off64_t ret; |
458 | 458 | ||
459 | if (!handle->cpu_data[cpu].page) | 459 | if (!handle->cpu_data[cpu].page) |
460 | return; | 460 | return 0; |
461 | 461 | ||
462 | if (handle->read_page) { | 462 | if (handle->read_page) { |
463 | if (handle->cpu_data[cpu].size <= handle->page_size) { | 463 | if (handle->cpu_data[cpu].size <= handle->page_size) { |
464 | free(handle->cpu_data[cpu].page); | 464 | free(handle->cpu_data[cpu].page); |
465 | handle->cpu_data[cpu].page = NULL; | 465 | handle->cpu_data[cpu].page = NULL; |
466 | return; | 466 | return 0; |
467 | } | 467 | } |
468 | 468 | ||
469 | update_cpu_data_index(handle, cpu); | 469 | update_cpu_data_index(handle, cpu); |
@@ -473,30 +473,31 @@ static void get_next_page(struct tracecmd_handle *handle, int cpu) | |||
473 | 473 | ||
474 | ret = lseek64(handle->fd, handle->cpu_data[cpu].offset, SEEK_SET); | 474 | ret = lseek64(handle->fd, handle->cpu_data[cpu].offset, SEEK_SET); |
475 | if (ret < 0) | 475 | if (ret < 0) |
476 | die("failed to lseek"); | 476 | return -1; |
477 | ret = read(handle->fd, handle->cpu_data[cpu].page, handle->page_size); | 477 | ret = read(handle->fd, handle->cpu_data[cpu].page, handle->page_size); |
478 | if (ret < 0) | 478 | if (ret < 0) |
479 | die("failed to read page"); | 479 | return -1; |
480 | 480 | ||
481 | /* reset the file pointer back */ | 481 | /* reset the file pointer back */ |
482 | lseek64(input_fd, save_seek, SEEK_SET); | 482 | lseek64(input_fd, save_seek, SEEK_SET); |
483 | 483 | ||
484 | return; | 484 | return 0; |
485 | } | 485 | } |
486 | 486 | ||
487 | munmap(handle->cpu_data[cpu].page, handle->page_size); | 487 | munmap(handle->cpu_data[cpu].page, handle->page_size); |
488 | handle->cpu_data[cpu].page = NULL; | 488 | handle->cpu_data[cpu].page = NULL; |
489 | 489 | ||
490 | if (handle->cpu_data[cpu].size <= handle->page_size) | 490 | if (handle->cpu_data[cpu].size <= handle->page_size) |
491 | return; | 491 | return 0; |
492 | 492 | ||
493 | update_cpu_data_index(handle, cpu); | 493 | update_cpu_data_index(handle, cpu); |
494 | 494 | ||
495 | handle->cpu_data[cpu].page = mmap(NULL, handle->page_size, PROT_READ, MAP_PRIVATE, | 495 | handle->cpu_data[cpu].page = mmap(NULL, handle->page_size, PROT_READ, MAP_PRIVATE, |
496 | input_fd, handle->cpu_data[cpu].offset); | 496 | input_fd, handle->cpu_data[cpu].offset); |
497 | if (handle->cpu_data[cpu].page == MAP_FAILED) | 497 | if (handle->cpu_data[cpu].page == MAP_FAILED) |
498 | die("failed to mmap cpu %d at offset 0x%llx", | 498 | return -1; |
499 | cpu, handle->cpu_data[cpu].offset); | 499 | |
500 | return 0; | ||
500 | } | 501 | } |
501 | 502 | ||
502 | enum old_ring_buffer_type { | 503 | enum old_ring_buffer_type { |
@@ -539,7 +540,8 @@ read_old_format(struct tracecmd_handle *handle, void **ptr, int cpu) | |||
539 | return NULL; | 540 | return NULL; |
540 | 541 | ||
541 | case OLD_RINGBUF_TYPE_TIME_STAMP: | 542 | case OLD_RINGBUF_TYPE_TIME_STAMP: |
542 | die("should not be here"); | 543 | warning("should not be here"); |
544 | return NULL; | ||
543 | break; | 545 | break; |
544 | default: | 546 | default: |
545 | if (len) | 547 | if (len) |
@@ -554,7 +556,9 @@ read_old_format(struct tracecmd_handle *handle, void **ptr, int cpu) | |||
554 | 556 | ||
555 | handle->cpu_data[cpu].timestamp += delta; | 557 | handle->cpu_data[cpu].timestamp += delta; |
556 | 558 | ||
557 | data = malloc_or_die(sizeof(*data)); | 559 | data = malloc(sizeof(*data)); |
560 | if (!data) | ||
561 | return NULL; | ||
558 | memset(data, 0, sizeof(*data)); | 562 | memset(data, 0, sizeof(*data)); |
559 | 563 | ||
560 | data->ts = handle->cpu_data[cpu].timestamp; | 564 | data->ts = handle->cpu_data[cpu].timestamp; |
@@ -590,8 +594,10 @@ tracecmd_peek_data(struct tracecmd_handle *handle, int cpu) | |||
590 | 594 | ||
591 | if (!index) { | 595 | if (!index) { |
592 | /* FIXME: handle header page */ | 596 | /* FIXME: handle header page */ |
593 | if (header_page_ts_size != 8) | 597 | if (header_page_ts_size != 8) { |
594 | die("expected a long long type for timestamp"); | 598 | warning("expected a long long type for timestamp"); |
599 | return NULL; | ||
600 | } | ||
595 | handle->cpu_data[cpu].timestamp = data2host8(ptr); | 601 | handle->cpu_data[cpu].timestamp = data2host8(ptr); |
596 | ptr += 8; | 602 | ptr += 8; |
597 | switch (header_page_size_size) { | 603 | switch (header_page_size_size) { |
@@ -604,7 +610,8 @@ tracecmd_peek_data(struct tracecmd_handle *handle, int cpu) | |||
604 | ptr += 8; | 610 | ptr += 8; |
605 | break; | 611 | break; |
606 | default: | 612 | default: |
607 | die("bad long size"); | 613 | warning("bad long size"); |
614 | return NULL; | ||
608 | } | 615 | } |
609 | ptr = handle->cpu_data[cpu].page + header_page_data_offset; | 616 | ptr = handle->cpu_data[cpu].page + header_page_data_offset; |
610 | } | 617 | } |
@@ -613,7 +620,8 @@ read_again: | |||
613 | index = calc_index(handle, ptr, cpu); | 620 | index = calc_index(handle, ptr, cpu); |
614 | 621 | ||
615 | if (index >= handle->cpu_data[cpu].page_size) { | 622 | if (index >= handle->cpu_data[cpu].page_size) { |
616 | get_next_page(handle, cpu); | 623 | if (get_next_page(handle, cpu)) |
624 | return NULL; | ||
617 | return trace_peek_data(cpu); | 625 | return trace_peek_data(cpu); |
618 | } | 626 | } |
619 | 627 | ||
@@ -636,8 +644,10 @@ read_again: | |||
636 | 644 | ||
637 | switch (type_len) { | 645 | switch (type_len) { |
638 | case RINGBUF_TYPE_PADDING: | 646 | case RINGBUF_TYPE_PADDING: |
639 | if (!delta) | 647 | if (!delta) { |
640 | die("error, hit unexpected end of page"); | 648 | warning("error, hit unexpected end of page"); |
649 | return NULL; | ||
650 | } | ||
641 | length = data2host4(ptr); | 651 | length = data2host4(ptr); |
642 | ptr += 4; | 652 | ptr += 4; |
643 | length *= 4; | 653 | length *= 4; |
@@ -667,7 +677,9 @@ read_again: | |||
667 | 677 | ||
668 | handle->cpu_data[cpu].timestamp += delta; | 678 | handle->cpu_data[cpu].timestamp += delta; |
669 | 679 | ||
670 | data = malloc_or_die(sizeof(*data)); | 680 | data = malloc(sizeof(*data)); |
681 | if (!data) | ||
682 | return NULL; | ||
671 | memset(data, 0, sizeof(*data)); | 683 | memset(data, 0, sizeof(*data)); |
672 | 684 | ||
673 | data->ts = handle->cpu_data[cpu].timestamp; | 685 | data->ts = handle->cpu_data[cpu].timestamp; |
@@ -692,38 +704,40 @@ tracecmd_read_data(struct tracecmd_handle *handle, int cpu) | |||
692 | return data; | 704 | return data; |
693 | } | 705 | } |
694 | 706 | ||
695 | static void init_read(struct tracecmd_handle *handle, int cpu) | 707 | static int init_read(struct tracecmd_handle *handle, int cpu) |
696 | { | 708 | { |
697 | off64_t ret; | 709 | off64_t ret; |
698 | off64_t save_seek; | 710 | off64_t save_seek; |
699 | 711 | ||
700 | handle->cpu_data[cpu].page = malloc_or_die(handle->page_size); | 712 | handle->cpu_data[cpu].page = malloc(handle->page_size); |
713 | if (!handle->cpu_data[cpu].page) | ||
714 | return -1; | ||
701 | 715 | ||
702 | /* other parts of the code may expect the pointer to not move */ | 716 | /* other parts of the code may expect the pointer to not move */ |
703 | save_seek = lseek64(input_fd, 0, SEEK_CUR); | 717 | save_seek = lseek64(input_fd, 0, SEEK_CUR); |
704 | 718 | ||
705 | ret = lseek64(input_fd, (off64_t)handle->cpu_data[cpu].offset, SEEK_SET); | 719 | ret = lseek64(input_fd, (off64_t)handle->cpu_data[cpu].offset, SEEK_SET); |
706 | if (ret < 0) | 720 | if (ret < 0) |
707 | die("failed to lseek"); | 721 | return -1; |
708 | ret = read(input_fd, handle->cpu_data[cpu].page, handle->page_size); | 722 | ret = read(input_fd, handle->cpu_data[cpu].page, handle->page_size); |
709 | if (ret < 0) | 723 | if (ret < 0) |
710 | die("failed to read page"); | 724 | return -1; |
711 | 725 | ||
712 | /* reset the file pointer back */ | 726 | /* reset the file pointer back */ |
713 | lseek64(input_fd, save_seek, SEEK_SET); | 727 | lseek64(input_fd, save_seek, SEEK_SET); |
728 | |||
729 | return 0; | ||
714 | } | 730 | } |
715 | 731 | ||
716 | static void init_cpu(struct tracecmd_handle *handle, int cpu) | 732 | static int init_cpu(struct tracecmd_handle *handle, int cpu) |
717 | { | 733 | { |
718 | if (!handle->cpu_data[cpu].size) { | 734 | if (!handle->cpu_data[cpu].size) { |
719 | printf("CPU %d is empty\n", cpu); | 735 | printf("CPU %d is empty\n", cpu); |
720 | return; | 736 | return 0; |
721 | } | 737 | } |
722 | 738 | ||
723 | if (handle->read_page) { | 739 | if (handle->read_page) |
724 | init_read(handle, cpu); | 740 | return init_read(handle, cpu); |
725 | return; | ||
726 | } | ||
727 | 741 | ||
728 | handle->cpu_data[cpu].page = mmap(NULL, handle->page_size, PROT_READ, | 742 | handle->cpu_data[cpu].page = mmap(NULL, handle->page_size, PROT_READ, |
729 | MAP_PRIVATE, input_fd, handle->cpu_data[cpu].offset); | 743 | MAP_PRIVATE, input_fd, handle->cpu_data[cpu].offset); |
@@ -732,8 +746,9 @@ static void init_cpu(struct tracecmd_handle *handle, int cpu) | |||
732 | fprintf(stderr, "Can not mmap file, will read instead\n"); | 746 | fprintf(stderr, "Can not mmap file, will read instead\n"); |
733 | handle->read_page = 1; | 747 | handle->read_page = 1; |
734 | 748 | ||
735 | init_read(handle, cpu); | 749 | return init_read(handle, cpu); |
736 | } | 750 | } |
751 | return 0; | ||
737 | } | 752 | } |
738 | 753 | ||
739 | int tracecmd_init_data(struct tracecmd_handle *handle) | 754 | int tracecmd_init_data(struct tracecmd_handle *handle) |
@@ -780,7 +795,8 @@ int tracecmd_init_data(struct tracecmd_handle *handle) | |||
780 | handle->cpu_data[cpu].offset = read8(handle); | 795 | handle->cpu_data[cpu].offset = read8(handle); |
781 | handle->cpu_data[cpu].size = read8(handle); | 796 | handle->cpu_data[cpu].size = read8(handle); |
782 | 797 | ||
783 | init_cpu(handle, cpu); | 798 | if (init_cpu(handle, cpu)) |
799 | return -1; | ||
784 | } | 800 | } |
785 | 801 | ||
786 | return 0; | 802 | return 0; |