@@ -163,8 +163,6 @@ struct tracecmd_input {
struct pid_addr_maps *pid_maps;
/* file information */
struct file_section *sections;
- size_t header_files_start;
- size_t ftrace_files_start;
size_t options_start;
size_t total_file_size;
@@ -3301,21 +3299,26 @@ int tracecmd_make_pipe(struct tracecmd_input *handle, int cpu, int fd, int cpus)
*/
void tracecmd_print_events(struct tracecmd_input *handle, const char *regex)
{
- int ret;
+ struct file_section *sec;
if (!regex)
regex = ".*";
- if (!handle->ftrace_files_start) {
- lseek64(handle->fd, handle->header_files_start, SEEK_SET);
+ sec = open_section(handle, TRACECMD_OPTION_HEADER_INFO);
+ if (sec) {
read_header_files(handle);
+ close_section(handle, sec);
+ }
+ sec = open_section(handle, TRACECMD_OPTION_FTRACE_EVENTS);
+ if (sec) {
+ read_ftrace_files(handle, regex);
+ close_section(handle, sec);
+ }
+ sec = open_section(handle, TRACECMD_OPTION_EVENT_FORMATS);
+ if (sec) {
+ read_event_files(handle, regex);
+ close_section(handle, sec);
}
- ret = read_ftrace_files(handle, regex);
- if (ret < 0)
- return;
-
- read_event_files(handle, regex);
- return;
}
/* Show the cpu data stats */
@@ -3905,6 +3908,7 @@ int tracecmd_copy_headers(struct tracecmd_input *handle, int fd,
enum tracecmd_file_states start_state,
enum tracecmd_file_states end_state)
{
+ struct file_section *sec;
int ret;
if (!start_state)
@@ -3920,13 +3924,17 @@ int tracecmd_copy_headers(struct tracecmd_input *handle, int fd,
if (handle->file_state >= start_state) {
/* Set the handle to just before the start state */
- lseek64(handle->fd, handle->header_files_start, SEEK_SET);
+ sec = open_section(handle, TRACECMD_OPTION_HEADER_INFO);
+ if (!sec)
+ return -1;
/* Now that the file handle has moved, change its state */
handle->file_state = TRACECMD_FILE_INIT;
}
-
/* Try to bring the input up to the start state - 1 */
ret = tracecmd_read_headers(handle, start_state - 1);
+ if (sec)
+ close_section(handle, sec);
+
if (ret < 0)
goto out;
Utilize the internal database with file sections, when reading parts of a trace file. This logic unifies the way trace file version 6 and 7 are processed. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- lib/trace-cmd/trace-input.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-)