diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2010-02-05 10:28:18 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2010-02-05 10:28:18 -0500 |
| commit | e85b5f74e0bc8300ad1213e320f071f10be4f724 (patch) | |
| tree | 1e2c97700a6cfac93dca8e5b44e941e6ee5595fd | |
| parent | fb33c621b0c7066129486f5b7c40b70703d88a43 (diff) | |
trace-cmd: Fix trace-cmd split to handle different endianess
If a little endian host splits a big endian file, the result is
a mixture of little and big endian numbers. This patch fixes this
by making sure the endianess of the file stays the same.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | trace-output.c | 84 | ||||
| -rw-r--r-- | trace-split.c | 13 |
2 files changed, 72 insertions, 25 deletions
diff --git a/trace-output.c b/trace-output.c index 207a53a..aa251fe 100644 --- a/trace-output.c +++ b/trace-output.c | |||
| @@ -23,6 +23,7 @@ struct tracecmd_output { | |||
| 23 | int fd; | 23 | int fd; |
| 24 | int page_size; | 24 | int page_size; |
| 25 | int cpus; | 25 | int cpus; |
| 26 | struct pevent *pevent; | ||
| 26 | char *tracing_dir; | 27 | char *tracing_dir; |
| 27 | }; | 28 | }; |
| 28 | 29 | ||
| @@ -32,6 +33,23 @@ do_write_check(struct tracecmd_output *handle, void *data, int size) | |||
| 32 | return __do_write_check(handle->fd, data, size); | 33 | return __do_write_check(handle->fd, data, size); |
| 33 | } | 34 | } |
| 34 | 35 | ||
| 36 | static int convert_endian_4(struct tracecmd_output *handle, int val) | ||
| 37 | { | ||
| 38 | if (!handle->pevent) | ||
| 39 | return val; | ||
| 40 | |||
| 41 | return __data2host4(handle->pevent, val); | ||
| 42 | } | ||
| 43 | |||
| 44 | static unsigned long long convert_endian_8(struct tracecmd_output *handle, | ||
| 45 | unsigned long long val) | ||
| 46 | { | ||
| 47 | if (!handle->pevent) | ||
| 48 | return val; | ||
| 49 | |||
| 50 | return __data2host8(handle->pevent, val); | ||
| 51 | } | ||
| 52 | |||
| 35 | void tracecmd_output_close(struct tracecmd_output *handle) | 53 | void tracecmd_output_close(struct tracecmd_output *handle) |
| 36 | { | 54 | { |
| 37 | if (!handle) | 55 | if (!handle) |
| @@ -45,6 +63,9 @@ void tracecmd_output_close(struct tracecmd_output *handle) | |||
| 45 | if (handle->tracing_dir) | 63 | if (handle->tracing_dir) |
| 46 | free(handle->tracing_dir); | 64 | free(handle->tracing_dir); |
| 47 | 65 | ||
| 66 | if (handle->pevent) | ||
| 67 | pevent_unref(handle->pevent); | ||
| 68 | |||
| 48 | free(handle); | 69 | free(handle); |
| 49 | } | 70 | } |
| 50 | 71 | ||
| @@ -172,7 +193,7 @@ int tracecmd_ftrace_enable(int set) | |||
| 172 | 193 | ||
| 173 | static int read_header_files(struct tracecmd_output *handle) | 194 | static int read_header_files(struct tracecmd_output *handle) |
| 174 | { | 195 | { |
| 175 | unsigned long long size, check_size; | 196 | unsigned long long size, check_size, endian8; |
| 176 | struct stat st; | 197 | struct stat st; |
| 177 | char *path; | 198 | char *path; |
| 178 | int fd; | 199 | int fd; |
| @@ -209,7 +230,8 @@ static int read_header_files(struct tracecmd_output *handle) | |||
| 209 | 230 | ||
| 210 | if (do_write_check(handle, "header_page", 12)) | 231 | if (do_write_check(handle, "header_page", 12)) |
| 211 | goto out_close; | 232 | goto out_close; |
| 212 | if (do_write_check(handle, &size, 8)) | 233 | endian8 = convert_endian_8(handle, size); |
| 234 | if (do_write_check(handle, &endian8, 8)) | ||
| 213 | goto out_close; | 235 | goto out_close; |
| 214 | check_size = copy_file_fd(handle, fd); | 236 | check_size = copy_file_fd(handle, fd); |
| 215 | close(fd); | 237 | close(fd); |
| @@ -233,7 +255,8 @@ static int read_header_files(struct tracecmd_output *handle) | |||
| 233 | 255 | ||
| 234 | if (do_write_check(handle, "header_event", 13)) | 256 | if (do_write_check(handle, "header_event", 13)) |
| 235 | goto out_close; | 257 | goto out_close; |
| 236 | if (do_write_check(handle, &size, 8)) | 258 | endian8 = convert_endian_8(handle, size); |
| 259 | if (do_write_check(handle, &endian8, 8)) | ||
| 237 | goto out_close; | 260 | goto out_close; |
| 238 | check_size = copy_file_fd(handle, fd); | 261 | check_size = copy_file_fd(handle, fd); |
| 239 | close(fd); | 262 | close(fd); |
| @@ -251,11 +274,12 @@ static int read_header_files(struct tracecmd_output *handle) | |||
| 251 | 274 | ||
| 252 | static int copy_event_system(struct tracecmd_output *handle, const char *sys) | 275 | static int copy_event_system(struct tracecmd_output *handle, const char *sys) |
| 253 | { | 276 | { |
| 254 | unsigned long long size, check_size; | 277 | unsigned long long size, check_size, endian8; |
| 255 | struct dirent *dent; | 278 | struct dirent *dent; |
| 256 | struct stat st; | 279 | struct stat st; |
| 257 | char *format; | 280 | char *format; |
| 258 | DIR *dir; | 281 | DIR *dir; |
| 282 | int endian4; | ||
| 259 | int count = 0; | 283 | int count = 0; |
| 260 | int ret; | 284 | int ret; |
| 261 | 285 | ||
| @@ -280,7 +304,8 @@ static int copy_event_system(struct tracecmd_output *handle, const char *sys) | |||
| 280 | count++; | 304 | count++; |
| 281 | } | 305 | } |
| 282 | 306 | ||
| 283 | if (do_write_check(handle, &count, 4)) | 307 | endian4 = convert_endian_4(handle, count); |
| 308 | if (do_write_check(handle, &endian4, 4)) | ||
| 284 | return -1; | 309 | return -1; |
| 285 | 310 | ||
| 286 | rewinddir(dir); | 311 | rewinddir(dir); |
| @@ -297,7 +322,8 @@ static int copy_event_system(struct tracecmd_output *handle, const char *sys) | |||
| 297 | if (ret >= 0) { | 322 | if (ret >= 0) { |
| 298 | /* unfortunately, you can not stat debugfs files for size */ | 323 | /* unfortunately, you can not stat debugfs files for size */ |
| 299 | size = get_size(format); | 324 | size = get_size(format); |
| 300 | if (do_write_check(handle, &size, 8)) | 325 | endian8 = convert_endian_8(handle, size); |
| 326 | if (do_write_check(handle, &endian8, 8)) | ||
| 301 | goto out_free; | 327 | goto out_free; |
| 302 | check_size = copy_file(handle, format); | 328 | check_size = copy_file(handle, format); |
| 303 | if (size != check_size) { | 329 | if (size != check_size) { |
| @@ -340,6 +366,7 @@ static int read_event_files(struct tracecmd_output *handle) | |||
| 340 | char *sys; | 366 | char *sys; |
| 341 | DIR *dir; | 367 | DIR *dir; |
| 342 | int count = 0; | 368 | int count = 0; |
| 369 | int endian4; | ||
| 343 | int ret; | 370 | int ret; |
| 344 | 371 | ||
| 345 | path = get_tracing_file(handle, "events"); | 372 | path = get_tracing_file(handle, "events"); |
| @@ -369,7 +396,8 @@ static int read_event_files(struct tracecmd_output *handle) | |||
| 369 | } | 396 | } |
| 370 | 397 | ||
| 371 | ret = -1; | 398 | ret = -1; |
| 372 | if (do_write_check(handle, &count, 4)) | 399 | endian4 = convert_endian_4(handle, count); |
| 400 | if (do_write_check(handle, &endian4, 4)) | ||
| 373 | goto out_close_dir; | 401 | goto out_close_dir; |
| 374 | 402 | ||
| 375 | rewinddir(dir); | 403 | rewinddir(dir); |
| @@ -410,7 +438,7 @@ static int read_event_files(struct tracecmd_output *handle) | |||
| 410 | 438 | ||
| 411 | static int read_proc_kallsyms(struct tracecmd_output *handle) | 439 | static int read_proc_kallsyms(struct tracecmd_output *handle) |
| 412 | { | 440 | { |
| 413 | unsigned int size, check_size; | 441 | unsigned int size, check_size, endian4; |
| 414 | const char *path = "/proc/kallsyms"; | 442 | const char *path = "/proc/kallsyms"; |
| 415 | struct stat st; | 443 | struct stat st; |
| 416 | int ret; | 444 | int ret; |
| @@ -419,12 +447,14 @@ static int read_proc_kallsyms(struct tracecmd_output *handle) | |||
| 419 | if (ret < 0) { | 447 | if (ret < 0) { |
| 420 | /* not found */ | 448 | /* not found */ |
| 421 | size = 0; | 449 | size = 0; |
| 422 | if (do_write_check(handle, &size, 4)) | 450 | endian4 = convert_endian_4(handle, size); |
| 451 | if (do_write_check(handle, &endian4, 4)) | ||
| 423 | return -1; | 452 | return -1; |
| 424 | return 0; | 453 | return 0; |
| 425 | } | 454 | } |
| 426 | size = get_size(path); | 455 | size = get_size(path); |
| 427 | if (do_write_check(handle, &size, 4)) | 456 | endian4 = convert_endian_4(handle, size); |
| 457 | if (do_write_check(handle, &endian4, 4)) | ||
| 428 | return -1; | 458 | return -1; |
| 429 | check_size = copy_file(handle, path); | 459 | check_size = copy_file(handle, path); |
| 430 | if (size != check_size) { | 460 | if (size != check_size) { |
| @@ -438,7 +468,7 @@ static int read_proc_kallsyms(struct tracecmd_output *handle) | |||
| 438 | 468 | ||
| 439 | static int read_ftrace_printk(struct tracecmd_output *handle) | 469 | static int read_ftrace_printk(struct tracecmd_output *handle) |
| 440 | { | 470 | { |
| 441 | unsigned int size, check_size; | 471 | unsigned int size, check_size, endian4; |
| 442 | const char *path; | 472 | const char *path; |
| 443 | struct stat st; | 473 | struct stat st; |
| 444 | int ret; | 474 | int ret; |
| @@ -451,12 +481,14 @@ static int read_ftrace_printk(struct tracecmd_output *handle) | |||
| 451 | if (ret < 0) { | 481 | if (ret < 0) { |
| 452 | /* not found */ | 482 | /* not found */ |
| 453 | size = 0; | 483 | size = 0; |
| 454 | if (do_write_check(handle, &size, 4)) | 484 | endian4 = convert_endian_4(handle, size); |
| 485 | if (do_write_check(handle, &endian4, 4)) | ||
| 455 | return -1; | 486 | return -1; |
| 456 | return 0; | 487 | return 0; |
| 457 | } | 488 | } |
| 458 | size = get_size(path); | 489 | size = get_size(path); |
| 459 | if (do_write_check(handle, &size, 4)) | 490 | endian4 = convert_endian_4(handle, size); |
| 491 | if (do_write_check(handle, &endian4, 4)) | ||
| 460 | return -1; | 492 | return -1; |
| 461 | check_size = copy_file(handle, path); | 493 | check_size = copy_file(handle, path); |
| 462 | if (size != check_size) { | 494 | if (size != check_size) { |
| @@ -472,12 +504,14 @@ static struct tracecmd_output *create_file(const char *output_file, int cpus, | |||
| 472 | struct tracecmd_input *ihandle) | 504 | struct tracecmd_input *ihandle) |
| 473 | { | 505 | { |
| 474 | struct tracecmd_output *handle; | 506 | struct tracecmd_output *handle; |
| 507 | unsigned long long endian8; | ||
| 475 | struct pevent *pevent; | 508 | struct pevent *pevent; |
| 476 | char buf[BUFSIZ]; | 509 | char buf[BUFSIZ]; |
| 477 | char *file = NULL; | 510 | char *file = NULL; |
| 478 | struct stat st; | 511 | struct stat st; |
| 479 | off64_t check_size; | 512 | off64_t check_size; |
| 480 | off64_t size; | 513 | off64_t size; |
| 514 | int endian4; | ||
| 481 | int ret; | 515 | int ret; |
| 482 | 516 | ||
| 483 | handle = malloc(sizeof(*handle)); | 517 | handle = malloc(sizeof(*handle)); |
| @@ -503,6 +537,9 @@ static struct tracecmd_output *create_file(const char *output_file, int cpus, | |||
| 503 | /* get endian and page size */ | 537 | /* get endian and page size */ |
| 504 | if (ihandle) { | 538 | if (ihandle) { |
| 505 | pevent = tracecmd_get_pevent(ihandle); | 539 | pevent = tracecmd_get_pevent(ihandle); |
| 540 | /* Use the pevent of the ihandle for later writes */ | ||
| 541 | handle->pevent = tracecmd_get_pevent(ihandle); | ||
| 542 | pevent_ref(pevent); | ||
| 506 | if (pevent->file_bigendian) | 543 | if (pevent->file_bigendian) |
| 507 | buf[0] = 1; | 544 | buf[0] = 1; |
| 508 | else | 545 | else |
| @@ -524,7 +561,8 @@ static struct tracecmd_output *create_file(const char *output_file, int cpus, | |||
| 524 | if (do_write_check(handle, buf, 1)) | 561 | if (do_write_check(handle, buf, 1)) |
| 525 | goto out_free; | 562 | goto out_free; |
| 526 | 563 | ||
| 527 | if (do_write_check(handle, &handle->page_size, 4)) | 564 | endian4 = convert_endian_4(handle, handle->page_size); |
| 565 | if (do_write_check(handle, &endian4, 4)) | ||
| 528 | goto out_free; | 566 | goto out_free; |
| 529 | 567 | ||
| 530 | if (ihandle) | 568 | if (ihandle) |
| @@ -548,7 +586,8 @@ static struct tracecmd_output *create_file(const char *output_file, int cpus, | |||
| 548 | ret = stat(file, &st); | 586 | ret = stat(file, &st); |
| 549 | if (ret >= 0) { | 587 | if (ret >= 0) { |
| 550 | size = get_size(file); | 588 | size = get_size(file); |
| 551 | if (do_write_check(handle, &size, 8)) | 589 | endian8 = convert_endian_8(handle, size); |
| 590 | if (do_write_check(handle, &endian8, 8)) | ||
| 552 | goto out_free; | 591 | goto out_free; |
| 553 | check_size = copy_file(handle, file); | 592 | check_size = copy_file(handle, file); |
| 554 | if (size != check_size) { | 593 | if (size != check_size) { |
| @@ -558,7 +597,8 @@ static struct tracecmd_output *create_file(const char *output_file, int cpus, | |||
| 558 | } | 597 | } |
| 559 | } else { | 598 | } else { |
| 560 | size = 0; | 599 | size = 0; |
| 561 | if (do_write_check(handle, &size, 8)) | 600 | endian8 = convert_endian_8(handle, size); |
| 601 | if (do_write_check(handle, &endian8, 8)) | ||
| 562 | goto out_free; | 602 | goto out_free; |
| 563 | } | 603 | } |
| 564 | put_tracing_file(file); | 604 | put_tracing_file(file); |
| @@ -580,6 +620,7 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in | |||
| 580 | if (!handle) | 620 | if (!handle) |
| 581 | return NULL; | 621 | return NULL; |
| 582 | 622 | ||
| 623 | cpus = convert_endian_4(handle, cpus); | ||
| 583 | if (do_write_check(handle, &cpus, 4)) | 624 | if (do_write_check(handle, &cpus, 4)) |
| 584 | goto out_free; | 625 | goto out_free; |
| 585 | 626 | ||
| @@ -607,13 +648,16 @@ int tracecmd_append_cpu_data(struct tracecmd_output *handle, | |||
| 607 | unsigned long long *offsets = NULL; | 648 | unsigned long long *offsets = NULL; |
| 608 | unsigned long long *sizes = NULL; | 649 | unsigned long long *sizes = NULL; |
| 609 | unsigned long long offset; | 650 | unsigned long long offset; |
| 651 | unsigned long long endian8; | ||
| 610 | off64_t check_size; | 652 | off64_t check_size; |
| 611 | char *file; | 653 | char *file; |
| 612 | struct stat st; | 654 | struct stat st; |
| 655 | int endian4; | ||
| 613 | int ret; | 656 | int ret; |
| 614 | int i; | 657 | int i; |
| 615 | 658 | ||
| 616 | if (do_write_check(handle, &cpus, 4)) | 659 | endian4 = convert_endian_4(handle, cpus); |
| 660 | if (do_write_check(handle, &endian4, 4)) | ||
| 617 | goto out_free; | 661 | goto out_free; |
| 618 | 662 | ||
| 619 | if (do_write_check(handle, "flyrecord", 10)) | 663 | if (do_write_check(handle, "flyrecord", 10)) |
| @@ -644,9 +688,11 @@ int tracecmd_append_cpu_data(struct tracecmd_output *handle, | |||
| 644 | offset += st.st_size; | 688 | offset += st.st_size; |
| 645 | offset = (offset + (handle->page_size - 1)) & ~(handle->page_size - 1); | 689 | offset = (offset + (handle->page_size - 1)) & ~(handle->page_size - 1); |
| 646 | 690 | ||
| 647 | if (do_write_check(handle, &offsets[i], 8)) | 691 | endian8 = convert_endian_8(handle, offsets[i]); |
| 692 | if (do_write_check(handle, &endian8, 8)) | ||
| 648 | goto out_free; | 693 | goto out_free; |
| 649 | if (do_write_check(handle, &sizes[i], 8)) | 694 | endian8 = convert_endian_8(handle, sizes[i]); |
| 695 | if (do_write_check(handle, &endian8, 8)) | ||
| 650 | goto out_free; | 696 | goto out_free; |
| 651 | } | 697 | } |
| 652 | 698 | ||
diff --git a/trace-split.c b/trace-split.c index 1e25da2..b1fe4de 100644 --- a/trace-split.c +++ b/trace-split.c | |||
| @@ -155,14 +155,15 @@ static int write_record(struct tracecmd_input *handle, | |||
| 155 | return 1; | 155 | return 1; |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | static void write_page(struct cpu_data *cpu_data, int long_size) | 158 | static void write_page(struct pevent *pevent, |
| 159 | struct cpu_data *cpu_data, int long_size) | ||
| 159 | { | 160 | { |
| 160 | if (long_size == 8) | 161 | if (long_size == 8) |
| 161 | *(unsigned long long *)cpu_data->commit = | 162 | *(unsigned long long *)cpu_data->commit = |
| 162 | (unsigned long long)cpu_data->index - 16; | 163 | __data2host8(pevent, (unsigned long long)cpu_data->index - 16); |
| 163 | else | 164 | else |
| 164 | *(unsigned int *)cpu_data->commit = | 165 | *(unsigned int *)cpu_data->commit = |
| 165 | cpu_data->index - 12; | 166 | __data2host4(pevent, cpu_data->index - 12); |
| 166 | write(cpu_data->fd, cpu_data->page, page_size); | 167 | write(cpu_data->fd, cpu_data->page, page_size); |
| 167 | } | 168 | } |
| 168 | 169 | ||
| @@ -226,7 +227,7 @@ static int parse_cpu(struct tracecmd_input *handle, | |||
| 226 | while (record && (!end || record->ts <= end)) { | 227 | while (record && (!end || record->ts <= end)) { |
| 227 | if (cpu_data[cpu].index + record->record_size > page_size) { | 228 | if (cpu_data[cpu].index + record->record_size > page_size) { |
| 228 | if (cpu_data[cpu].page) | 229 | if (cpu_data[cpu].page) |
| 229 | write_page(&cpu_data[cpu], long_size); | 230 | write_page(pevent, &cpu_data[cpu], long_size); |
| 230 | else | 231 | else |
| 231 | cpu_data[cpu].page = malloc_or_die(page_size); | 232 | cpu_data[cpu].page = malloc_or_die(page_size); |
| 232 | 233 | ||
| @@ -304,14 +305,14 @@ static int parse_cpu(struct tracecmd_input *handle, | |||
| 304 | 305 | ||
| 305 | if (percpu) { | 306 | if (percpu) { |
| 306 | if (cpu_data[cpu].page) { | 307 | if (cpu_data[cpu].page) { |
| 307 | write_page(&cpu_data[cpu], long_size); | 308 | write_page(pevent, &cpu_data[cpu], long_size); |
| 308 | free(cpu_data[cpu].page); | 309 | free(cpu_data[cpu].page); |
| 309 | cpu_data[cpu].page = NULL; | 310 | cpu_data[cpu].page = NULL; |
| 310 | } | 311 | } |
| 311 | } else { | 312 | } else { |
| 312 | for (cpu = 0; cpu < cpus; cpu++) { | 313 | for (cpu = 0; cpu < cpus; cpu++) { |
| 313 | if (cpu_data[cpu].page) { | 314 | if (cpu_data[cpu].page) { |
| 314 | write_page(&cpu_data[cpu], long_size); | 315 | write_page(pevent, &cpu_data[cpu], long_size); |
| 315 | free(cpu_data[cpu].page); | 316 | free(cpu_data[cpu].page); |
| 316 | cpu_data[cpu].page = NULL; | 317 | cpu_data[cpu].page = NULL; |
| 317 | } | 318 | } |
