@@ -4809,6 +4809,35 @@ error:
return -1;
}
+static int copy_cpu_count(struct tracecmd_input *in_handle, struct tracecmd_output *out_handle)
+{
+ unsigned int cpus;
+
+ if (!check_in_state(in_handle, TRACECMD_FILE_CPU_COUNT) ||
+ !check_out_state(out_handle, TRACECMD_FILE_CPU_COUNT))
+ return -1;
+
+ if (!HAS_SECTIONS(in_handle)) {
+ if (read4(in_handle, &cpus))
+ return -1;
+ } else {
+ cpus = in_handle->max_cpu;
+ }
+
+ if (tracecmd_get_out_file_version(out_handle) < FILE_VERSION_SECTIONS) {
+ cpus = tep_read_number(in_handle->pevent, &cpus, 4);
+ if (do_write_check(out_handle, &cpus, 4))
+ return -1;
+ } else {
+ tracecmd_add_option(out_handle, TRACECMD_OPTION_CPUCOUNT, sizeof(int), &cpus);
+ }
+
+ 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.
@@ -4907,6 +4936,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;
}
The tracecmd_copy_headers() API should be able to copy CPU count also, as it is part of the headers. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- lib/trace-cmd/trace-input.c | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)