aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--trace-cmd.h4
-rw-r--r--trace-input.c47
-rw-r--r--trace-output.c28
4 files changed, 77 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index b094abe..6cd9b93 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ KS_PATCHLEVEL = 2
9KS_EXTRAVERSION = 9KS_EXTRAVERSION =
10 10
11# file format version 11# file format version
12FILE_VERSION = 5 12FILE_VERSION = 6
13 13
14MAKEFLAGS += --no-print-directory 14MAKEFLAGS += --no-print-directory
15 15
diff --git a/trace-cmd.h b/trace-cmd.h
index 7e21bc7..b484998 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -61,6 +61,10 @@ char *tracecmd_find_tracing_dir(void);
61 61
62/* --- Opening and Reading the trace.dat file --- */ 62/* --- Opening and Reading the trace.dat file --- */
63 63
64enum {
65 TRACECMD_OPTION_DONE,
66};
67
64struct tracecmd_input *tracecmd_alloc(const char *file); 68struct tracecmd_input *tracecmd_alloc(const char *file);
65struct tracecmd_input *tracecmd_alloc_fd(int fd); 69struct tracecmd_input *tracecmd_alloc_fd(int fd);
66struct tracecmd_input *tracecmd_open(const char *file); 70struct tracecmd_input *tracecmd_open(const char *file);
diff --git a/trace-input.c b/trace-input.c
index fed915d..c919cd0 100644
--- a/trace-input.c
+++ b/trace-input.c
@@ -1747,6 +1747,36 @@ static int init_cpu(struct tracecmd_input *handle, int cpu)
1747 return 0; 1747 return 0;
1748} 1748}
1749 1749
1750static int handle_options(struct tracecmd_input *handle)
1751{
1752 unsigned short option;
1753 unsigned int size;
1754 char *buf;
1755
1756 do {
1757 if (do_read_check(handle, &option, 2))
1758 return -1;
1759
1760 switch (option) {
1761 case TRACECMD_OPTION_DONE:
1762 break;
1763 default:
1764 warning("unknown option %d", option);
1765 /* next 4 bytes is the size of the option */
1766 if (do_read_check(handle, &size, 4))
1767 return -1;
1768 size = __data2host4(handle->pevent, size);
1769 buf = malloc_or_die(size);
1770 if (do_read_check(handle, buf, size))
1771 return -1;
1772 free(buf);
1773 break;
1774 }
1775 } while (option != TRACECMD_OPTION_DONE);
1776
1777 return 0;
1778}
1779
1750/** 1780/**
1751 * tracecmd_init_data - prepare reading the data from trace.dat 1781 * tracecmd_init_data - prepare reading the data from trace.dat
1752 * @handle: input handle for the trace.dat file 1782 * @handle: input handle for the trace.dat file
@@ -1783,14 +1813,27 @@ int tracecmd_init_data(struct tracecmd_input *handle)
1783 pevent_set_cpus(pevent, handle->cpus); 1813 pevent_set_cpus(pevent, handle->cpus);
1784 pevent_set_long_size(pevent, handle->long_size); 1814 pevent_set_long_size(pevent, handle->long_size);
1785 1815
1816 if (do_read_check(handle, buf, 10))
1817 return -1;
1818
1819 /* check if this handles options */
1820 if (strncmp(buf, "options", 7) == 0) {
1821 if (handle_options(handle) < 0)
1822 return -1;
1823 if (do_read_check(handle, buf, 10))
1824 return -1;
1825 }
1826
1786 /* 1827 /*
1787 * Check if this is a latency report or not. 1828 * Check if this is a latency report or not.
1788 */ 1829 */
1789 if (do_read_check(handle, buf, 10))
1790 return -1;
1791 if (strncmp(buf, "latency", 7) == 0) 1830 if (strncmp(buf, "latency", 7) == 0)
1792 return 1; 1831 return 1;
1793 1832
1833 /* We expect this to be flyrecord */
1834 if (strncmp(buf, "flyrecord", 9) != 0)
1835 return -1;
1836
1794 handle->cpu_data = malloc(sizeof(*handle->cpu_data) * handle->cpus); 1837 handle->cpu_data = malloc(sizeof(*handle->cpu_data) * handle->cpus);
1795 if (!handle->cpu_data) 1838 if (!handle->cpu_data)
1796 return -1; 1839 return -1;
diff --git a/trace-output.c b/trace-output.c
index b586846..89b3954 100644
--- a/trace-output.c
+++ b/trace-output.c
@@ -327,7 +327,7 @@ static int copy_event_system(struct tracecmd_output *handle, const char *sys)
327 endian4 = convert_endian_4(handle, count); 327 endian4 = convert_endian_4(handle, count);
328 if (do_write_check(handle, &endian4, 4)) 328 if (do_write_check(handle, &endian4, 4))
329 return -1; 329 return -1;
330 330
331 rewinddir(dir); 331 rewinddir(dir);
332 while ((dent = readdir(dir))) { 332 while ((dent = readdir(dir))) {
333 if (strcmp(dent->d_name, ".") == 0 || 333 if (strcmp(dent->d_name, ".") == 0 ||
@@ -648,6 +648,26 @@ static struct tracecmd_output *create_file(const char *output_file, int cpus,
648 return handle; 648 return handle;
649} 649}
650 650
651static int add_options(struct tracecmd_output *handle)
652{
653 unsigned short option;
654
655 if (do_write_check(handle, "options ", 10))
656 return -1;
657
658 /*
659 * Right now we have no options, but this is where options
660 * will be added in the future.
661 */
662
663 option = TRACECMD_OPTION_DONE;
664
665 if (do_write_check(handle, &option, 2))
666 return -1;
667
668 return 0;
669}
670
651struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus) 671struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus)
652{ 672{
653 struct tracecmd_output *handle; 673 struct tracecmd_output *handle;
@@ -661,6 +681,9 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in
661 if (do_write_check(handle, &cpus, 4)) 681 if (do_write_check(handle, &cpus, 4))
662 goto out_free; 682 goto out_free;
663 683
684 if (add_options(handle) < 0)
685 goto out_free;
686
664 if (do_write_check(handle, "latency ", 10)) 687 if (do_write_check(handle, "latency ", 10))
665 goto out_free; 688 goto out_free;
666 689
@@ -697,6 +720,9 @@ int tracecmd_append_cpu_data(struct tracecmd_output *handle,
697 if (do_write_check(handle, &endian4, 4)) 720 if (do_write_check(handle, &endian4, 4))
698 goto out_free; 721 goto out_free;
699 722
723 if (add_options(handle) < 0)
724 goto out_free;
725
700 if (do_write_check(handle, "flyrecord", 10)) 726 if (do_write_check(handle, "flyrecord", 10))
701 goto out_free; 727 goto out_free;
702 728