diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-11-15 09:46:17 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-11-15 09:46:17 -0500 |
commit | 93b3117efefb9d4f4b5b1fe751aa706f6d569af7 (patch) | |
tree | 3a82bb2fef8bd87e22c6e89cde4167b7da68adb4 | |
parent | a027c04554674d2a138236a0d7610d5f9ee1d8de (diff) |
trace-cmd: Add ability to add options to trace.dat
Add tracecmd_add_option that allows us to add options into the
trace.dat file. Currently, options may only be added before
the file has been written.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-output.c | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/trace-output.c b/trace-output.c index 14fe0f1..d9d1845 100644 --- a/trace-output.c +++ b/trace-output.c | |||
@@ -39,12 +39,21 @@ | |||
39 | #include "trace-cmd-local.h" | 39 | #include "trace-cmd-local.h" |
40 | #include "version.h" | 40 | #include "version.h" |
41 | 41 | ||
42 | struct tracecmd_option { | ||
43 | unsigned short id; | ||
44 | int size; | ||
45 | void *data; | ||
46 | }; | ||
47 | |||
42 | struct tracecmd_output { | 48 | struct tracecmd_output { |
43 | int fd; | 49 | int fd; |
44 | int page_size; | 50 | int page_size; |
45 | int cpus; | 51 | int cpus; |
46 | struct pevent *pevent; | 52 | struct pevent *pevent; |
47 | char *tracing_dir; | 53 | char *tracing_dir; |
54 | int options_written; | ||
55 | int nr_options; | ||
56 | struct tracecmd_option *options; | ||
48 | }; | 57 | }; |
49 | 58 | ||
50 | static int | 59 | static int |
@@ -72,6 +81,8 @@ static unsigned long long convert_endian_8(struct tracecmd_output *handle, | |||
72 | 81 | ||
73 | void tracecmd_output_close(struct tracecmd_output *handle) | 82 | void tracecmd_output_close(struct tracecmd_output *handle) |
74 | { | 83 | { |
84 | int i; | ||
85 | |||
75 | if (!handle) | 86 | if (!handle) |
76 | return; | 87 | return; |
77 | 88 | ||
@@ -86,6 +97,12 @@ void tracecmd_output_close(struct tracecmd_output *handle) | |||
86 | if (handle->pevent) | 97 | if (handle->pevent) |
87 | pevent_unref(handle->pevent); | 98 | pevent_unref(handle->pevent); |
88 | 99 | ||
100 | if (handle->options) { | ||
101 | for (i = 0; i < handle->nr_options; i++) | ||
102 | free(handle->options[i].data); | ||
103 | free(handle->options); | ||
104 | } | ||
105 | |||
89 | free(handle); | 106 | free(handle); |
90 | } | 107 | } |
91 | 108 | ||
@@ -648,23 +665,75 @@ static struct tracecmd_output *create_file(const char *output_file, | |||
648 | return handle; | 665 | return handle; |
649 | } | 666 | } |
650 | 667 | ||
668 | /** | ||
669 | * tracecmd_add_option - add options to the file | ||
670 | * @handle: the output file handle name | ||
671 | * @id: the id of the option | ||
672 | * @size: the size of the option data | ||
673 | * @data: the data to write to the file. | ||
674 | */ | ||
675 | int tracecmd_add_option(struct tracecmd_output *handle, | ||
676 | unsigned short id, | ||
677 | int size, void *data) | ||
678 | { | ||
679 | int index = handle->nr_options; | ||
680 | |||
681 | /* | ||
682 | * We can only add options before they were written. | ||
683 | * This may change in the future. | ||
684 | */ | ||
685 | if (handle->options_written) | ||
686 | return -EBUSY; | ||
687 | |||
688 | handle->nr_options++; | ||
689 | |||
690 | if (!handle->options) | ||
691 | handle->options = malloc_or_die(sizeof(*handle->options)); | ||
692 | else { | ||
693 | handle->options = realloc(handle->options, | ||
694 | sizeof(*handle->options) * handle->nr_options); | ||
695 | if (!handle->options) | ||
696 | die("Could not reallocate space for options"); | ||
697 | } | ||
698 | |||
699 | handle->options[index].id = id; | ||
700 | handle->options[index].size = size; | ||
701 | handle->options[index].data = malloc_or_die(size); | ||
702 | memcpy(handle->options[index].data, data, size); | ||
703 | |||
704 | return 0; | ||
705 | } | ||
706 | |||
651 | static int add_options(struct tracecmd_output *handle) | 707 | static int add_options(struct tracecmd_output *handle) |
652 | { | 708 | { |
653 | unsigned short option; | 709 | unsigned short option; |
710 | int i; | ||
711 | |||
712 | if (handle->options_written) | ||
713 | die("options already written?"); | ||
654 | 714 | ||
655 | if (do_write_check(handle, "options ", 10)) | 715 | if (do_write_check(handle, "options ", 10)) |
656 | return -1; | 716 | return -1; |
657 | 717 | ||
658 | /* | 718 | for (i = 0; i < handle->nr_options; i++) { |
659 | * Right now we have no options, but this is where options | 719 | if (do_write_check(handle, &handle->options[i].id, 2)) |
660 | * will be added in the future. | 720 | return -1; |
661 | */ | 721 | |
722 | if (do_write_check(handle, &handle->options[i].size, 4)) | ||
723 | return -1; | ||
724 | |||
725 | if (do_write_check(handle, &handle->options[i].data, | ||
726 | handle->options[i].size)) | ||
727 | return -1; | ||
728 | } | ||
662 | 729 | ||
663 | option = TRACECMD_OPTION_DONE; | 730 | option = TRACECMD_OPTION_DONE; |
664 | 731 | ||
665 | if (do_write_check(handle, &option, 2)) | 732 | if (do_write_check(handle, &option, 2)) |
666 | return -1; | 733 | return -1; |
667 | 734 | ||
735 | handle->options_written = 1; | ||
736 | |||
668 | return 0; | 737 | return 0; |
669 | } | 738 | } |
670 | 739 | ||