diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-07-17 19:35:14 -0400 |
---|---|---|
committer | Steven Rostedt <srostedt@redhat.com> | 2009-07-17 19:37:19 -0400 |
commit | d52dd1f4601dc2c1de730b52c3e00267740b79c5 (patch) | |
tree | 0f09bd55e0dc501410117b77b6678fb900a4e853 /trace-cmd.c | |
parent | 4de0b9baa56cb9e7164b5cfc6ead489c0d1c8e53 (diff) |
Use arch page size instead of hard coded 4096
Archs may use different page sizes. We must use the target arch page
size for this instead of just hard coding 4096. This must also be saved
in the data file so that it can be read by the host data.
Also fixed the bigendian routine on the recording side.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Diffstat (limited to 'trace-cmd.c')
-rw-r--r-- | trace-cmd.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/trace-cmd.c b/trace-cmd.c index 72f070b..12581bc 100644 --- a/trace-cmd.c +++ b/trace-cmd.c | |||
@@ -49,6 +49,8 @@ | |||
49 | #define ITER_CTRL "trace_options" | 49 | #define ITER_CTRL "trace_options" |
50 | #define MAX_LATENCY "tracing_max_latency" | 50 | #define MAX_LATENCY "tracing_max_latency" |
51 | 51 | ||
52 | unsigned int page_size; | ||
53 | |||
52 | static const char *output_file = "trace.dat"; | 54 | static const char *output_file = "trace.dat"; |
53 | static int output_fd; | 55 | static int output_fd; |
54 | 56 | ||
@@ -513,7 +515,7 @@ static int create_recorder(int cpu) | |||
513 | int brass[2]; | 515 | int brass[2]; |
514 | int pid; | 516 | int pid; |
515 | int ret; | 517 | int ret; |
516 | char buf[PAGE_SIZE]; | 518 | char buf[page_size]; |
517 | 519 | ||
518 | pid = fork(); | 520 | pid = fork(); |
519 | if (pid < 0) | 521 | if (pid < 0) |
@@ -547,13 +549,13 @@ static int create_recorder(int cpu) | |||
547 | die("can not create pipe"); | 549 | die("can not create pipe"); |
548 | 550 | ||
549 | do { | 551 | do { |
550 | ret = splice(in_fd, NULL, brass[1], NULL, PAGE_SIZE, 1 /* SPLICE_F_MOVE */); | 552 | ret = splice(in_fd, NULL, brass[1], NULL, page_size, 1 /* SPLICE_F_MOVE */); |
551 | if (ret < 0) { | 553 | if (ret < 0) { |
552 | perror("in"); | 554 | perror("in"); |
553 | printf("errno=%d\n", errno); | 555 | printf("errno=%d\n", errno); |
554 | die("splice in"); | 556 | die("splice in"); |
555 | } | 557 | } |
556 | ret = splice(brass[0], NULL, out_fd, NULL, PAGE_SIZE, 3 /* and NON_BLOCK */); | 558 | ret = splice(brass[0], NULL, out_fd, NULL, page_size, 3 /* and NON_BLOCK */); |
557 | if (ret < 0 && errno != EAGAIN) { | 559 | if (ret < 0 && errno != EAGAIN) { |
558 | perror("in"); | 560 | perror("in"); |
559 | printf("errno=%d\n", errno); | 561 | printf("errno=%d\n", errno); |
@@ -563,7 +565,7 @@ static int create_recorder(int cpu) | |||
563 | 565 | ||
564 | /* splice only reads full pages */ | 566 | /* splice only reads full pages */ |
565 | do { | 567 | do { |
566 | ret = read(in_fd, buf, PAGE_SIZE); | 568 | ret = read(in_fd, buf, page_size); |
567 | if (ret > 0) | 569 | if (ret > 0) |
568 | write(out_fd, buf, ret); | 570 | write(out_fd, buf, ret); |
569 | } while (ret > 0); | 571 | } while (ret > 0); |
@@ -601,13 +603,13 @@ static ssize_t write_or_die(const void *buf, size_t len) | |||
601 | return ret; | 603 | return ret; |
602 | } | 604 | } |
603 | 605 | ||
604 | static int bigendian(void) | 606 | int bigendian(void) |
605 | { | 607 | { |
606 | unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 }; | 608 | unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 }; |
607 | unsigned int *ptr; | 609 | unsigned int *ptr; |
608 | 610 | ||
609 | ptr = (unsigned int *)str; | 611 | ptr = (unsigned int *)str; |
610 | return *ptr == 0x1234; | 612 | return *ptr == 0x01020304; |
611 | } | 613 | } |
612 | 614 | ||
613 | static unsigned long long copy_file_fd(int fd) | 615 | static unsigned long long copy_file_fd(int fd) |
@@ -864,6 +866,7 @@ static void read_tracing_data(void) | |||
864 | 866 | ||
865 | write_or_die(VERSION, strlen(VERSION) + 1); | 867 | write_or_die(VERSION, strlen(VERSION) + 1); |
866 | 868 | ||
869 | /* save endian */ | ||
867 | if (bigendian()) | 870 | if (bigendian()) |
868 | buf[0] = 1; | 871 | buf[0] = 1; |
869 | else | 872 | else |
@@ -871,9 +874,14 @@ static void read_tracing_data(void) | |||
871 | 874 | ||
872 | write_or_die(buf, 1); | 875 | write_or_die(buf, 1); |
873 | 876 | ||
877 | /* save size of long */ | ||
874 | buf[0] = sizeof(long); | 878 | buf[0] = sizeof(long); |
875 | write_or_die(buf, 1); | 879 | write_or_die(buf, 1); |
876 | 880 | ||
881 | /* save page_size */ | ||
882 | page_size = getpagesize(); | ||
883 | write_or_die(&page_size, 4); | ||
884 | |||
877 | read_header_files(); | 885 | read_header_files(); |
878 | read_ftrace_files(); | 886 | read_ftrace_files(); |
879 | read_event_files(); | 887 | read_event_files(); |
@@ -947,7 +955,7 @@ static void read_thread_data(void) | |||
947 | 955 | ||
948 | /* hold any extra data for data */ | 956 | /* hold any extra data for data */ |
949 | offset += cpu_count * (16); | 957 | offset += cpu_count * (16); |
950 | offset = (offset + (PAGE_SIZE - 1)) & ~(PAGE_MASK); | 958 | offset = (offset + (page_size - 1)) & ~(PAGE_MASK); |
951 | 959 | ||
952 | for (i = 0; i < cpu_count; i++) { | 960 | for (i = 0; i < cpu_count; i++) { |
953 | file = malloc_or_die(strlen(output_file) + 20); | 961 | file = malloc_or_die(strlen(output_file) + 20); |
@@ -959,7 +967,7 @@ static void read_thread_data(void) | |||
959 | offsets[i] = offset; | 967 | offsets[i] = offset; |
960 | sizes[i] = st.st_size; | 968 | sizes[i] = st.st_size; |
961 | offset += st.st_size; | 969 | offset += st.st_size; |
962 | offset = (offset + (PAGE_SIZE - 1)) & ~(PAGE_MASK); | 970 | offset = (offset + (page_size - 1)) & ~(PAGE_MASK); |
963 | 971 | ||
964 | write_or_die(&offsets[i], 8); | 972 | write_or_die(&offsets[i], 8); |
965 | write_or_die(&sizes[i], 8); | 973 | write_or_die(&sizes[i], 8); |