From 1402044a1577c9b62b60f64fdb48ae9524be458c Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Tue, 21 Aug 2012 13:57:43 -0400 Subject: [PATCH] Basic support to display vPID and vTID Signed-off-by: Julien Desfossez --- src/common.c | 50 ++++++++++++++++++++++++++++++++++++++++++- src/common.h | 5 ++++- src/cursesdisplay.c | 52 +++++++++++++++++++++++++++++++++++++++------ src/lttngtop.c | 20 +++++++++++++++-- src/lttngtoptypes.h | 7 +++--- 5 files changed, 119 insertions(+), 15 deletions(-) diff --git a/src/common.c b/src/common.c index 43e258b..fd941bd 100644 --- a/src/common.c +++ b/src/common.c @@ -84,6 +84,51 @@ uint64_t get_context_ppid(const struct bt_ctf_event *event) return ppid; } +uint64_t get_context_vtid(const struct bt_ctf_event *event) +{ + const struct definition *scope; + uint64_t vtid; + + scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT); + vtid = bt_ctf_get_int64(bt_ctf_get_field(event, + scope, "_vtid")); + if (bt_ctf_field_get_error()) { + return -1ULL; + } + + return vtid; +} + +uint64_t get_context_vpid(const struct bt_ctf_event *event) +{ + const struct definition *scope; + uint64_t vpid; + + scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT); + vpid = bt_ctf_get_int64(bt_ctf_get_field(event, + scope, "_vpid")); + if (bt_ctf_field_get_error()) { + return -1ULL; + } + + return vpid; +} + +uint64_t get_context_vppid(const struct bt_ctf_event *event) +{ + const struct definition *scope; + uint64_t vppid; + + scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT); + vppid = bt_ctf_get_int64(bt_ctf_get_field(event, + scope, "_vppid")); + if (bt_ctf_field_get_error()) { + return -1ULL; + } + + return vppid; +} + char *get_context_comm(const struct bt_ctf_event *event) { const struct bt_definition *scope; @@ -149,12 +194,15 @@ struct processtop* add_proc(struct lttngtop *ctx, int tid, char *comm, } struct processtop* update_proc(struct processtop* proc, int pid, int tid, - int ppid, char *comm) + int ppid, int vpid, int vtid, int vppid, char *comm) { if (proc) { proc->pid = pid; proc->tid = tid; proc->ppid = ppid; + proc->vpid = vpid; + proc->vtid = vtid; + proc->vppid = vppid; if (strcmp(proc->comm, comm) != 0) { free(proc->comm); proc->comm = strdup(comm); diff --git a/src/common.h b/src/common.h index 1bde45c..2458c85 100644 --- a/src/common.h +++ b/src/common.h @@ -39,7 +39,7 @@ struct processtop *find_process_tid(struct lttngtop *ctx, int pid, char *comm); struct processtop* add_proc(struct lttngtop *ctx, int pid, char *comm, unsigned long timestamp); struct processtop* update_proc(struct processtop* proc, int pid, int tid, - int ppid, char *comm); + int ppid, int vpid, int vtid, int vppid, char *comm); void add_thread(struct processtop *parent, struct processtop *thread); struct processtop* get_proc(struct lttngtop *ctx, int tid, char *comm, unsigned long timestamp); @@ -64,6 +64,9 @@ uint64_t get_context_tid(const struct bt_ctf_event *event); uint64_t get_context_pid(const struct bt_ctf_event *event); uint64_t get_context_ppid(const struct bt_ctf_event *event); char *get_context_comm(const struct bt_ctf_event *event); +uint64_t get_context_vtid(const struct bt_ctf_event *event); +uint64_t get_context_vpid(const struct bt_ctf_event *event); +uint64_t get_context_vppid(const struct bt_ctf_event *event); enum bt_cb_ret handle_statedump_process_state(struct bt_ctf_event *call_data, void *private_data); diff --git a/src/cursesdisplay.c b/src/cursesdisplay.c index 02764dd..62c4ba4 100644 --- a/src/cursesdisplay.c +++ b/src/cursesdisplay.c @@ -59,6 +59,7 @@ char log_lines[MAX_LINE_LENGTH * MAX_LOG_LINES + MAX_LOG_LINES]; int max_elements = 80; int toggle_threads = 1; +int toggle_virt = -1; int toggle_pause = -1; int max_center_lines; @@ -66,7 +67,7 @@ GPtrArray *selected_processes; pthread_t keyboard_thread; -struct header_view cputopview[4]; +struct header_view cputopview[6]; struct header_view iostreamtopview[3]; struct header_view fileview[3]; @@ -78,6 +79,8 @@ void reset_ncurses() sem_post(&pause_sem); sem_post(&timer); sem_post(&goodtodisplay); + sem_post(&end_trace_sem); + sem_post(&goodtoupdate); } static void handle_sigterm(int signal) @@ -288,6 +291,7 @@ void update_footer() print_key(footer, "q", "Quit ", 0); print_key(footer, "r", "Pref ", 0); print_key(footer, "t", "Threads ", toggle_threads); + print_key(footer, "v", "Virt ", toggle_virt); print_key(footer, "p", "Pause ", toggle_pause); wrefresh(footer); @@ -525,6 +529,7 @@ void update_cputop_display() double maxcputime; int nblinedisplayed = 0; int current_line = 0; + int current_row_offset; int column; elapsed = data->end - data->start; @@ -544,7 +549,10 @@ void update_cputop_display() set_window_title(center, "CPU Top"); wattron(center, A_BOLD); column = 1; - for (i = 0; i < 4; i++) { + for (i = 0; i < 6; i++) { + if (toggle_virt < 0 && (i == 3 || i == 4)) { + continue; + } if (cputopview[i].sort) { wattron(center, A_UNDERLINE); pref_current_sort = i; @@ -561,6 +569,7 @@ void update_cputop_display() for (i = list_offset; i < data->process_table->len && nblinedisplayed < max_center_lines; i++) { tmp = g_ptr_array_index(data->process_table, i); + current_row_offset = 1; if (tmp->pid != tmp->tid) if (toggle_threads == -1) continue; @@ -575,14 +584,31 @@ void update_cputop_display() mvwhline(center, current_line + header_offset, 1, ' ', COLS-3); } /* CPU(%) */ - mvwprintw(center, current_line + header_offset, 1, "%1.2f", + mvwprintw(center, current_line + header_offset, + current_row_offset, "%1.2f", tmp->totalcpunsec / maxcputime); + current_row_offset += 10; /* PID */ - mvwprintw(center, current_line + header_offset, 11, "%d", tmp->pid); + mvwprintw(center, current_line + header_offset, + current_row_offset, "%d", tmp->pid); + current_row_offset += 10; /* TID */ - mvwprintw(center, current_line + header_offset, 21, "%d", tmp->tid); + mvwprintw(center, current_line + header_offset, + current_row_offset, "%d", tmp->tid); + current_row_offset += 10; + if (toggle_virt > 0) { + /* VPID */ + mvwprintw(center, current_line + header_offset, + current_row_offset, "%d", tmp->vpid); + current_row_offset += 10; + /* VTID */ + mvwprintw(center, current_line + header_offset, + current_row_offset, "%d", tmp->vtid); + current_row_offset += 10; + } /* NAME */ - mvwprintw(center, current_line + header_offset, 31, "%s", tmp->comm); + mvwprintw(center, current_line + header_offset, + current_row_offset, "%s", tmp->comm); wattroff(center, COLOR_PAIR(6)); wattroff(center, COLOR_PAIR(5)); nblinedisplayed++; @@ -672,6 +698,12 @@ void update_process_details() wprintw(center, "%d", tmp->pid); print_key_title("PPID", line++); wprintw(center, "%d", tmp->ppid); + print_key_title("VPID", line++); + wprintw(center, "%d", tmp->vpid); + print_key_title("VTID", line++); + wprintw(center, "%d", tmp->vtid); + print_key_title("VPPID", line++); + wprintw(center, "%d", tmp->vppid); print_key_title("CPU", line++); wprintw(center, "%1.2f %%", tmp->totalcpunsec/maxcputime); @@ -1513,6 +1545,10 @@ void *handle_keyboard(void *p) case 'r': toggle_pref_panel(); break; + case 'v': + toggle_virt *= -1; + update_current_view(); + break; /* ESCAPE, but slow to process, don't know why */ case 27: if (pref_panel_visible) @@ -1539,7 +1575,9 @@ void init_view_headers() cputopview[0].sort = 1; cputopview[1].title = strdup("PID"); cputopview[2].title = strdup("TID"); - cputopview[3].title = strdup("NAME"); + cputopview[3].title = strdup("VPID"); + cputopview[4].title = strdup("VTID"); + cputopview[5].title = strdup("NAME"); iostreamtopview[0].title = strdup("R (B/sec)"); iostreamtopview[1].title = strdup("W (B/sec)"); diff --git a/src/lttngtop.c b/src/lttngtop.c index c567878..d282011 100644 --- a/src/lttngtop.c +++ b/src/lttngtop.c @@ -93,11 +93,15 @@ void *refresh_thread(void *p) if (quit) { sem_post(&pause_sem); sem_post(&timer); + sem_post(&end_trace_sem); sem_post(&goodtodisplay); + sem_post(&goodtoupdate); pthread_exit(0); } + if (!opt_input_path) { bt_list_for_each_entry(mmap_info, &mmap_list.head, list) helper_kernctl_buffer_flush(mmap_info->fd); + } sem_wait(&pause_sem); sem_post(&pause_sem); sem_post(&timer); @@ -293,7 +297,7 @@ void update_perf_counter(struct processtop *proc, const struct bt_ctf_event *eve enum bt_cb_ret fix_process_table(struct bt_ctf_event *call_data, void *private_data) { - int pid, tid, ppid; + int pid, tid, ppid, vpid, vtid, vppid; char *comm; struct processtop *parent, *child; unsigned long timestamp; @@ -314,6 +318,18 @@ enum bt_cb_ret fix_process_table(struct bt_ctf_event *call_data, if (ppid == -1ULL) { goto error; } + vpid = get_context_vpid(call_data); + if (pid == -1ULL) { + vpid = -1; + } + vtid = get_context_vtid(call_data); + if (tid == -1ULL) { + vtid = -1; + } + vppid = get_context_vppid(call_data); + if (ppid == -1ULL) { + vppid = -1; + } comm = get_context_comm(call_data); if (!comm) { goto error; @@ -323,7 +339,7 @@ enum bt_cb_ret fix_process_table(struct bt_ctf_event *call_data, child = find_process_tid(<tngtop, tid, comm); if (!child) child = add_proc(<tngtop, tid, comm, timestamp); - update_proc(child, pid, tid, ppid, comm); + update_proc(child, pid, tid, ppid, vpid, vtid, vppid, comm); if (pid != tid) { /* find or create the parent */ diff --git a/src/lttngtoptypes.h b/src/lttngtoptypes.h index e01f804..66b2079 100644 --- a/src/lttngtoptypes.h +++ b/src/lttngtoptypes.h @@ -44,12 +44,11 @@ struct processtop { char *comm; int tid; int ppid; - int oldpid; - int oldtid; - int oldppid; + int vpid; + int vtid; + int vppid; unsigned long birth; unsigned long death; - unsigned long lastactivity; /* Files managing */ GPtrArray *process_files_table; struct file_history *files_history; -- 2.34.1