Skip to content

Commit b52b0fd

Browse files
committed
uftrace: Increase TID length to 7
On recent distros, the PID is often goes to 7 digits (bigger than 1,000,000). So let's increase the length and update the code to use the TASK_ID_LEN macro. Signed-off-by: Namhyung Kim <[email protected]>
1 parent a4963f8 commit b52b0fd

File tree

12 files changed

+54
-48
lines changed

12 files changed

+54
-48
lines changed

cmds/dump.c

+18-14
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ static void dump_raw_task_rstack(struct uftrace_dump_ops *ops, struct uftrace_ta
601601
name = event_get_name(task->h, frs->addr);
602602

603603
pr_time(frs->time);
604-
pr_out("%5d: [%s] %s(%" PRIx64 ") depth: %u\n", task->tid, rstack_type(frs), name,
605-
frs->addr, frs->depth);
604+
pr_out("%*d: [%s] %s(%" PRIx64 ") depth: %u\n", TASK_ID_LEN, task->tid, rstack_type(frs),
605+
name, frs->addr, frs->depth);
606606
pr_hex(&raw->file_offset, frs, sizeof(*frs));
607607

608608
if (frs->type == UFTRACE_EVENT)
@@ -611,13 +611,15 @@ static void dump_raw_task_rstack(struct uftrace_dump_ops *ops, struct uftrace_ta
611611
if (frs->more && show_args) {
612612
if (frs->type == UFTRACE_ENTRY) {
613613
pr_time(frs->time);
614-
pr_out("%5d: [%s] length = %d\n", task->tid, "args ", task->args.len);
614+
pr_out("%*d: [%s] length = %d\n", TASK_ID_LEN, task->tid, "args ",
615+
task->args.len);
615616
pr_args(&task->args);
616617
pr_hex(&raw->file_offset, task->args.data, ALIGN(task->args.len, 8));
617618
}
618619
else if (frs->type == UFTRACE_EXIT) {
619620
pr_time(frs->time);
620-
pr_out("%5d: [%s] length = %d\n", task->tid, "retval", task->args.len);
621+
pr_out("%*d: [%s] length = %d\n", TASK_ID_LEN, task->tid, "retval",
622+
task->args.len);
621623
pr_retval(&task->args);
622624
pr_hex(&raw->file_offset, task->args.data, ALIGN(task->args.len, 8));
623625
}
@@ -633,13 +635,13 @@ static void dump_raw_task_event(struct uftrace_dump_ops *ops, struct uftrace_tas
633635
char *name = event_get_name(task->h, frs->addr);
634636

635637
pr_time(frs->time);
636-
pr_out("%5d: [%s] %s(%" PRIx64 ") depth: %u\n", task->tid, rstack_type(frs), name,
637-
frs->addr, frs->depth);
638+
pr_out("%*d: [%s] %s(%" PRIx64 ") depth: %u\n", TASK_ID_LEN, task->tid, rstack_type(frs),
639+
name, frs->addr, frs->depth);
638640
pr_hex(&raw->file_offset, frs, sizeof(*frs));
639641

640642
if (frs->more && show_args) {
641643
pr_time(frs->time);
642-
pr_out("%5d: [%s] length = %d\n", task->tid, "data ", task->args.len);
644+
pr_out("%*d: [%s] length = %d\n", TASK_ID_LEN, task->tid, "data ", task->args.len);
643645
pr_event(task, frs->addr);
644646
pr_hex(&raw->file_offset, task->args.data, ALIGN(task->args.len, 8));
645647
}
@@ -692,8 +694,8 @@ static void dump_raw_kernel_rstack(struct uftrace_dump_ops *ops,
692694
timestamp = ((uint64_t)upper << 27) + (lower >> 5);
693695

694696
pr_time(frs->time - timestamp);
695-
pr_out("%5d: [%s] %s (+%" PRIu64 " nsec)\n", tid, "time ", "extend",
696-
timestamp);
697+
pr_out("%*d: [%s] %s (+%" PRIu64 " nsec)\n", TASK_ID_LEN, tid, "time ",
698+
"extend", timestamp);
697699

698700
if (debug)
699701
pr_hex(&offset, tmp, 8);
@@ -705,8 +707,8 @@ static void dump_raw_kernel_rstack(struct uftrace_dump_ops *ops,
705707
}
706708

707709
pr_time(frs->time);
708-
pr_out("%5d: [%s] %s(%" PRIx64 ") depth: %u\n", tid, rstack_type(frs), name, frs->addr,
709-
frs->depth);
710+
pr_out("%*d: [%s] %s(%" PRIx64 ") depth: %u\n", TASK_ID_LEN, tid, rstack_type(frs), name,
711+
frs->addr, frs->depth);
710712

711713
if (debug) {
712714
/* this is only needed for hex dump */
@@ -744,7 +746,8 @@ static void dump_raw_kernel_event(struct uftrace_dump_ops *ops,
744746
event_data = read_kernel_event(kernel, cpu, &size);
745747

746748
pr_time(frs->time);
747-
pr_out("%5d: [%s] %s(%ld) %.*s\n", tid, rstack_type(frs), buf, frs->addr, size, event_data);
749+
pr_out("%*d: [%s] %s(%ld) %.*s\n", TASK_ID_LEN, tid, rstack_type(frs), buf, frs->addr, size,
750+
event_data);
748751

749752
if (debug) {
750753
/* this is only needed for hex dump */
@@ -765,7 +768,7 @@ static void dump_raw_kernel_event(struct uftrace_dump_ops *ops,
765768
static void dump_raw_kernel_lost(struct uftrace_dump_ops *ops, uint64_t time, int tid, int losts)
766769
{
767770
pr_time(time);
768-
pr_red("%5d: [%s ]: %d events\n", tid, "lost", losts);
771+
pr_red("%*d: [%s ]: %d events\n", TASK_ID_LEN, tid, "lost", losts);
769772
}
770773

771774
static void dump_raw_perf_start(struct uftrace_dump_ops *ops, struct uftrace_perf_reader *perf,
@@ -788,7 +791,8 @@ static void dump_raw_perf_event(struct uftrace_dump_ops *ops, struct uftrace_per
788791
char *evt_name = event_get_name(NULL, frs->addr);
789792

790793
pr_time(frs->time);
791-
pr_out("%5d: [%s] %s(%" PRIu64 ")\n", perf->tid, rstack_type(frs), evt_name, frs->addr);
794+
pr_out("%*d: [%s] %s(%" PRIu64 ")\n", TASK_ID_LEN, perf->tid, rstack_type(frs), evt_name,
795+
frs->addr);
792796

793797
if (debug) {
794798
/* XXX: this is different from file contents */

cmds/graph.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static void print_task_self_time(struct field_data *fd)
128128
static void print_task_tid(struct field_data *fd)
129129
{
130130
struct uftrace_task *task = fd->arg;
131-
pr_out("[%6d]", task->tid);
131+
pr_out("[%*d]", TASK_ID_LEN, task->tid);
132132
}
133133

134134
static struct display_field field_task_total_time = {
@@ -154,8 +154,8 @@ static struct display_field field_task_self_time = {
154154
static struct display_field field_task_tid = {
155155
.id = GRAPH_F_TASK_TID,
156156
.name = "tid",
157-
.header = " TID ",
158-
.length = 8,
157+
.header = " TID ",
158+
.length = TASK_ID_LEN + 2, /* +2 for "[ ]" */
159159
.print = print_task_tid,
160160
.list = LIST_HEAD_INIT(field_task_tid.list),
161161
};

cmds/info.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ static void print_task(struct uftrace_data *handle, struct uftrace_task *t)
12151215
/* TIMESTAMP */
12161216
pr_out(" %13lu.%09lu ", t->time.stamp / NSEC_PER_SEC, t->time.stamp % NSEC_PER_SEC);
12171217
/* FLAGS TID COMM */
1218-
pr_out(" %s [%6d] %-16s ", flags, t->tid, t->comm);
1218+
pr_out(" %s [%*d] %-16s ", flags, TASK_ID_LEN, t->tid, t->comm);
12191219
/* DATA SIZE */
12201220
if (stbuf.st_size) {
12211221
uint64_t size_kb = stbuf.st_size / 1024;
@@ -1235,8 +1235,8 @@ static void print_task_info(struct uftrace_data *handle)
12351235
struct rb_node *n;
12361236
struct uftrace_task *t;
12371237

1238-
pr_out("#%23s %5s %8s %-16s %s\n", "TIMESTAMP ", "FLAGS", " TID ", "TASK",
1239-
"DATA SIZE");
1238+
pr_out("#%23s %5s %*s %-16s %s\n", "TIMESTAMP ", "FLAGS", TASK_ID_LEN + 2,
1239+
" TID ", "TASK", "DATA SIZE");
12401240

12411241
n = rb_first(&handle->sessions.tasks);
12421242
while (n != NULL) {

cmds/replay.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void print_duration(struct field_data *fd)
3838
static void print_tid(struct field_data *fd)
3939
{
4040
struct uftrace_task_reader *task = fd->task;
41-
pr_out("[%6d]", task->tid);
41+
pr_out("[%*d]", TASK_ID_LEN, task->tid);
4242
}
4343

4444
static void print_addr(struct field_data *fd)
@@ -87,7 +87,8 @@ static void print_task(struct field_data *fd)
8787
{
8888
struct uftrace_task_reader *task = fd->task;
8989

90-
pr_out("%*s", 15, task->t->comm);
90+
/* The task (command) name contains NUL at the end */
91+
pr_out("%*s", TASK_COMM_LEN - 1, task->t->comm);
9192
}
9293

9394
static void print_module(struct field_data *fd)
@@ -131,8 +132,8 @@ static struct display_field field_duration = {
131132
static struct display_field field_tid = {
132133
.id = REPLAY_F_TID,
133134
.name = "tid",
134-
.header = " TID ",
135-
.length = 8,
135+
.header = " TID ",
136+
.length = TASK_ID_LEN + 2, /* +2 for "[ ]" */
136137
.print = print_tid,
137138
.list = LIST_HEAD_INIT(field_tid.list),
138139
};
@@ -182,7 +183,7 @@ static struct display_field field_task = {
182183
.id = REPLAY_F_TASK,
183184
.name = "task",
184185
.header = " TASK NAME",
185-
.length = 15,
186+
.length = TASK_COMM_LEN - 1, /* -1 due to NUL at the end */
186187
.print = print_task,
187188
.list = LIST_HEAD_INIT(field_task.list),
188189
};

cmds/report.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static void print_task(struct uftrace_report_node *node, void *arg, int space)
361361
print_field(node, space);
362362

363363
pr_out("%*s", space, " ");
364-
pr_out("%-16s\n", t->comm);
364+
pr_out("%-*s\n", TASK_COMM_LEN, t->comm);
365365
}
366366

367367
static void report_task(struct uftrace_data *handle, struct uftrace_opts *opts)

scripts/dump.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function uftrace_entry(ctx)
2020
local _name = ctx['name']
2121

2222
local unit = 1000000000
23-
print(string.format('%d.%09d %6d: [entry] %s(%x) depth: %d',
23+
print(string.format('%d.%09d %7d: [entry] %s(%x) depth: %d',
2424
_time / unit, _time % unit, _tid, _name, _address, _depth))
2525

2626
if ctx['args'] ~= nil then
@@ -39,7 +39,7 @@ function uftrace_exit(ctx)
3939
local _name = ctx["name"]
4040

4141
local unit = 1000000000
42-
print(string.format('%d.%09d %6d: [exit ] %s(%x) depth: %d',
42+
print(string.format('%d.%09d %7d: [exit ] %s(%x) depth: %d',
4343
_time / unit, _time % unit, _tid, _name, _address, _depth))
4444

4545
if ctx['retval'] ~= nil then
@@ -55,7 +55,7 @@ function uftrace_event(ctx)
5555
local _name = ctx["name"]
5656

5757
local unit = 1000000000
58-
print(string.format('%d.%09d %6d: [event] %s(%x)',
58+
print(string.format('%d.%09d %7d: [event] %s(%x)',
5959
_time / unit, _time % unit, _tid, _name, _address))
6060
end
6161

scripts/dump.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def uftrace_entry(ctx):
2828
_name = ctx["name"]
2929

3030
unit = 10 ** 9
31-
print("%d.%09d %6d: [entry] %s(%x) depth: %d" %
31+
print("%d.%09d %7d: [entry] %s(%x) depth: %d" %
3232
(_time / unit, _time % unit, _tid, _name, _address, _depth))
3333

3434
if "args" in ctx:
@@ -47,7 +47,7 @@ def uftrace_exit(ctx):
4747
_name = ctx["name"]
4848

4949
unit = 10 ** 9
50-
print("%d.%09d %6d: [exit ] %s(%x) depth: %d" %
50+
print("%d.%09d %7d: [exit ] %s(%x) depth: %d" %
5151
(_time / unit, _time % unit, _tid, _name, _address, _depth))
5252

5353
if "retval" in ctx:
@@ -62,7 +62,7 @@ def uftrace_event(ctx):
6262
_name = ctx["name"]
6363

6464
unit = 10 ** 9
65-
print("%d.%09d %6d: [event] %s(%x)" %
65+
print("%d.%09d %7d: [event] %s(%x)" %
6666
(_time / unit, _time % unit, _tid, _name, _address))
6767

6868
# uftrace_end is optional, so can be omitted.

scripts/replay.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function uftrace_entry(ctx)
1010
local indent = _depth * 2
1111
local space = string.rep(' ', indent)
1212

13-
local buf = string.format(' %10s [%6d] | %s%s() {', '', _tid, space, _symname)
13+
local buf = string.format(' %10s [%7d] | %s%s() {', '', _tid, space, _symname)
1414
print(buf)
1515
end
1616

@@ -26,7 +26,7 @@ function uftrace_exit(ctx)
2626
local time_and_unit = get_time_and_unit(_duration)
2727
local time = time_and_unit[1]
2828
local unit = time_and_unit[2]
29-
local buf = string.format(' %7.3f %s [%6d] | %s}', time, unit, _tid, space)
29+
local buf = string.format(' %7.3f %s [%7d] | %s}', time, unit, _tid, space)
3030
local buf = string.format('%s /* %s */', buf, _symname)
3131
print(buf)
3232
end

scripts/replay.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def uftrace_entry(ctx):
1010
indent = _depth * 2
1111
space = " " * indent
1212

13-
buf = " %10s [%6d] | %s%s() {" % ("", _tid, space, _symname)
13+
buf = " %10s [%7d] | %s%s() {" % ("", _tid, space, _symname)
1414
print(buf)
1515

1616
def uftrace_exit(ctx):
@@ -24,7 +24,7 @@ def uftrace_exit(ctx):
2424
space = " " * indent
2525

2626
(time, unit) = get_time_and_unit(_duration)
27-
buf = " %7.3f %s [%6d] | %s}" % (time, unit, _tid, space)
27+
buf = " %7.3f %s [%7d] | %s}" % (time, unit, _tid, space)
2828
buf = "%s /* %s */" % (buf, _symname)
2929
print(buf)
3030

uftrace.h

+1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ void put_libmcount_path(char *libpath);
357357
#define SESSION_ID_LEN 16
358358
#define TASK_COMM_LEN 16
359359
#define TASK_COMM_LAST (TASK_COMM_LEN - 1)
360+
#define TASK_ID_LEN 7
360361

361362
struct uftrace_session {
362363
struct rb_node node;

utils/fstack.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ int fstack_entry(struct uftrace_task_reader *task, struct uftrace_record *rstack
610610
if (fstack == NULL)
611611
return -1;
612612

613-
pr_dbg2("ENTRY: [%5d] stack: %d, depth: %d, disp: %d, I: %d, O: %d, D: %d, flags = %lx %s\n",
614-
task->tid, task->stack_count - 1, rstack->depth, task->display_depth,
613+
pr_dbg2("ENTRY: [%*d] stack: %d, depth: %d, disp: %d, I: %d, O: %d, D: %d, flags = %lx %s\n",
614+
TASK_ID_LEN, task->tid, task->stack_count - 1, rstack->depth, task->display_depth,
615615
task->filter.in_count, task->filter.out_count, task->filter.depth, fstack->flags,
616616
rstack->more ? "more" : "");
617617

@@ -740,8 +740,8 @@ void fstack_exit(struct uftrace_task_reader *task)
740740
if (fstack == NULL)
741741
return;
742742

743-
pr_dbg2("EXIT : [%5d] stack: %d, depth: %d, disp: %d, I: %d, O: %d, D: %d, flags = %lx\n",
744-
task->tid, task->stack_count, task->rstack->depth, task->display_depth,
743+
pr_dbg2("EXIT : [%*d] stack: %d, depth: %d, disp: %d, I: %d, O: %d, D: %d, flags = %lx\n",
744+
TASK_ID_LEN, task->tid, task->stack_count, task->rstack->depth, task->display_depth,
745745
task->filter.in_count, task->filter.out_count, task->filter.depth, fstack->flags);
746746

747747
if (fstack->flags & FSTACK_FL_FILTERED)
@@ -1021,10 +1021,10 @@ bool fstack_check_filter(struct uftrace_task_reader *task)
10211021
if (fstack == NULL)
10221022
return false;
10231023

1024-
pr_dbg2("SCHED: [%5d] stack: %d, depth: %d, disp: %d, I: %d, O: %d, D: %d, %s\n",
1025-
task->tid, idx, fstack->orig_depth, task->display_depth,
1026-
task->filter.in_count, task->filter.out_count, task->filter.depth,
1027-
sched);
1024+
pr_dbg2("SCHED: [%*d] stack: %d, depth: %d, disp: %d, I: %d, O: %d, D: %d, %s\n",
1025+
TASK_ID_LEN, task->tid, idx, fstack->orig_depth,
1026+
task->display_depth, task->filter.in_count, task->filter.out_count,
1027+
task->filter.depth, sched);
10281028
}
10291029
}
10301030

@@ -2237,7 +2237,7 @@ static void adjust_rstack_after_schedule(struct uftrace_data *handle,
22372237
task->timestamp_next -= prev_fstack->total_time;
22382238
}
22392239

2240-
pr_dbg3("task[%6d] delay next record after schedule\n", task->tid);
2240+
pr_dbg3("task[%*d] delay next record after schedule\n", TASK_ID_LEN, task->tid);
22412241
next_rec->time = ~0ULL;
22422242
return;
22432243
}
@@ -2253,7 +2253,7 @@ static void adjust_rstack_after_schedule(struct uftrace_data *handle,
22532253
/* save it in case it's overwritten by subsequent schedule */
22542254
task->timestamp_estimate = next_rec->time;
22552255

2256-
pr_dbg3("task[%6d] estimate next record after schedule\n", task->tid);
2256+
pr_dbg3("task[%*d] estimate next record after schedule\n", TASK_ID_LEN, task->tid);
22572257
}
22582258

22592259
static int __read_rstack(struct uftrace_data *handle, struct uftrace_task_reader **taskp,

utils/report.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -851,9 +851,9 @@ void report_sort_tasks(struct uftrace_data *handle, struct rb_root *name_root,
851851
static void print_##_func(struct field_data *fd) \
852852
{ \
853853
struct uftrace_report_node *node = fd->arg; \
854-
pr_out("%6d", strtol(node->name, NULL, 10)); \
854+
pr_out("%*d", TASK_ID_LEN, strtol(node->name, NULL, 10)); \
855855
} \
856-
FIELD_STRUCT(_id, _name, _func, _header, 6)
856+
FIELD_STRUCT(_id, _name, _func, _header, TASK_ID_LEN)
857857

858858
#define NODATA "-"
859859
static void print_time_or_dash(uint64_t time_nsec)

0 commit comments

Comments
 (0)