isPerfFile checks if a file is in perf.data format. It also returns false if it encounters an error during the check.
(path string)
| 552 | // isPerfFile checks if a file is in perf.data format. It also returns false |
| 553 | // if it encounters an error during the check. |
| 554 | func isPerfFile(path string) bool { |
| 555 | sourceFile, openErr := os.Open(path) |
| 556 | if openErr != nil { |
| 557 | return false |
| 558 | } |
| 559 | defer sourceFile.Close() |
| 560 | |
| 561 | // If the file is the output of a perf record command, it should begin |
| 562 | // with the string PERFILE2. |
| 563 | perfHeader := []byte("PERFILE2") |
| 564 | actualHeader := make([]byte, len(perfHeader)) |
| 565 | if _, readErr := sourceFile.Read(actualHeader); readErr != nil { |
| 566 | return false |
| 567 | } |
| 568 | return bytes.Equal(actualHeader, perfHeader) |
| 569 | } |
| 570 | |
| 571 | // convertPerfData converts the file at path which should be in perf.data format |
| 572 | // using the perf_to_profile tool and returns the file containing the |