bool kernel_syscallchains;
s16 args_alignment;
bool show_tstamp;
+ bool show_cpu;
bool show_duration;
bool show_zeros;
bool show_arg_names;
*/
struct thread_trace {
u64 entry_time;
+ u32 entry_cpu;
bool entry_pending;
unsigned long nr_events;
unsigned long pfmaj, pfmin;
return fprintf(fp, " ? ");
}
+/**
+ * trace__fprintf_cpu - Print the CPU ID to a given file stream
+ * @cpu: The CPU ID to print
+ * @fp: The file stream to write to
+ *
+ * Formats and prints the specified CPU ID enclosed in brackets
+ * (e.g., "[003] ") to the provided file pointer. It is used to
+ * align and display the CPU ID consistently within the trace output.
+ *
+ * Return: The number of characters printed.
+ */
+static size_t trace__fprintf_cpu(u32 cpu, FILE *fp)
+{
+ size_t printed = 0;
+
+ if (cpu != (u32)-1)
+ printed += fprintf(fp, "[%03u] ", cpu);
+
+ return printed;
+}
+
static pid_t workload_pid = -1;
static volatile sig_atomic_t done = false;
static volatile sig_atomic_t interrupted = false;
}
static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread,
- u64 duration, bool duration_calculated, u64 tstamp, FILE *fp)
+ u64 duration, bool duration_calculated,
+ u64 tstamp, u32 cpu, FILE *fp)
{
size_t printed = 0;
if (trace->show_tstamp)
printed = trace__fprintf_tstamp(trace, tstamp, fp);
+ if (trace->show_cpu && cpu != (u32)-1)
+ printed += trace__fprintf_cpu(cpu, fp);
if (trace->show_duration)
printed += fprintf_duration(duration, duration_calculated, fp);
return printed + trace__fprintf_comm_tid(trace, thread, fp);
if (!ttrace->entry_pending)
return 0;
- printed = trace__fprintf_entry_head(trace, trace->current, 0, false, ttrace->entry_time, trace->output);
+ printed = trace__fprintf_entry_head(trace, trace->current, 0, false,
+ ttrace->entry_time, ttrace->entry_cpu,
+ trace->output);
printed += len = fprintf(trace->output, "%s)", ttrace->entry_str);
if (len < trace->args_alignment - 4)
if (evsel != trace->syscalls.events.sys_enter)
augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_syscalls_args_size);
ttrace->entry_time = sample->time;
+ ttrace->entry_cpu = sample->cpu;
msg = ttrace->entry_str;
printed += scnprintf(msg + printed, trace__entry_str_size - printed, "%s(", sc->name);
if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) {
int alignment = 0;
- trace__fprintf_entry_head(trace, thread, 0, false, ttrace->entry_time, trace->output);
+ trace__fprintf_entry_head(trace, thread, 0, false,
+ ttrace->entry_time,
+ sample->cpu, trace->output);
printed = fprintf(trace->output, "%s)", ttrace->entry_str);
if (trace->args_alignment > printed)
alignment = trace->args_alignment - printed;
if (trace->summary_only || (ret >= 0 && trace->failure_only))
goto out;
- trace__fprintf_entry_head(trace, thread, duration, duration_calculated, ttrace->entry_time, trace->output);
+ trace__fprintf_entry_head(trace, thread, duration,
+ duration_calculated, ttrace->entry_time,
+ sample->cpu, trace->output);
if (ttrace->entry_pending) {
printed = fprintf(trace->output, "%s", ttrace->entry_str);
trace__printf_interrupted_entry(trace);
trace__fprintf_tstamp(trace, sample->time, trace->output);
+ if (trace->show_cpu)
+ trace__fprintf_cpu(sample->cpu, trace->output);
+
if (trace->trace_syscalls && trace->show_duration)
fprintf(trace->output, "( ): ");
thread__find_symbol(thread, sample->cpumode, sample->ip, &al);
- trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output);
+ trace__fprintf_entry_head(trace, thread, 0, true, sample->time,
+ sample->cpu, trace->output);
fprintf(trace->output, "%sfault [",
evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ?
OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages",
"number of mmap data pages", evlist__parse_mmap_pages),
OPT_STRING('u', "uid", &trace.uid_str, "user", "user to profile"),
+ OPT_BOOLEAN(0, "show-cpu", &trace.show_cpu, "show cpu id"),
OPT_CALLBACK(0, "duration", &trace, "float",
"show only events with duration > N.M ms",
trace__set_duration),
goto out;
}
+ if (trace.show_cpu)
+ trace.opts.sample_cpu = true;
+
if ((nr_cgroups || trace.cgroup) && !trace.opts.target.system_wide) {
usage_with_options_msg(trace_usage, trace_options,
"cgroup monitoring only available in system-wide mode");