@@ -4043,6 +4043,23 @@ error:
return -1;
}
+static int copy_cpu_count(struct tracecmd_input *in_handle, struct tracecmd_output *out_handle)
+{
+ unsigned int size;
+
+ if (!check_in_state(in_handle, TRACECMD_FILE_CPU_COUNT) ||
+ !check_out_state(out_handle, TRACECMD_FILE_CPU_COUNT))
+ return -1;
+
+ if (read_copy_size4(in_handle, out_handle, &size) < 0)
+ return -1;
+
+ in_handle->file_state = TRACECMD_FILE_CPU_COUNT;
+ out_set_file_state(out_handle, in_handle->file_state);
+
+ return 0;
+}
+
/**
* tracecmd_copy_headers - Copy headers from a tracecmd_input handle to a file descriptor
* @in_handle: input handle for the trace.dat file to copy from.
@@ -4135,6 +4152,19 @@ int tracecmd_copy_headers(struct tracecmd_input *in_handle,
return 0;
ret = copy_command_lines(in_handle, out_handle);
+ if (ret < 0)
+ goto out;
+
+ /* fallthrough */
+ case TRACECMD_FILE_CPU_COUNT:
+ if (end_state <= in_handle->file_state)
+ return 0;
+
+ ret = copy_cpu_count(in_handle, out_handle);
+ if (ret < 0)
+ goto out;
+
+ /* fallthrough */
default:
break;
}
@@ -1949,7 +1949,7 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char
if (!handle)
return NULL;
- fstate = state > TRACECMD_FILE_CMD_LINES ? TRACECMD_FILE_CMD_LINES : state;
+ fstate = state > TRACECMD_FILE_CPU_COUNT ? TRACECMD_FILE_CPU_COUNT : state;
if (tracecmd_copy_headers(ihandle, handle, 0, fstate) < 0)
goto out_free;
Extend the tracecmd_copy() API to support copying of CPU count from input to output trace hanlder. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- lib/trace-cmd/trace-input.c | 30 ++++++++++++++++++++++++++++++ lib/trace-cmd/trace-output.c | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-)